Create a Podfile and replace the text with the code below. And run a Pod Install
platform :ios, '9.0'
use_frameworks!
target 'AlamofireSwiftyJSONSample' do
pod 'Alamofire'
pod 'SwiftyJSON'
end
Create a Podfile and replace the text with the code below. And run a Pod Install
import Alamofire
import SwiftyJSON
Paste the code below in viewDidLoad() method of your ViewController class
Alamofire.request("https://jsonplaceholder.typicode.com/posts/1", method: .get).validate().responseJSON { response in
switch response.result {
case .success(let value):
let json = JSON(value)
print(json)
print("User ID: " + json["userId"])
print("Title: " + json["title"])
print("Body: " + json["body"])
case .failure(let error):
print(error)
}
}