Learn
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.
Instructions
1.
Given the Book
structure, create an instance of Book
and save it to a variable called myFavBook
.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.