Struct : Value Type | No Inheritance | No Deinitializers | No Type casting
Class : Reference Type | Inheritance supported | Has Deinitializers | Type casting
Common factors between struct and class:
Both allows to define properties to store values
Both allows to define methods
Both allows to define subscripts
Both allows to define initializers
Both allows extension and protocols
class Bike {
var color: String
init(color:String) {
self.color = color
}
}
var bike1 = Bike(color: "Blue")
var bike2 = bike1
bike1.color = "Red"
print(bike2.color) // prints Red