Reputation: 10811
I'm trying to use an @IBAction to tie up a button click event to a Swift method. In Objective-C the parameter type of the IBAction is id. What is the equivalent of id in Swift?
Upvotes: 63
Views: 24473
Reputation: 10811
Any
, if you know the sender is never nil
.
@IBAction func buttonClicked(sender : Any) {
println("Button was clicked", sender)
}
Any?
, if the sender could be nil
.
@IBAction func buttonClicked(sender : Any?) {
println("Button was clicked", sender)
}
AnyObject
, if you know the sender is never nil
.
@IBAction func buttonClicked(sender : AnyObject) {
println("Button was clicked", sender)
}
AnyObject?
, if the sender could be nil
.
@IBAction func buttonClicked(sender : AnyObject?) {
println("Button was clicked", sender)
}
Upvotes: 93
Reputation: 6394
AnyObject
Other mapping type,
Remap certain Objective-C core types to their alternatives in Swift, like NSString to String
Remap certain Objective-C concepts to matching concepts in Swift, like pointers to optionals
Upvotes: 0