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 trial
Anthony Babich
5,505 PointsWhy would you write a protocol with a var but make it { get } and not { get set }
I think the question is straight forward. I'm confused. So in some of the iOS Swift 2.0 videos I've seen the instructor create a protocol with a variable but mark it as { get }
Isn't { get } read only? So wouldn't { get } always be a constant of let declaration?
3 Answers
garyguermantokman
21,097 PointsHey,
In short, property requirements are always declared as variables.
This is defined in the Swift Programming Language.
Check out the protocol docs to learn more Apple Protocol docs
jcorum
71,830 PointsAnthony, here's another bit from the Apple documentation:
Read-Only Computed Properties
A computed property with a getter but no setter is known as a read-only computed property. A read-only computed property always returns a value, and can be accessed through dot syntax, but cannot be set to a different value.
NOTE You must declare computed properties—including read-only computed properties—as variable properties with the var keyword, because their value is not fixed. The let keyword is only used for constant properties, to indicate that their values cannot be changed once they are set as part of instance initialization.
Anthony Babich
5,505 PointsThanks a lot for the responses. I do enjoy treehouse but I wish similarly to the Swift tutorials that they would start from scratch instead of throwing all this crap at me all at once. There's just so much!!!.... So, until I figure out why I feel so confused I am going to read the documentation. Thanks a lot.