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 trialUnsubscribed User
12,874 PointsWhy do we put failable initialiser of Contact struct inside an extension?
Is there any particular reason the Key Struct and failable init methods for the Contact Struct are inside an extension. What the advantages compared with keeping inside the struct itself?
2 Answers
Bertram Srugies
4,704 PointsIt is more a convention in the Swift community as far as i understand. You always want the struct to have a clear purpose, so additional functionality is added via an extension resulting in code that is easier to read.
Amazon Web
iOS Development Techdegree Student 4,092 PointsFirst, we put init method in the extension of a struct to avoid overriding the memberwise init method of a struct. Second, we use extension to group the code.