forked from Alamofire/Alamofire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding example project and test harness
- Loading branch information
Showing
17 changed files
with
1,669 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
Alamofire.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
Example/Images.xcassets/LaunchImage.launchimage/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
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.
Oops, something went wrong.