Blueprinting the Shopping List Item model

Now that we understand the files and folders in our projects a little bit, let's start writing some code. We will begin by writing code for our first model, the Shopping List Item. To do so, perform the following steps:

  1. Create a new group called Models under the ShoppingList folder in your project.
  2. Then right-click and click on New File... under the Models folder and select a Swift file from the iOS template. Call this new file Item.swift and click Create.

 

  1. Copy the following code into the Item.swift file:
import UIKitclass Item {    var name: String    var isChecked: Bool    init(name: String, isChecked: Bool = false) {        self.name = name        self.isChecked = isChecked    }}

Let's go over the code in more detail: ...

Get Hands-On Full-Stack Development with Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.