3

How can I set in the Storyboard a ViewController Storyboard ID from a variable in a struct swift file?

I don't want to write down the Storyboard ID of a VC from the Identity Inspector > Identity > StoryboardID hardcoded. I want it to be in a variable in a struct swift file where I can access it and also set it/change it from there.

denis_lor
  • 6,212
  • 4
  • 31
  • 55
  • I don't answer substituting a hardcoded string inside a swift file with a variable , I mean this is the only way to dynamically load a vc , BTW your request doesn't exist you may try it in Android or any other platform as there is no mental use case for it – Shehata Gamal Oct 24 '18 at 13:55

1 Answers1

0

From Apple docs. https://developer.apple.com/documentation/uikit/uistoryboard/1616214-instantiateviewcontroller

An identifier string that uniquely identifies the view controller in the storyboard file. You set the identifier for a given view controller in Interface Builder when configuring the storyboard file. This identifier is not a property of the view controller object itself and is used only by the storyboard file to locate the view controller.

If the specified identifier does not exist (or is nil) in the storyboard file, this method raises an exception.

As storyboardID is not the property of the ViewController or some other class we may not access this property.

Sateesh Yemireddi
  • 4,289
  • 1
  • 20
  • 37