Skip to content

Instantly share code, notes, and snippets.

@feighter09
Last active August 12, 2016 05:07
Show Gist options
  • Save feighter09/4937cf2fec37562f2aecbaceb2077e0c to your computer and use it in GitHub Desktop.
Save feighter09/4937cf2fec37562f2aecbaceb2077e0c to your computer and use it in GitHub Desktop.
First time networking in iOS
import UIKit
import Alamofire
import SwiftyJSON
class ViewController: UIViewController {
convenience init() { self.init(nibName: "ViewController", bundle: nil) }
@IBOutlet weak var label: UILabel!
override func viewDidLoad()
{
super.viewDidLoad()
let url = "http://httpbin.org/post"
let params = ["param": "feighter09"]
request(.POST, url, parameters: params).response { _, _, data, error in
if let jsonData = data where error == nil {
let json = JSON(data: jsonData)
self.label.text = "Username: " + json["form"]["param"].stringValue
}
else {
self.label.text = "Request failed"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment