2
@objc public protocol P1 {
  func p1foo()
}

@objc public protocol P2 {
  func p2foo()
}

class A<T>: NSObject, P1 {
  func p1foo() { }
}

class B: A<Int> {

}

extension B: P2 {
  func p2foo() { }
}

-> Type 'B' does not conform to protocol 'P2'.

Why? Removing the generic solves this error, but I don't understand - B should be a fully-specific type at this point...

1 Answer 1

3

It's the combination of the @objc and the generic. Objective-C knows nothing of Swift generics, so your notion that B should adopt an @objc protocol causes the compiler to throw a wobbly.

You've already detected this from one direction; and you can equally see it from the other. You can make your code compile by deleting the @objc attributes. Or you can make it compile by removing the generic. You can't have both at once.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.