4

How can I change the identifier name of a specific segue programmatically?

I found this way but didn't work with me:

SWrevealviewcontroller : Switch slideout menu direction from left to right pragmatically

Edit:

I have menu SWreavealviewcontroller and I want it to be from left in case of English language and from right in case of Arabic language.

kkakkurt
  • 2,790
  • 1
  • 30
  • 33
Amal El-galant
  • 139
  • 1
  • 16

1 Answers1

4

You can't change segue names programmatically. Because a segue defines a transition between two view controllers in your app’s storyboard file and you can rename it in your storyboard.

You can define more than one segues between your view controllers and call segues programmatically like this:

performSegue(withIdentifier: "yourSegueID", sender: nil)

For your problem:

  1. You can create two segues between your view controllers, and give two different segue identifier names to them (eg. englishSegue and arabicSegue).
  2. Create a variable for your segue identifier. (You will use it to select which of your segue should be triggered.)
  3. Control your language in your view controller (eg. in your viewDidLoad function or where you should control it) programmatically and set your language variable as English or Arabic.
  4. After that you can trigger it anywhere you want it. For example in a button click:

    if (yourIdentifier == "English") {
        performSegue(withIdentifier: "englishSegue", sender: nil)
    } else if (yourIdentifier == "Arabic") {
        performSegue(withIdentifier: "arabicSegue", sender: nil)
    }
    
kkakkurt
  • 2,790
  • 1
  • 30
  • 33
  • i want to have 2 segue identifier for the same view because i have menu SWreavealviewcontroller and i want it to be from left in case of english language and from right in case of Arabic language – Amal El-galant May 24 '17 at 11:45
  • This solution was perfect for me. I was trying to have a different kind of segue for the iOS app on Mac M1 & M2. This allowed me to simply call the respective identifier. – Jose Santos Jul 23 '23 at 18:35