Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@benrigas
benrigas / Swift JSON Playground
Last active November 2, 2017 14:51
Swift Playground for initializing objects from Dictionary/JSON
// Playground - noun: a place where people can play
import Cocoa
extension String {
func dictionaryFromJSON () -> Dictionary<String, AnyObject>? {
if let dict = NSJSONSerialization.JSONObjectWithData(self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true),
options: .AllowFragments,
error: nil) as? Dictionary<String,AnyObject>
{