Arrow is an elegant JSON parsing library in Swift.
It allows to parse JSON and map it to custom model classes with help of an <--
operator:
identifier <-- json["id"]
name <-- json["name"]
stats <-- json["stats"]
Example:
Swift model
struct Profile {
var identifier = 0
var name = ""
var link: NSURL?
var weekday: WeekDay = .Monday
var stats = Stats()
var phoneNumbers = [PhoneNumber]()
}
JSON file
{
"id": 15678,
"name": "John Doe",
"link": "https://apple.com/steve",
"weekdayInt" : 3,
"stats": {
"numberOfFriends": 163,
"numberOfFans": 10987
},
"phoneNumbers": [{
"label": "house",
"number": "9809876545"
}, {
"label": "cell",
"number": "0908070656"
}, {
"label": "work",
"number": "0916570656"
}]
}
Mapping
extension Profile: ArrowParsable {
mutating func deserialize(json: JSON) {
identifier <-- json["id"]
link <-- json["link"]
name <-- json["name"]
weekday <-- json["weekdayInt"]
stats <- json["stats"]
phoneNumbers <-- json["phoneNumbers"]
}
}
Usage
let profile = Profile()
profile.deserialize(json)
Installation:
Carthage
github "s4cha/Arrow"
CocoaPods
pod 'Arrow'
use_frameworks!
Manually
Simply Copy and Paste Arrow.swift in your Xcode Project
https://github.com/s4cha/Arrow
As A Framework
Download Arrow from the GitHub repository and build the Framework target on the example project. Then Link against this framework.