The TaskAPI will accept new tasks as POST requests containing JSON representations of the tasks and will return all the existing tasks via GET requests.
First, let's define a task – in the App group of your Xcode project, create a new file called Task.swift in a new group called Models.
After creating this file, ensure that it is a member of the App target and not any others. The Target Membership panel for our new file should look like this:
Figure 8.2 – Target membership
Now, let's define our task as having two properties: description and category, plus an identifier:
class Task {
let id: String
var description: String
var category: String
init(id: String, description: String, category: String) {
self.id = id
self.description = description
self.category = category
}
}
We can now create a Task in code, like this:
let task = Task(id: "1", description: "Remember the milk", category:
"shopping")
However, we...