Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGavin Hobbs
5,205 PointsWhat is the 'super' thing?
What is the 'super' keyword and what does it do? For example, in this video they had me write some of this...
override func viewDidLoad() {
super.viewDidLoad()
funFactLabel.text = "An interesting fact!"
}
But I didn't really understand what Pasan was saying about the Super.viewDidLoad()
. Especially the Super
part.
Can anyone explain this better than Pasan did?
Thanks!
2 Answers
Sarah Hurtgen
Treehouse Project ReviewerThe "super" refers to the super class, or "parent" class, that your current subclass is inheriting from. I don't think I can explain it better than Pasan, but looking at your example I'm guessing you're in the Build a simple iPhone App course, and I'm not sure how much detail he would go into there for subclassing.
I recommend the Object Oriented Swift Course section on Class Inheritance, and specifically, in the second video, Overriding Properties, he explains this concept in more detail.
Hope that helps!
Luke Pettway
16,593 PointsSuper stands for the superclass of the class where the method definition is. It simply specifies where to search for a method should begin. It is usually considered to call super for all function overrides that don't return a value. There could be something going on within the super (parent) that you aren't aware of, and not allowing it to run could cause all sorts of problems, so that's why it is called within the override before you pass in your own changes to the method.