Skip to content

Instantly share code, notes, and snippets.

@michaelteter
Last active September 18, 2016 17:45
Show Gist options
  • Save michaelteter/2e6017e7df94394e55746f139144d682 to your computer and use it in GitHub Desktop.
Save michaelteter/2e6017e7df94394e55746f139144d682 to your computer and use it in GitHub Desktop.
Reminder of the syntax of Alamofire 4 JSON request
// Remember to add to Info.plist
// App Transport Security Settings / Dictionary
// Allow Arbitrary Loads / Boolean / YES
// (or to be safer, use the Exception Domains subkey to be specific about which domains are allowed non-secure)
import Alamofire
// ...
func example() {
let url = URL(string: "http://pokeapi.co/api/v2/type/3/")!
Alamofire.request(url).responseJSON { response in
switch response.result {
case .success:
print("/ JSON returned in makeRequest: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv")
print(response.result.value)
print("\\ JSON returned in makeRequest: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^")
break
case .failure(let error):
print(error)
break
}
}
// You'll notice this occurs in the console LONG before the request completes.
print("~~~~~~ below request ~~~~~~~~")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment