12.1 An Overview of Swift Structures
As with classes, structures form the basis of object-oriented programming and provide a way to encapsulate data and functionality into re-usable instances. Structure declarations resemble classes with the exception that the struct keyword is used in place of the class keyword. The following code, for example, declares a simple structure consisting of a String variable, initializer and method:
struct SampleStruct {
var name: String
init(name: String) {
self.name = name
}
func buildHelloMsg() {
"Hello " + name
}
}
Consider the above structure declaration in comparison to the equivalent class declaration:
class...