Sandeep Bhandari
Sandeep Bhandari

Reputation: 20379

how can I have a different Storyboard.strings to the same storyboard for each target in Xcode?

I have multiple storyboards in my project. Lets say one of them is Main.storyboard. I have few hard coded strings in Main.storyboard. Because we are trying to create a white labeled app, I have added multiple targets to existing project.

Now each target uses the same Main.storyboard because there is no change in UI. But I need to customize the hardcoded strings in Main.storyboard to each target.

For example in Target A strings should say "Welcome to A" when built for TargetB string should be "Welcome to B".

One way I can think of is creating IBOutlet to each such UIComponent and update their value dynamically by adding if else statements or easy way would be enable localization to Main.storyboard and have different Main.strings file for each target.

I would prefer using 2nd approach but I dont know how to achieve it. Any help would be greatly appreciated. No need of code in here hence not adding any snippet. If you need screen shot of project structure lemme know :)

Upvotes: 1

Views: 240

Answers (1)

André Slotta
André Slotta

Reputation: 14040

  1. Add a Localizable.strings file for each target
  2. Add an entry in each Localizable.strings file with a common key but different text
  3. Set the text with the NSLocalizedString function

example

Update:

Instead of Localizable.strings you could also add Main.strings (name depends on your storyboard name) files for each target. In those files you can then set texts for specific UI elements by using {element_identifier}.text as the key. You find the identifier by right clicking the storyboard -> "Open As" -> "Source Code".

example 2

Upvotes: 1

Related Questions