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 trialChase Maddox
Courses Plus Student 5,461 PointsBeginning Protocol Code Challenge #1
Hi,
Why is the Code Challenge not accepting my answer? It gives the error, "Make sure User specifies a gettable property named name
of type String", but I thought I did specify a gettable property named 'name'.
Thanks, Chase
protocol User {
var name: String {get}
var age: Int {get set}
}
3 Answers
Mika Kiela
2,178 PointsHi Chase!
You should just use spaces around the gettable and settable. Like this:
protocol User { var name: String { get } var age: Int { get set } }
doesitmatter
12,885 PointsPasan Premaratne
In the first challenge we are asked to make make a user protocol, in doing so the following fails:
protocol User{
var name : String {get}
var age : Int {get set}
}
even though it does work in XCODE
This passes the challenge:
protocol User{
var name: String { get }
var age: Int { get set }
}
I think it is too strict, if XCode has no problem with it why should it matter? Also the hints don't point out to the fact that it is a syntax problem.
Mika Kiela
2,178 Pointsdoesn't pass, why?
The Colons after the variables, must be right after 'name' and 'age'. So there is two extra spaces over there.
Example:
protocol User{
var name: String { get }
var age: Int { get set }
}
doesitmatter
12,885 Pointsdoesitmatter
12,885 Pointsdoesn't pass, why?
Chase Maddox
Courses Plus Student 5,461 PointsChase Maddox
Courses Plus Student 5,461 PointsAwesome, that did it! Thanks Mika!