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 Intermediate Swift 2 Extensions and Protocols Protocol Conformance Using Extensions

Paul M
Paul M
16,370 Points

What did the "get" mean in the protocol?

When he put the keyword get in the protocol like this,

protocol UniqueType {
    var id: Int {
        get
    }
}

what did the keyword "get" mean in the protocol and what is it used for?

1 Answer

Tassia Castro
seal-mask
.a{fill-rule:evenodd;}techdegree
Tassia Castro
iOS Development Techdegree Student 9,170 Points

It means that whoever conforms to this protocol is able to declare its “id” property as both ‘var’ or ‘let’

If the protocol was this way:

protocol UniqueType {
    var id: Int { get  set }
}

Then, whoever conforms to this protocol is not allowed to declare the property ‘id’ as ‘let’ (constant). So if you tried to do this:

class Type: UniqueType {
    let id: Int 
}

You would get an error saying that your class ‘Type’ does not conform to protocol ‘UniqueType’

Jay Siddik
Jay Siddik
11,901 Points

|| this means .... what ? (Quiz) Mash