How to call REST APIs with AlamoFire and Swift

Alamofire is a networking API that leverages the full power of Swift.

Reference:
http://www.raywenderlich.com/85080/beginning-alamofire-tutorial
https://github.com/Alamofire/Alamofire

alamofire

alamofire

Here is sample how to call REST APIs with AlamoFire.

import UIKit
import Alamofire

class ViewController: ViewController {

    var user: [JSON] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()

        Alamofire.request(.GET, "https://api.github.com/users/datomnurdin").responseJSON { (request, response, json, error) in
            if json != nil {
                var jsonObj = JSON(json!)
                if let data = jsonObj["user"].arrayValue as [JSON]?{
                    println(data)
                }
            }
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *