June 2015
Intermediate to advanced
192 pages
4h 8m
English
Of course, you can invoke the NSJSONSerialization.dataWithJSONObject method from Swift, too, which returns an NSData object that you can then convert to a string.
Here's a simple example:
var error: NSError? var data: NSJSONSerialization.dataWithJSONObject( dictionary, options: NSJSONWritingOptions(0), error: &error); var json: NSString(data: data, encoding: NSUTF8StringEncoding);
The method dataWithJSONObject operates just as its Objective-C counterpart does. Once we receive NSData containing the JSON-encoded version of the dictionary, we convert it to NSString using the NSString constructor.
Read now
Unlock full access