Differences between init() methods

What are the differences between :

convenience init()

required init()

override init()

init()

I am getting error, where I have two init methods. convenience init() and init()

Error is : ‘self’ used before super.init call

I have write super.init(), then also no luck. Please let me know about above methods.

I’m kinda new to Swift, but from what I understand, the convenience init() is used to provide alternate constructors to your class, so you get different ways of creating your instances. Your convenience declaration has to be different from any other init() you might already have.

For example, a CGPoint can be instanciated with no params, ‘x’ and ‘y’ as CGFloats, as doubles, ints, etc. Behind the scenes, I’m pretty sure they do the exact same thing, but the different param types let you create a CGPoint without having to typecast.

hope it helps a little!

1 Like

Thanks for your time.

Tutorial available on this topic https://www.raywenderlich.com/119922/swift-tutorial-initialization-part-1

2 Likes