Skip to content

Commit

Permalink
Merge pull request #1385 from Alamofire/feature/refactoring-apis-for-…
Browse files Browse the repository at this point in the history
…swift-3

Refactored All APIs for Swift 3
  • Loading branch information
cnoon committed Aug 10, 2016
2 parents a94323c + 8c5a83b commit aebd1d4
Show file tree
Hide file tree
Showing 38 changed files with 3,571 additions and 3,815 deletions.
94 changes: 42 additions & 52 deletions Alamofire.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions Example/Source/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDele
onto primaryViewController: UIViewController)
-> Bool
{
if let secondaryAsNavController = secondaryViewController as? UINavigationController {
if let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController {
return topAsDetailController.request == nil
}
if
let secondaryAsNavController = secondaryViewController as? UINavigationController,
let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController
{
return topAsDetailController.request == nil
}

return false
Expand Down
6 changes: 2 additions & 4 deletions Example/Source/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,11 @@ class DetailViewController: UITableViewController {
options: .skipsHiddenFiles
)

if let fileURL = contents.first,
let data = try? Data(contentsOf: fileURL)
{
if let fileURL = contents.first, let data = try? Data(contentsOf: fileURL) {
let json = try JSONSerialization.jsonObject(with: data, options: JSONSerialization.ReadingOptions())
let prettyData = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)

if let prettyString = NSString(data: prettyData, encoding: String.Encoding.utf8.rawValue) as? String {
if let prettyString = String(data: prettyData, encoding: String.Encoding.utf8) {
try fileManager.removeItem(at: fileURL)
return prettyString
}
Expand Down
20 changes: 11 additions & 9 deletions Example/Source/MasterViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class MasterViewController: UITableViewController {
if let split = splitViewController {
let controllers = split.viewControllers

if let navigationController = controllers.last as? UINavigationController,
let topViewController = navigationController.topViewController as? DetailViewController
if
let navigationController = controllers.last as? UINavigationController,
let topViewController = navigationController.topViewController as? DetailViewController
{
detailViewController = topViewController
}
Expand All @@ -57,30 +58,31 @@ class MasterViewController: UITableViewController {
// MARK: - UIStoryboardSegue

override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
if let navigationController = segue.destination as? UINavigationController,
let detailViewController = navigationController.topViewController as? DetailViewController
if
let navigationController = segue.destination as? UINavigationController,
let detailViewController = navigationController.topViewController as? DetailViewController
{
func requestForSegue(_ segue: UIStoryboardSegue) -> Request? {
switch segue.identifier! {
case "GET":
detailViewController.segueIdentifier = "GET"
return Alamofire.request(.GET, "https://httpbin.org/get")
return Alamofire.request("https://httpbin.org/get", withMethod: .get)
case "POST":
detailViewController.segueIdentifier = "POST"
return Alamofire.request(.POST, "https://httpbin.org/post")
return Alamofire.request("https://httpbin.org/post", withMethod: .post)
case "PUT":
detailViewController.segueIdentifier = "PUT"
return Alamofire.request(.PUT, "https://httpbin.org/put")
return Alamofire.request("https://httpbin.org/put", withMethod: .put)
case "DELETE":
detailViewController.segueIdentifier = "DELETE"
return Alamofire.request(.DELETE, "https://httpbin.org/delete")
return Alamofire.request("https://httpbin.org/delete", withMethod: .delete)
case "DOWNLOAD":
detailViewController.segueIdentifier = "DOWNLOAD"
let destination = Alamofire.Request.suggestedDownloadDestination(
directory: .cachesDirectory,
domain: .userDomainMask
)
return Alamofire.download(.GET, "https://httpbin.org/stream/1", destination: destination)
return Alamofire.download("https://httpbin.org/stream/1", to: destination, withMethod: .get)
default:
return nil
}
Expand Down

0 comments on commit aebd1d4

Please sign in to comment.