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 we have done this. First of all, this is an example of Protocol-Oriented Programming and second, we will use this request model in our post web service call.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset