Search code examples
xcodeplistuistoryboardseguexcode-storyboard

Is there a way to use plist file strings in the Xcode Storyboard Attribtutes inspector?


I'm finding that I'm having to declare the same string value for segue identifiers twice:

  1. Once in code to handle segue logic in my prepare() stubs
  2. Once in the inspector to set segue IDs in the storyboard

Obviously this opens up many potential issues with typos and what not between the two string values.

What I'd like to do if possible is to define my segue IDs once in a plist file and then reference that same definition twice in the the two places listed above. Of course I know it is possible to reference in plist value in Swift but is this possible in the Storyboard attributes inspector?

The field I'm trying to set with a PLIST value


Solution

  • I don't think that's possible, but I have two alternatives for you:

    1. Use something like R.swift. This tool will parse your Storyboard and create constants you can use in code

    2. Instead of identifying a segue by its identifier, do it by its destination controller.

    Example:

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if let controller = segue.destination as? MyViewController {
          controller.value = self.value
        }
    }
    

    Personally I use number 2, I very very rarely read the name property of the segue