@objc protocols don't support default implementations for methods via extensions. Attempting to do so makes the compiler suggest that you add the @objc attribute to your default method implementation, which instead it should tell you that the entire construct is invalid.
Untitled.swift:13:7: error: non-'@objc' method 'requiredMethod()' does not satisfy requirement of '@objc' protocol 'ObjCProtocol'
class ConformingClass: NSObject, ObjCProtocol {
^
Untitled.swift:8:19: note: add '@objc' to expose this instance method to Objective-C
/* @objc */ func requiredMethod() {
^
@objc
Untitled.swift:4:13: note: requirement 'requiredMethod()' declared here
@objc func requiredMethod()
^
If you follow the fix-it, you another error which correctly tells you that this is invalid. But strangely, you still get a suggestion to add @objc:
Untitled.swift:8:3: error: @objc can only be used with members of classes, @objc protocols, and concrete extensions of classes
@objc func requiredMethod() {
~^~~~~
Untitled.swift:13:7: error: non-'@objc' method 'requiredMethod()' does not satisfy requirement of '@objc' protocol 'ObjCProtocol'
class ConformingClass: NSObject, ObjCProtocol {
^
Untitled.swift:8:13: note: add '@objc' to expose this instance method to Objective-C
@objc func requiredMethod() {
^
@objc
Untitled.swift:4:13: note: requirement 'requiredMethod()' declared here
@objc func requiredMethod()
^
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, DiagnosticsQoI, TypeChecker | |Assignee | @theblixguy | |Priority | Medium | md5: 1e0dc6ae6b02f489a3c7f3c42370108bIssue Description:
@objc
protocols don't support default implementations for methods via extensions. Attempting to do so makes the compiler suggest that you add the@objc
attribute to your default method implementation, which instead it should tell you that the entire construct is invalid.Example code:
Error:
If you follow the fix-it, you another error which correctly tells you that this is invalid. But strangely, you still get a suggestion to add
@objc
: