You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"
The text was updated successfully, but these errors were encountered:
Both good ideas. @slavapestov, it's not really possible to add @objc methods to generic classes from another module, right? (But we could allow it within the same module.)
The last idea, Yes! I rewrote a lot of code after which I was met by the compiler letting me know: "@objc is not supported within extensions of generic classes or classes that inherit from generic classes". Life is hard.
The diagnostics QoI issue is fixed. Repurposing this report into a request to allow @objc in extensions of generic classes within the same module.
AnthonyLatsis
added
feature
A feature request or implementation
and removed
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
diagnostics QoI
Bug: Diagnostics Quality of Implementation
labels
Jul 6, 2022
Environment
Swift 2.1
Mac OS X 10.11.3
Xcode 7.2.1
Additional Detail from JIRA
md5: 2de02e9c18e4d7298b9946f1b00e3d94
duplicates:
Issue Description:
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"
The text was updated successfully, but these errors were encountered: