1

I have looked everywhere for the answer but none of the answers seem to fit my problem.

I have a switch statement that references back to a function whenever the case is different:

switch wall["ExposureOneType"] as! String {
                case "Twitter":
                cell.exposureButtonOne.addTarget(self, action: #selector(self.openThis(urlStr:"https://twitter.com/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Instagram":
                cell.exposureButtonOne.addTarget(self, action: #selector(openThis(urlStr:"https://www.instagram.com/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Youtube":
                cell.exposureButtonOne.addTarget(self, action: #selector(openThis(urlStr:"https://www.youtube.com/user/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Facebook":
                cell.exposureButtonOne.addTarget(self, action: #selector(openThis(urlStr:"https://www.facebook.com/\(String(describing: wall["ExposureOne"]))")), for: UIControlEvents.touchUpInside)
                case "Snapchat":
                cell.exposureButtonOne.isEnabled = false
            default:
                cell.exposureButtonOne.isEnabled = false
            }

The function openThis() is:

func openThis(urlStr:String!) {

    if let url = URL(string: urlStr) {
        UIApplication.shared.open(url as URL, options: [:], completionHandler: nil)
    }

}

But I am getting the error that is in the title. Any reason why? Any workarounds? All help will be appreciated!

Natan Yagudayev
  • 73
  • 1
  • 13
  • 1
    Possible duplicate of http://stackoverflow.com/questions/40334786/argument-of-selector-does-not-refer-to-an-initializer-or-method – You *cannot* add arbitrary parameters to the selector. – Martin R Mar 15 '17 at 16:08
  • Oh wow. Is there a way to work around this? @MartinR – Natan Yagudayev Mar 15 '17 at 16:11
  • One way is to make each assign a unique tag property/attribute to each cell. Then in openThis() you query which tag and open the appropriate thing. –  Mar 15 '17 at 16:30

0 Answers0