I am new to swift, and just happen to have Swift 3 released, but apple document still using Swift2 syntax.
Understand that below (Swift2)
@IBOutlet var weak saveButton:UIBarButtonItem!
This method lets you configure a ViewController
before it's presented.
override func prepareForSegue(segue: UIStoryboardSegue, sender:AnyObject?) {
if saveButton === sender { //originally swift 2 can compare
}
Has changed to (Swift3)
override func prepare(for segue: UIStoryboardSegue, sender:Any){
}
Now on swift 3 I cannot check if sender = saveButton
I am very new to Swift, is that I need to cast it like sender as UIBarButtonItem?
Original Apple Guide
Try like this inside prepareforsegue
method.
override func prepare(for segue: UIStoryboardSegue, sender:Any){
if let barButton = sender as? UIBarButtonItem {
if saveButton == barButton {
//Do what you want
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With