This article is part of a series on learning Swift by writing code to The Swift Programming Language book from Apple. This is the ninth article in Section 2 (here is Section 1)
Read each article after you have read the corresponding chapter in the book. This article is a companion to Initialization.
If you are jumping around these articles, make sure you read the Introduction to see my recommendation for setting up a reading environment.
To add a new page, in Xcode:
At this point, you should have read Initialization in The Swift Programming Language. You should have a Playground page for this chapter with code in it that you generated while reading the book.
For these exercises, we are going to imagine a to do app
In your Playground write code to do the following:
ToDoItemwith two properties: A string named
titleand a bool named
initthat only takes a
titleparameter and sets
ToDoListwith a variable array called
ToDoItemthat is uninitialized
initthat takes no parameters and sets
itemsto an empty list
initthat takes an array of items and uses it to initialize the list
initthat takes items and change the parameter so that every item is checked and then call
super.initto set the items list
The next article will provide exercises for the DeInitialization chapter.