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

Dan Sabin
PRO
Dan Sabin
Pro Student 1,909 Points

It seems like the either the prompt or the check are not in sync for this question. Any idea on how to proceed

I've tried creating a gettable type, but the "error" says I need to make a function. I tried guessing what function they might be asking to see if the prompt would change and give me more information, no luck. Not sure how to proceed.

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

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

1 Answer

Charles Kenney
Charles Kenney
15,604 Points

The problem is, you set your Pet protocol's gettable 'cuddlyName' property to a constant when it should be a variable. Your protocols should look like this:

protocol Animal {
  var numberOfLegs: Int { get }
}

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

So our struct, dog should look like this:

struct dog: Pet {
  var numberOfLegs: Int
  var cuddlyName: String
}

Hope this answers your question. -Charles