Created
February 15, 2017 06:21
-
-
Save mwrites/5ec473243954df2bdea72052f85480ce to your computer and use it in GitHub Desktop.
JsonDic parsing helper
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
struct JsonDic { | |
let dic : [String:AnyObject] | |
func integer(key: String) throws -> Int { | |
guard let s = dic[key] as? Int else { throw ResourceError.parseWrongType(key) } | |
return s | |
} | |
func string(key: String) throws -> String { | |
guard let s = dic[key] as? String else { throw ResourceError.parseWrongType(key) } | |
return s | |
} | |
func dictionary(key: String) throws -> JsonDic { | |
guard let d = dic[key] as? JsonDic else { throw ResourceError.parseWrongType(key) } | |
return d | |
} | |
} | |
enum ResourceError : Swift.Error { | |
case parseType(String) | |
case parseWrongType(String) | |
case parseClosure | |
case jsonParsing | |
case serverErrorCode(Int) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment