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.