Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - perform Segue

Tags:

ios

swift

self

if (view.annotation.title as String!) == "Helgoland " {   currentLong = 7.889021   currentLat = 54.180210    url = "google.com"    let alertController: UIAlertController = UIAlertController(title: "Change Map Type", message: nil, preferredStyle: UIAlertControllerStyle.Alert)   let cancelAction: UIAlertAction = UIAlertAction(title: "Back", style: UIAlertActionStyle.Cancel, handler: nil)   let button1action: UIAlertAction = UIAlertAction(title: "Product Page", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in     performSegueWithIdentifier("showShop", sender: self)   })   let button2action: UIAlertAction = UIAlertAction(title: "Video", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) -> () in     youtubeVideoID = "XX"     UIApplication.sharedApplication().openURL(NSURL(string: "http://www.youtube.com/watch?v=\(youtubeVideoID)"))   })   alertController.addAction(cancelAction)   alertController.addAction(button1action)   alertController.addAction(button2action)   self.presentViewController(alertController, animated: true, completion: nil) } 

I always get an error with

"Implicit use of 'self' in closure; use 'self.' to make capture semantic explicit"

but if I set self.view, it also fails.

like image 554
Fabian Boulegue Avatar asked Sep 25 '14 13:09

Fabian Boulegue


People also ask

What is perform segue in Swift?

Swift version: 5.6. Segues are a visual way to connect various components on your storyboard, but sometimes it's important to be able to trigger them programmatically as well as after a user interaction.

What is Sender in Perform segue?

The string that identifies the triggered segue. In Interface Builder, you specify the segue's identifier string in the attributes inspector. This method throws an Exception handling if there is no segue with the specified identifier. sender. The object that you want to use to initiate the segue.


1 Answers

You'll need to explicitly use self :

self.performSegueWithIdentifier("showShop", sender: self)

And for Swift 3 (thx @KingChintz) :

self.performSegue(withIdentifier: "showShop", sender: self)

like image 121
Yaman Avatar answered Sep 23 '22 22:09

Yaman