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 Swift 2.0 Protocols Swift 2.0 Protocols Conforming to a Protocol

Nikita Voloboev
Nikita Voloboev
4,816 Points

how come this code doesn't pass the test, the struct should satisfy the protocol or am I mistaken?

I am really confused as to why that code doesn't pass. I made age a constant since its a 'get /set'. I am really confused about { get set } and what it means but from what I've read this should work. Where did I make the mistake?

protocols.swift
protocol UserType {
    var name: String { get }
    var age: Int { get set }
}

struct Person {
    var name: String
    let age: Int
}

let somePerson = Person(name: "nikita", age: 21)

1 Answer

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

Change age from let to var and your code will pass! The variable age should not be a constant :)

Jacob Bergdahl
Jacob Bergdahl
29,118 Points

Oh, sorry, you must of course also infer to the UserType. Person is a UserType. Therefor, it must say Person: UserType.