1 - Properties 2 - Protocols 3 - Backward data passing 4 - Forward data passing
what is difference between class and struct? class is a reference type struct is a value type. Class always requires an initializer, structs don’t require initializer. Inheritance can be implemented in Class but not struct.
1 - computed properties 2 - stored properties 3 - Observer
Computed property
struct contact {
var name: String
var number: Int
var fullContact: String {
return "name is \(name), and number is \(number)"
}
}
var zee = contact.init(name: "zeeshan", number: 3130261452)
print(zee.name)
print(zee.number)
print(zee.fullContact)
Stored Property
struct contact {
var name: String
var number: Int
}
Protocol contains functions that must be used in all that classes that inherit that protocol.
we have to define functions with parameters explicitly.
for eg.
protocol vehicle {
func turn()
func turn(right: String)
}
is possible