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 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,119 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,119 Points

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