Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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