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 trialLucas Wang
5,588 PointsReceiving irrelevant error in "Protocol Inheritance" code challenge
The error is telling me that I'm not implementing a method as specified in the directions but there's nothing in the directions asking me to implement a method!
Directions: "In the editor, I've provided a simple protocol to represent an animal.
For the first task, create a protocol named Pet which should inherit from Animal and require an additional gettable stored property, cuddlyName, of type String."
Error: "Make sure you are adding the method requirement as specified in the question to the Pet protocol"
protocol Animal {
var numberOfLegs: Int { get }
}
protocol Pet : Animal {
var cuddlyName : String { get }
}
1 Answer
Jennifer Nordell
Treehouse TeacherHi there! It's not entirely irrelevant. It can't see the method. Keep in mind that the get
is a special kind of method called an accessor method. The problem here is that you have an extra space between your variable name and the type of the variable:
//You wrote
var cuddlyName : String { get }
// It wants
var cuddlyName: String { get }
Note the removal of the space between cuddlyName
and the colon.
Hope this helps!
Lucas Wang
5,588 PointsLucas Wang
5,588 PointsThanks for clarifying it! I
Jennifer Nordell
Treehouse TeacherJennifer Nordell
Treehouse TeacherOn a side note, this would not cause a compiler error that I'm aware of, but it is confusing the challenge checker for some reason!