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 trial

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,407 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.