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

Conforming to the request protocol

Now, let's create a request model named TodoRequest:

struct TodoRequest: RequestProtocol {     let todoId: Int     let name: String     let description: String     let notes: String     let completed: Bool     let synced: Bool     subscript(key: String) -> (String?, String?) {         get {             switch key {             case "todoId": return (String(todoId), "todoId")             case "name": return (name, "name")             case "description": return (description, "description")             case "notes": return (notes, "notes")             case "completed": return (String(completed), "completed")             case "synced": return (String(synced), "synced")             default: return ("Cookie","test=123")             }         }     } } 

As shown in the preceding code, this struct conforms to RequestProtocol. You might wonder why ...

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