Understanding structures
Like classes, structures also group together properties and methods used to represent an object and do specific tasks. Remember the Animal
class you created? You can also use a structure to accomplish the same thing. There are differences between classes and structures though, and you will learn more about those later in this chapter.
Here’s what a structure declaration and definition look like:
struct StructName {
property1
property2
property3
method1() {
code
}
method2(){
code
}
}
As you can see, a structure is very similar to a class. It also has a descriptive name, can contain properties and methods, and you can create instances.
To learn more about structures, visit https://docs.swift.org/swift-book/documentation/the-swift-programming-language/classesandstructures.
Let’s look at how to work with structures. You’ll learn how to declare and define structures, create...