Skip to content

Instantly share code, notes, and snippets.

@ladislas
Created March 8, 2018 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ladislas/d87970c98ef9cefc06564b25c8978b78 to your computer and use it in GitHub Desktop.
Save ladislas/d87970c98ef9cefc06564b25c8978b78 to your computer and use it in GitHub Desktop.
Swift Selector & Arguments
import Foundation
class A: NSString {
let funcName = "sayHello"
@objc func sayHello() -> Void {
print("Hello from func as selector")
}
@objc func printSmthg(_ string: String) -> Void {
print(string)
}
}
var a = A()
a.perform(NSSelectorFromString(a.funcName))
let printSelector: Selector = NSSelectorFromString("printSmthg:")
a.perform(printSelector, with: "Bonjour je suis une fonction appelée avec un string")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment