O'Reilly logo

Swift Functional Programming - Second Edition by Dr. Fatih Nayebi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Argo models

Whenever we receive a JSON payload from the backend, we will be able to use the decode function to decode our JSON payload to our model:

let data: Data? = nil let json: Any? = try? JSONSerialization.jsonObject(with: data!,                                                       options: []) if let j: Any = json {     let todo: Todo? = decode(j) } 

We can see that Argo can be leveraged as an example to master lots of FP paradigms. Using Argo, Curry, and custom operators, we are able to parse and decode JSON payloads to our model objects declaratively. Also, our models become immutable value types that we can use in our applications without being concerned about mutability.

Also, we defined an enum called TodoFilter. We will use this enum to filter items.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required