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

iOS Protocols in Swift Protocol Basics Conforming to a Protocol

Lana Wong
Lana Wong
3,968 Points

Can 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


protocol User {
  var name: String { get }
  var age: Int { get set }

struct Person {

1 Answer

13,273 Points

get & 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