perform
is NSObjectProtocol's function:
func perform(_ aSelector: Selector!) -> Unmanaged<AnyObject>!
func perform(_ aSelector: Selector!, with object: Any!) -> Unmanaged<AnyObject>!
func perform(_ aSelector: Selector!, with object1: Any!, with object2: Any!) -> Unmanaged<AnyObject>!
This is my code:
func test() {
let sel2 = #selector(newAction(pra:param:))
perform(sel2, with: 2, with: "bbb")
}
@objc func newAction(pra: Int, param: String) {
print("pra = \(pra), param = \(param)") // pra = -5251357295740329306, param = bbb
}
The question Alternative to performSelector in Swift? answers the value type can't work by this way.But the String
and Int
are implement by struct, why can the String
work by perform selector?