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-1230] Using a Selector("function") does not work when the "function" is defined via a Protocol Extension #43838

Closed
swift-ci opened this issue Apr 14, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-1230
Radar None
Original Reporter chillok (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 0afc67cdb12d157a330aadefca9e1e36

duplicates:

  • SR-492 Protocol extenstion methods aren't exposed to Objective-C

Issue Description:

Consider:

// Our View Controllers will Adhere to this

protocol UIViewControllerProtocol {
    
}


// Add Default Behaviour

extension UIViewControllerProtocol where Self: UIViewController {
    func dismiss() {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

 // the nib/view for the View Controller will always be MyViewController minus the Controller bit
  static var viewName: String {
        
        let string = String(Self)
        return string.stringByRemovingSuffix("Controller")
    }
    
    // just create a new View Controller linked to it's nib
    static func controller() -> Self {
        
        let controller = Self(nibName: self.viewName, bundle: NSBundle.mainBundle())
        return controller
    }
}


class ViewController: UIViewController {

func load() {
        
        let controller = NewViewController.controller() 
        
        let navigationController = UINavigationController(rootViewController: controller)
        let closeButton = UIBarButtonItem(title: "Close", style: UIBarButtonItemStyle.Plain, target: controller, action: Selector("dismiss"))
        navigationController.navigationBar.topItem?.setLeftBarButtonItem(closeButton, animated: true)
        
        self.presentViewController(navigationController, animated: true, completion: nil)
    }
}

If we tap the closeButton we will get:

-[ViewController dismiss]: unrecognized selector sent to instance 0x7feba5b33070

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

1 participant