Daniel Shin
Daniel Shin

Reputation: 5206

Swift superclass property/method access: self vs super

In swift, it seems that superclass's property or method can be accessed through both self and super without any compile issue.

I do know that when you need to override superclass's property or method, it is mandatory to use super to disambiguate.

But when you simply want to access shared method from superclass, which one is more appropriate?

I tend to prefer super since I personally think it makes a more readable code but not sure what the best practice is.

Thank you!

Upvotes: 1

Views: 1549

Answers (1)

Rohit
Rohit

Reputation: 965

If method is overridden, then self can be used to access method in a subclass otherwise for accessing method of a super class from a base class best practice is to use super.

Upvotes: 3

Related Questions