Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Created August 6, 2016 15:19
Show Gist options
  • Save KentarouKanno/0dc978ae57f862c8baacae2dd11b104d to your computer and use it in GitHub Desktop.
Save KentarouKanno/0dc978ae57f862c8baacae2dd11b104d to your computer and use it in GitHub Desktop.
Alamofire

Alamofire

Alamofire

★ 基本的な使い方

import UIKit
import Alamofire

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // String
        let stringURL = "https://httpbin.org/get"
        
        // NSURL
        let nsURL = NSURL(string: "https://httpbin.org/get")!
        
        // NSURLRequest
        let nsURLRequest = NSURLRequest(URL: nsURL)
        
        // NSURLComponents
        let nsURLcomponents = NSURLComponents(string:"https://httpbin.org/get")!
        
        Alamofire.request(.GET, nsURLcomponents, parameters: ["foo": "bar"])
            .responseJSON { response in
                print(response.request)  // original URL request
                print(response.response) // URL response
                print(response.data)     // server data
                print(response.result)   // result of response serialization
                
                if let JSON = response.result.value {
                    print("JSON: \(JSON)")
                }
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment