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 trialNikita Voloboev
4,816 Pointshow 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?
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
29,119 PointsChange age from let to var and your code will pass! The variable age should not be a constant :)
Nikita Voloboev
4,816 PointsNikita Voloboev
4,816 Pointsstill does not pass :(
Jacob Bergdahl
29,119 PointsJacob Bergdahl
29,119 PointsOh, sorry, you must of course also infer to the UserType. Person is a UserType. Therefor, it must say Person: UserType.