When should I use anyObject insted of UIButton in swift? I am making an IBAction for my button that will be used to do more than on task on of the tasks is to switch to the next view.
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- SwiftUI: UIImage (QRCode) does not load after call
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Using if let syntax in switch statement
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Enum with associated value conforming to CaseItera
- Swift - hide pickerView after value selected
- Is there a Github markdown language identifier for
Ultimately, it really doesn't matter.
You can choose to use the parameter of
(sender: AnyObject)
or you can use(sender: UIButton)
.There might be times however where you might have to cast
AnyObject
as aUIButton
if you need access to the properties provided byUIButton
.For example let's say you have and you want the button to disappear after it is clicked.
The purpose of using an abstract AnyObject type for an IBAction may be advantage for a situation in which you have multiple UI objects that should trigger the same action. An example of this would be if you wanted to have a button and a gesture recognizer share the functionality of a common action. Even with a shared action, it would be possible to have different execution paths for the two objects.