Let's say you have a protocol and a class like the following:
If I want to make MySubclass implement MyProtocol, my first attempt would be something like this:
But, this yields a bunch of strange compiler errors. First, it says I need to qualify foo as @objc. Okay, so I do that, and then it tells me that @objc is not supported within extensions of generic classes. However, it's perfectly okay to do the following:
If I define my class like that instead, it compiles and everything works as expected. The @objc limitation seems a bit odd, given that I can just move the conformance out of the extension and back into the class and everything works just fine.
What I'd like to say changed:
- Allow extensions to implement Objective-C protocols in generic classes, so that we don't have to stray from the "implement your protocols in extensions" patterns for just this case
- At the very least, I think the compiler should just tell you up front: "You can't implement Objective-C protocols in extensions to generic classes"