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

Fred Waltman
Fred Waltman
336 Points

I guess I don't understand the question

Error message does not match the question

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

protocol Pet : Animal {
  var cuddlyName : String { get }
}

1 Answer

David Papandrew
David Papandrew
8,386 Points

You have extra leading spaces before the colons in your code.

Remove those and you should be fine.

Here's is what I mean (this code will pass):

protocol Animal {
  var numberOfLegs: Int { get }
}

protocol Pet: Animal {      //Removed space after Pet and colon
  var cuddlyName: String { get }    //Removed space after cuddlyName and colon
}
Fred Waltman
Fred Waltman
336 Points

Thanks.

The error message I was getting was

"Make sure you are adding the method requirement as specified in the question to the Pet protocol"

Not very helpful. The preview showed no errors.

Any why is the space a problem? Not a problem in the Swift syntax, I tend to leave a space before and after (It's a habit from a previous environment) and never had a problem with Xcode.

I find it frustrating that there isn't an option to just give up and go on. I gave up on Treehouse a couple years ago or so ago because of that reason and I guess is a pet peeve of mine.

David Papandrew
David Papandrew
8,386 Points

Hi Fred,

All I know is that the Treehouse challenges are pretty strict about uppercase/lowercase, spaces and the like. Not something I can control so I can understand the frustration. Just something that I try to look for when I find my code not passing.

Good luck.