Stored Properties
Stored Properties
Introduction
Hello,
Property is added to define the properties of an object.
In order to add a property to an object in Swift, the variable or constant definition must be added to the type definition.
const
Properties are not limited to class definitions in Swift. Enumerations and structures can also have property declarations.
class Person {
var name: String = "Name"
var age:Int = 0
func profile() -> String {
return "I'm \(self.name) and I'm \(self.age) years old."
}
}
var p = Person()
p.name = "Coddy"
p.age = 10
print("p.name = \(p.name)")
print("p.age = \(p.age)")