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

Christopher Thiebaut
Christopher Thiebaut
2,736 Points

Challenge task 2 of 2 fails for no apparent reason.

My code runs fine in Xcode and has no errors or warnings. In the web-based editor here on Treehouse, it fails and says I need to make sure Dog conforms to Pet (which it does). In the past, I've had code challenges fail due to different whitespace. Is that what's happening here? What am I missing?

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

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

struct Dog : Pet {
  var numberOfLegs: Int = 4
  var cuddlyName: String
}

1 Answer

Matthew Long
Matthew Long
28,379 Points

Only thing I could find "wrong" with your code is the space between the Dog struct name and the colon? Maybe this is an issue with how treehouse is checking that you completed the challenge? Xcode doesn't show that space as an error or warning.

protocol Animal {
  var numberOfLegs: Int { get }
}

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

struct Dog: Pet {
  var numberOfLegs: Int
  var cuddlyName: String
}
Christopher Thiebaut
Christopher Thiebaut
2,736 Points

Thanks, it turns out that was the problem.