Type¶
Structures¶
A data type for storing multiple values.¶
Overview¶
Structures are complex objects that can store constants, variables, and functions.
For example, a structure can be used to create a user object with a welcome message that's shared across your application.
struct ExampleView: View {
var Kalil = User(name: "Kalil", age: 21)
var body: some View {
Text(Kalil.createWelcomeMessage())
}
}
struct User {
var name: String;
var age: Int;
func createWelcomeMessage()->String {
return "Hey \(name)! Welcome to Banana🍌 Docs🙂"
}
}
See Apple's Struct documention for the official guide. To quickly reference the difference between a Struct and a Class, see slide 24 of this Stanford lecture. To learn more about Struct vs Class, watch 15:30 to 28:00 of this Stanford lecture which explains both well.