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 trialCody Adkins
7,260 PointsWhy did we not have to write the Name and ID, to conform to User type in the extension of User type?
Does Swift already know that those properties are in the User type? So we do not have to explicitly write it out...
1 Answer
Steven Deutsch
21,046 PointsHey Cody Adkins,
You do not need to specify the name and ID in the User type's extension for a few reasons. Mainly, because these two properties are not specified in the PrettyPrintable protocol that you are conforming User to. The purpose of this extension is to achieve protocol conformance. You do this by implementing the properties and methods that the protocol specifies.
Remember that extensions are just a way to add additional functionality to a type in Swift. The User type already has the name and ID properties listed inside of them. Therefore, redeclaring them in an extension would be repetitive and trigger a compiler error for the invalid redeclaration.
Good Luck