Get Updates By E-mail 

Article Written By:
Johann Dowa

An Open Source Library That Makes Working With JSON Data Using Swift Much Easier

  •  
  •  
  •  
  •  
  •  

Handling JSON data can be difficult using Swift because of Swift’s strictness with types.

Here’s a library that makes handling Swift in much easier called SwiftyJSON from Ruoyu Fu.

SwiftyJSON makes things much simpler automatically handling different types of data.

This example from the readme shows the mess caused from using NSJSON to handle parsing the user and name from JSON data even when using chaining:

let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil)
if let userName = (((jsonObject as? NSArray)?[0] as? NSDictionary)?["user"] as? NSDictionary)?["name"]{
  //What A disaster above
}

While with SwiftyJSON you could use something like:

let json = JSONValue(dataFromNetworking)
if let userName = json[0]["user"]["name"].string{
  //Now you got your value
}

SwiftyJSON also handles wrapping of values, and handling incorrect keys.

You can find SwiftyJSON on Github here.

A nice library for working with JSON with Swift.


  •  
  •  
  •  
  •  
  •  

Submit A Resource

Have you created a useful tutorial, library or tool for iOS development that you would like to get in front of our 300,000+ monthly page views from iOS developers?

You can submit the url here.

The resources we feel will appeal to our readers the most will be posted on the front page.

Comments