A collection of (reactive) JSON parsing helpers for the Argo JSON parser.
The Argonauts were a band of heroes in Greek mythology. Their name comes from their ship, the Argo, named after its builder, Argus.
Map JSON responses to instances of your model objects. The model object needs to conform to Argo’s JSONDecodable
protocol.
// Create models from NSData
let responseData = // ... some JSON NSData, e.g. from a network response
let user: User = mapJSON(responseData)
// Create models from dictionary
let responseDict = // ... [String: AnyObject]
let user: User = mapJSON(responseDict)
Arrays of JSON objects are mapped to an array of model instances.
// Create array of models from NSData
let responseData = // ... some JSON NSData, e.g. from a network response
let tasks: [Task] = mapJSONArray(responseData)
// Create array of models from array of dictionaries
let responseDict = // ... [[String: AnyObject]]
let tasks: [Task] = mapJSON(responseDict)
Argonaut also supports JSON mapping on ReactiveCocoa signals.
// Create models from JSON dictionary
let jsonSignal = // ... emits [String: AnyObject]
jsonSignal.mapToObject(User.self).subscribeNext({ [weak self] user in
// use the User model
}, error: { error in
// Error in the ArgonautErrorDomain
println(error)
})
// Create array of models from array of JSON dictionaries
let jsonSignal = // ... emits [[String: AnyObject]]
jsonSignal.mapToObjectArray(Task.self).subscribeNext({ [weak self] tasks in
// use the array of Task models
}, error: { error in
// Error in the ArgonautErrorDomain
println(error)
})
Add the following line to your Cartfile.
github "aschuch/Argonaut”
Then run carthage update
.
Just drag and drop the three .swift
files in the Argonaut
folder into your project.
Open the Xcode project and press ⌘-U
to run the tests.
Alternatively, all tests can be run from the terminal using xctool.
xctool -scheme ArgonautTests -sdk iphonesimulator test
- Update to ReactiveCocoa swift (generic Signal)
- CocoaPods support
- Create something awesome, make the code better, add some functionality, whatever (this is the hardest part).
- Fork it
- Create new branch to make your changes
- Commit all your changes to your branch
- Submit a pull request
Feel free to get in touch.
- Website: http://schuch.me
- Twitter: @schuchalexander