Skip to content

Instantly share code, notes, and snippets.

@b3ll
Created May 14, 2016 08:59
Show Gist options
  • Save b3ll/75959235c67e0cd147504146e17a2cfa to your computer and use it in GitHub Desktop.
Save b3ll/75959235c67e0cd147504146e17a2cfa to your computer and use it in GitHub Desktop.
Blazingly-Fast JSON Parser written in Swift
import Foundation
public typealias JSON = AnyObject
public func JSONWithData(data: NSData) -> JSON? {
do {
let j = try NSJSONSerialization.JSONObjectWithData(data, options: [])
return j
} catch _ {
return nil
}
}
@AliSoftware
Copy link

AliSoftware commented May 14, 2016

That's way too much complicated. You could have written it in 3 lines only.

import Foundation
public typealias JSON = AnyObject
let JSONWithData: NSData -> JSON? = { try? NSJSONSerialization.JSONObjectWithData($0, options: []) }

@hectormatos2011
Copy link

Still too complicated. You could've written it in two lines:

import Foundation
let JSONWithData: NSData -> AnyObject? = { try? NSJSONSerialization.JSONObjectWithData($0, options: []) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment