Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-492] Protocol extenstion methods aren't exposed to Objective-C #43109

Open
swift-ci opened this issue Jan 7, 2016 · 5 comments
Open

[SR-492] Protocol extenstion methods aren't exposed to Objective-C #43109

swift-ci opened this issue Jan 7, 2016 · 5 comments

Comments

@swift-ci
Copy link
Collaborator

@swift-ci swift-ci commented Jan 7, 2016

Previous ID SR-492
Radar None
Original Reporter aleksanderkania (JIRA User)
Type Bug
Status Reopened
Resolution
Additional Detail from JIRA
Votes 5
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 5ed2a55af47268aca30c35583bd87d96

is duplicated by:

  • SR-942 Cannot provide default implementation of @objc protocol via extension
  • SR-1230 Using a Selector("function") does not work when the "function" is defined via a Protocol Extension
  • SR-9676 Default implementation for optional protocol functions not invoked

Issue Description:

When class conform the protocol that supplies some method and if the method have default implementation in protocol extension then _respondsToSelector _method return false.

protocol SomeProtocol{
    func foo()->Void
}

extension SomeProtocol{
    func foo()->Void{
        // do something
    }
}

class SomeClass : NSObject, SomeProtocol{
}

let some = SomeClass()
some.respondsToSelector("foo")
@phausler
Copy link
Member

@phausler phausler commented Jan 7, 2016

respondsToSelector is just a thin veil on class_respondsToSelector so this would be more the objc runtime's domain than Foundation. However is it the case that the protocol would have to have some decorator to be exposed as objc for this to work?

@belkadan
Copy link
Contributor

@belkadan belkadan commented Jan 7, 2016

Right, methods in protocol extensions are not exposed to Objective-C, ever. It's a little unfortunate that we don't have a way to manually do that from the class, though; if you redeclare the method you can't use the default implementation.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Mar 29, 2018

SR-3349 has a bit more discussion on why this isn't really implementable.

@belkadan
Copy link
Contributor

@belkadan belkadan commented Mar 29, 2018

…sorry, I missed my own comment about having it happen manually in the class somehow.

@swift-ci
Copy link
Collaborator Author

@swift-ci swift-ci commented Oct 8, 2018

Comment by Ilya Kulakov (JIRA)

I faced the similar problem: I have an existing Objective-C protocol with a method which I would like to refine for Swift to use Tuples instead of unsafe pointers. However it does seem to be possible.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants