Last active
August 29, 2015 14:22
-
-
Save cojoj/0eed4e67848d3f592310 to your computer and use it in GitHub Desktop.
ErrorType vs NSError
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class func parse(data: NSData) -> (AnyObject?, NSError?) { | |
do { | |
// From docs: If an error occurs, upon return contains an NSError object that describes the problem. | |
let obj = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) | |
return (obj as AnyObject, nil) | |
} catch { | |
// But here I get: ErrorType is not convertible to NSError | |
return (nil, error) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return (nil, error as NSError)
thanks toErrorType
bridging toNSError
. You can alsocatch let error as NSError
becausecatch
here is a shorthand forcatch let error
. Docs