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 trialbeomsu Kin
2,408 PointsWhy should I call custom init() before super.init() method??
I can't see any reason.
help me plz!!
1 Answer
aaron bentley
4,431 PointsHey mate, Refer to this forum post to find some guidance to your question.
from Swift Programming Language book
“Swift’s compiler performs four helpful safety-checks to make sure that two-phase initialization is completed without error:”
Safety check 1 “A designated initializer must ensure that all of the “properties introduced by its class are initialized before it delegates up to a superclass initializer.”
Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11"
Post found at:
Chokdee Srisuk
19,384 PointsChokdee Srisuk
19,384 PointsThe reason is you have to initilize your local stored properties within your own class and then you are able to call designated initializer of super class. Otherwise swift give you an error just like local stored property not initialized at super.init call.