Skip to content

Commit

Permalink
Adding example project and test harness
Browse files Browse the repository at this point in the history
  • Loading branch information
mattt committed Aug 24, 2014
1 parent 9f7c365 commit 627b742
Show file tree
Hide file tree
Showing 17 changed files with 1,669 additions and 0 deletions.
433 changes: 433 additions & 0 deletions Alamofire.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions Alamofire.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Example/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// AppDelegate.swift
//
// Copyright (c) 2014 Alamofire (http://alamofire.org)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {

var window: UIWindow?

// MARK: - UIApplicationDelegate

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
let splitViewController = self.window!.rootViewController as UISplitViewController
let navigationController = splitViewController.viewControllers.last as UINavigationController
navigationController.topViewController.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem()
splitViewController.delegate = self

return true
}

// MARK: - UISplitViewControllerDelegate

func splitViewController(splitViewController: UISplitViewController!, collapseSecondaryViewController secondaryViewController:UIViewController!, ontoPrimaryViewController primaryViewController:UIViewController!) -> Bool {
if let secondaryAsNavController = secondaryViewController as? UINavigationController {
if let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController {
return topAsDetailController.request == nil
}
}

return false
}

}

332 changes: 332 additions & 0 deletions Example/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

161 changes: 161 additions & 0 deletions Example/DetailViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// DetailViewController.swift
//
// Copyright (c) 2014 Alamofire (http://alamofire.org)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import UIKit
import Alamofire

class DetailViewController: UITableViewController {
enum Sections: Int {
case Headers, Body
}

var request: Alamofire.Request? {
willSet {
if self.request != nil {
self.request?.cancel()
self.refreshControl.endRefreshing()
self.headers.removeAll()
self.body = nil
self.elapsedTime = nil
}
}

didSet {
self.title = self.request?.description
}
}

var headers: [String: String] = [:]
var body: String?
var elapsedTime: NSTimeInterval?

override func awakeFromNib() {
super.awakeFromNib()
self.refreshControl.addTarget(self, action: "refresh", forControlEvents: .ValueChanged)

}

// MARK: - UIViewController

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

self.refresh()
}

// MARK: - IBAction

@IBAction func refresh() {
if self.request == nil {
return
}

self.refreshControl.beginRefreshing()

let start = CACurrentMediaTime()
self.request?.responseString { (request, response, body, error) in
let end = CACurrentMediaTime()
self.elapsedTime = end - start

for (field, value) in response!.allHeaderFields {
self.headers["\(field)"] = "\(value)"
}

self.body = body

self.tableView.reloadData()
self.refreshControl.endRefreshing()
}
}

// MARK: UITableViewDataSource

override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
switch Sections.fromRaw(section)! {
case .Headers:
return self.headers.count
case .Body:
return self.body == nil ? 0 : 1
default:
return 0
}
}

override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {

switch Sections.fromRaw(indexPath.section)! {
case .Headers:
let cell = self.tableView.dequeueReusableCellWithIdentifier("Header") as UITableViewCell
let field = self.headers.keys.array.sorted(<)[indexPath.row]
let value = self.headers[field]

cell.textLabel.text = field
cell.detailTextLabel.text = value

return cell
case .Body:
let cell = self.tableView.dequeueReusableCellWithIdentifier("Body") as UITableViewCell

cell.textLabel.text = self.body

return cell
default:
return nil
}
}

// MARK: UITableViewDelegate

override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
return 2
}

override func tableView(tableView: UITableView!, titleForHeaderInSection section: Int) -> String! {
switch Sections.fromRaw(section)! {
case .Headers:
return self.headers.isEmpty ? nil : "Headers"
case .Body:
return self.body == nil ? nil : "Body"
default:
return nil
}
}

override func tableView(tableView: UITableView!, heightForRowAtIndexPath indexPath: NSIndexPath!) -> CGFloat {
switch Sections.fromRaw(indexPath.section)! {
case .Body:
return 300
default:
return tableView.rowHeight
}
}

override func tableView(tableView: UITableView!, titleForFooterInSection section: Int) -> String! {
switch Sections.fromRaw(section)! {
case .Body:
return self.elapsedTime == nil ? nil : "Elapsed Time: \(self.elapsedTime!) sec"
default:
return nil
}
}
}

53 changes: 53 additions & 0 deletions Example/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
51 changes: 51 additions & 0 deletions Example/Images.xcassets/LaunchImage.launchimage/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"subtype" : "retina4",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
18 changes: 18 additions & 0 deletions Example/Images.xcassets/Logo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x",
"filename" : "Logo.png"
},
{
"idiom" : "universal",
"scale" : "2x",
"filename" : "[email protected]"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file added Example/Images.xcassets/Logo.imageset/Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 627b742

Please sign in to comment.