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 trialNIKOLA RUSEV
5,293 Pointsconforming protocol computed properties
In protocol person we have computed stored properties that must be declared as a variable but when struct user conform to protocol person stored properties are declared as constant. Why compailer dont rise an error??? is that becouse computed stored properties are declared as gettable?
1 Answer
Jesse Gay
Full Stack JavaScript Techdegree Student 14,045 PointsI think you're on the right track. If you try to use let in the protocol definition, Xcode says "Immutable property requirement must be declared as 'var' with a '{get}' specifier." From Apple Docs: If a protocol requires a property to be gettable and settable, that property requirement cannot be fulfilled by a constant stored property or a read-only computed property. If the protocol only requires a property to be gettable, the requirement can be satisfied by any kind of property, and it is valid for the property to be also settable if this is useful for your own code.
Property requirements are always declared as variable properties, prefixed with the var keyword. Gettable and settable properties are indicated by writing { get set } after their type declaration, and gettable properties are indicated by writing { get }.