Self property in Swift

Every instance of a type has a implicit property called self. This property refers to the current instance itself within its own methods. When a method parameter name is same as one of the properties defined inside a instance, then the parameter name takes precedence and Swift will treat both the parameter name and instance property as parameter name. In this case, we have to use self along with instance property to distinguish it from parameter name.



Leave a Reply