What is equivalent to Objective-C ID in Swift?

I am trying to use @IBAction to bind a button click event to a Swift method. In Objective-C, the IBAction parameter type is id. What is equivalent to id in Swift?

+55
objective-c swift swift-converter
Jun 03 '14 at 1:14
source share
2 answers

Swift 3

Any , if you know that the sender is never nil .

 @IBAction func buttonClicked(sender : Any) { println("Button was clicked", sender) } 

Any? if the sender may be nil .

 @IBAction func buttonClicked(sender : Any?) { println("Button was clicked", sender) } 

Swift 2

AnyObject if you know that the sender is never nil .

 @IBAction func buttonClicked(sender : AnyObject) { println("Button was clicked", sender) } 

AnyObject? if the sender may be nil .

 @IBAction func buttonClicked(sender : AnyObject?) { println("Button was clicked", sender) } 
+85
Jun 03 '14 at 1:14
source share

Anyobject

Another type of display,

Migrate certain types of Objective-C types to your alternatives in Swift, like NSString for a string

Reinstall specific Objective-C concepts to match concepts in Swift, such as pointers to options

0
Jul 27 '15 at 9:10
source share



All Articles