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 Protocols in Swift Creating Flexible Objects Using Protocols Protocol Inheritance

Lucas Wang
Lucas Wang
5,588 Points

Receiving 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"

protocols.swift
protocol Animal {
  var numberOfLegs: Int { get }
}
protocol Pet : Animal {
  var cuddlyName : String { get }
}

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Teacher

Hi 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! :sparkles:

Lucas Wang
Lucas Wang
5,588 Points

Thanks for clarifying it! I

Jennifer Nordell
Jennifer Nordell
Treehouse Teacher

On 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! :smiley: