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 Decodable
protocol.
// Create models from Data
let responseData = // ... some JSON Data, e.g. from a network response
let user: User? = decodeData(responseData)
let userDecoded: Decoded<User>? = decodeData(responseData)
Arrays of JSON objects are mapped to an array of model instances.
// Create array of models from Data
let responseData = // ... some JSON Data, e.g. from a network response
let tasks: [Task]? = decodeData(responseData)
let tasksDecoded: Decoded<[Task]>? = decodeData(responseData)
Argonaut also supports JSON mapping for ReactiveCocoa 4.0 (Signal and SignalProducer
).
// Create models from JSON dictionary
let jsonSignalProducer: SignalProducer<Any, NSError> = // ...
jsonSignalProducer.mapToType(User).startWithNext { [weak self] user in
// use the User model
}
// Create array of models from array of JSON dictionaries
let jsonSignalProducer: SignalProducer<Any, NSError> = // ...
jsonSignalProducer.mapToTypeArray(Task). startWithNext { [weak self] tasks in
// use the array of Task models
}
Current Swift compatibility breakdown:
Swift Version | Framework Version |
---|---|
3.0 | 4.x |
2.3 | 3.x |
2.2 | 2.x |
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