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 Intermediate Swift 2 Extensions and Protocols Extensions and Protocols

Alex Millius
Alex Millius
iOS Development Techdegree Student 5,468 Points

Incorrect answer

I think the response for this question is false

protocol SomeProtocol {
    func someMethod() -> Int

extension SomeProtocol {
    func someMethod() -> Int {
        return 1

struct SomeStruct: SomeProtocol {
    func someMethod() -> Int {
        return 2

let b: SomeProtocol = SomeStruct()

What is the value returned from the someMethod() call

The quizz says that the correct answer is 2. This doesn't sound right.

In any case, there is something wrong with this quiz. For the question:

 let a: SomeStruct = SomeStruct()

The answer given by the quiz is also 2

The two question can't have the same result

1 Answer

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Alex,

The quiz answer is not incorrect; b.someMethod() will return 2 in this example. Try it out in a playground. The protocol extension provides a default implementation, but the definition of the struct overrides the protocol, and so that's the implementation you get.

As for the a.someMethod() and b.someMethod(), nothing is wrong there, except that it's the exact same question, which is probably a mistake. I assume something was meant to be changed between those two questions other than the name of the constant. Gabe Nadel - you may want to tweak that.

Cheers :beers: