Type¶
Class¶
A data type for storing multiple values.¶
Overview¶
Classes are complex objects that can store constants, variables, and functions. Unlike a Struct they are a reference type.
For example, a class can be used to create a mutable user object with a welcome message that's shared across your application.
struct ExampleView: View {
var Kalil: MyUser = MyUser()
init() {
Kalil.name = "Alex"
}
var body: some View {
Text(Kalil.createWelcomeMessage()) // "Hey Alex Welcome to Banana🍌 Docs🙂"
}
}
class MyUser {
var name: String = "Kalil";
var age: Int = 21;
func createWelcomeMessage()->String {
return "Hey \(name)! Welcome to Banana🍌 Docs🙂"
}
}