enum JSONError: String, ErrorType {
case NoData = "ERROR: no data"
case ConversionFailed = "ERROR: conversion from JSON failed"
}
func jsonParser() {
let urlPath = "http://headers.jsontest.com/"
guard let endpoint = NSURL(string: urlPath) else { print("Error creating endpoint");return }
let request = NSMutableURLRequest(URL:endpoint)
NSURLSession.sharedSession().dataTaskWithRequest(request) { (data, response, error) -> Void in
do {
guard let dat = data else { throw JSONError.NoData }
guard let json = try NSJSONSerialization.JSONObjectWithData(dat, options: []) as? NSDictionary else { throw JSONError.ConversionFailed }
print(json)
} catch let error as JSONError {
print(error.rawValue)
} catch {
print(error)
}
}.resume()
}
Tuesday, 15 March 2016
SWIFT: SERVICE CALL IOS9
Subscribe to:
Post Comments (Atom)
Setting Up Multiple App Targets in Xcode from a Single Codebase
To create two different apps (like "Light" and "Regular") from the same codebase in Xcode, you can follow these steps b...
-
if u want to open in same window - ( WKWebView *) webView :( WKWebView *) webView createWebViewWithConfiguration :( WKWebViewConfigurat...
-
To create two different apps (like "Light" and "Regular") from the same codebase in Xcode, you can follow these steps b...
-
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"prefs:root=General&path=Network"]]; List of curre...
No comments:
Post a Comment