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 trialLana Wong
3,968 PointsCan someone please explain more about get set with protocols?
Hi. I'm a bit confused on setting a get set property in the protocol. Can someone please explain more about it? Thanks
Lana
protocol User {
var name: String { get }
var age: Int { get set }
}
struct Person {
}
1 Answer
tromben98
13,273 Pointsget & set decides how a certain property can be used. If a property is getable you can only retrieve the value that the property contains, while if the property is gettable and settable you can retrieve the the value of the property and also manipulate that value. So if you look att your protocol you can see that you can only retrieve the name of the user while you can retrieve and change the age of the user.
Best regards Jonas