-1

Intro

I am creating a Swift 2.0 app in which an action can be performed only a certain number of times, say 8. In order to accomplish this behavior, I need to cancel a certain segue, performAction, should it be triggered via pressing a button linked to it on storyboard.

Research

I ran across questions like http://stackoverflow.com/questions/8066525/prevent-segue-in-prepareforsegue-method, which suggested code like:

override func shouldPerformSegueWithIdentifier(identifier: String,sender: AnyObject?) -> Bool {

     return true
 }

Implementation

I implemented it like:

override func shouldPerformSegueWithIdentifier(identifier: "createCard" ,sender: AnyObject?) -> Bool {
    if amountOfTimes > 8 { //To be triggered if the segue should be cancelled
        return false
    } else {
    return true
    }
}

However I get the error

Expected ',' seperator

How can I have the segue be cancelled should amountOfTimes be greater than 8?

rocket101
  • 7,369
  • 11
  • 45
  • 64

3 Answers3

2

To check if your identifier is "createdCard" use the shouldPerformSegueWithIdentifiermethod like this:

override func shouldPerformSegueWithIdentifier(identifier: String ,sender: AnyObject?) -> Bool {

    return !(identifier == "createCard" && amountOfTimes > 8)

}
ronatory
  • 7,156
  • 4
  • 29
  • 49
1

The problem is this phrase:

identifier: "createCard"

That is not Swift. This is not a function call, it is a function implementation. You must say:

identifier: String

identifier is not a value you set, it's a value you receive. You can then look to see if it is "createCard", but you do not get to claim that it is.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

1 Click on First ViewController's Round Yellow/White icon (highlighted left side in image) and hold drag to next ViewController (ex. SubmitOTPVC). Then write this code in swift file:

 self.performSegue(withIdentifier: "otpVC", sender: nil)

here otpVC is the identifier name of segue.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Clean Coder
  • 496
  • 5
  • 12