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

Listing Todo items

To retrieve all Todo items, unlike our post call, we do not need to pass any header parameters, just cookie information. So, we add the following struct to handle this scenario:

struct RequestModel: RequestProtocol {     subscript(key: String) -> (String?, String?) {         get {             switch key {                 default: return ("Cookie","test=123")             }         }     } } 

Then, we can retrieve a list of Todo items using the following code:

sendRequest(Urls.getTodos, request: RequestModel()) {     (response, error) in     if error == nil {         let todos: [Todo]? = decode(response!)         completion(todos, nil)         print("request was successfull: \(todos)")     } else {         completion(nil, error)         print("Error: \(error?.localizedDescription)")     } } 

Although we added better error ...

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