Created
March 8, 2018 11:13
-
-
Save ladislas/d87970c98ef9cefc06564b25c8978b78 to your computer and use it in GitHub Desktop.
Swift Selector & Arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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