Get Updates By E-mail 

Article Written By:
Johann Dowa

Tutorial: Converting Swift Any Structs To JSON Quickly Using A Protocol And The Reflection API

  •  
  •  
  •  
  •  
  •  

NSJSONSerialization allows you to easily convert an NSArray or NSDictionary to JSON, but does not work directly with Swift structs.

Emil Loer has written a nice tutorial about how you can quickly convert a Swift struct to JSON by using a protocol and the Swift Reflections compatible with NSJSONSerialization , and also how you can easily go a step further so that you can easily serialize data types that are not supported by NSJSONSerialization such as NSDate.

You can find the tutorial over on the Codelle website.

A nice guide on how you can use Swift features to very cleanly convert Swift structs to JSON.


  •  
  •  
  •  
  •  
  •  

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