Swift 2 to 3 Migration for Prepareforsegue

Swift 2 to 3 Migration for prepareForSegue

Method signature is changed in swift 3.0

Replace this

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

With

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

Cannot override prepareForSegue function

In Swift 3 the signature of the method is

override func prepare(for segue: UIStoryboardSegue, sender: Any?)

A way to figure out yourself is to comment out the entire method and retype the first few characters (prep). Code completion will help you.

prepare(for segue: UIStoryboardSegue, sender: AnyObject?) missing in swift 3.0/Xcode 8 b6

Maybe this was a bug in Beta 6. I'm using the GM seed, and it is working:

prepareforsegue

BTW: In beta 6, the method was renamed to

prepare(for segue: UIStoryboardSegue, sender: Any?)

How to do a performSegue to a specific view in Tab Bar Controller from another view (swift 4)

with this code, you don't need segues, you can use when you push some button

let VC1 = self.storyboard!.instantiateViewController(withIdentifier: "tabBarController") as! tabBarLoginViewController
VC1.selectedIndex = 2 //this line says that the view that appears will be third of you tab bar controller
self.navigationController!.pushViewController(VC1, animated: true)

if you want to use segue use this, the segue needs to point of tab bar controller, not a view of tab bar controller

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "goToMain") {
let vc = segue.destination as! TabBarController
vc.selectedIndex = 2
}
}

Why is the iOS 11: self.performSegue() not working?

I found the solution to be at a completely different place (as so often).
The reason was that I had a logic in place in applicationDidBecomeActive that was replacing the current storyboard (bad approach!) - the additional popup from the FB Kit led to a recreation of my container view controller. Thus i had self.navigationController == nil during the call to perform the segue.

How to create a delay in Swift?

Instead of a sleep, which will lock up your program if called from the UI thread, consider using NSTimer or a dispatch timer.

But, if you really need a delay in the current thread:

do {
sleep(4)
}

This uses the sleep function from UNIX.



Related Topics



Leave a reply



Submit