Skip to Content
Creating an Instance

Instances are how we create individual objects using a structure. In the previous exercise’s example, we created a structure to model dogs:

struct Dog { var age = 0 var isGood = true }

In Dog, we’ve modeled some general traits dogs have. However, each dog is unique in their own way — to represent this programmatically, we have to create different instances of dogs!

var eloise = Dog()

In the example above we’ve created a single instance of the Dog struct by adding parentheses () to Dog and save it to the eloise variable.



Given the Book structure, create an instance of Book and save it to a variable called myFavBook.

Folder Icon

Take this course for free

Already have an account?