I am working on a Universal app & would like to access the values stored in app-info.plist file in my code.
Reason: I instantiate a UIViewController dynamically from a storyboard using:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
self = [storyboard instantiateViewControllerWithIdentifier:@"ExampleViewController"];
Now, having the storyboard name @"MainStoryboard_iPhone" above is ugly.
I want to do something like:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:appInfo.mainStoryboardBaseNamePhone bundle:nil];
self = [storyboard instantiateViewControllerWithIdentifier:@"ExampleViewController"];
where appInfo can perhaps be an NSDictionary of all values in app-info.plist
Well you can acces the info.plist very easly :
Getting the name of the storyboard:
Not sure wether it will detect if it is in a iPad and it should use the
UIMainStoryboardFile~ipad
key instated.Attributes from the info.plist for your project are directly accessible by the following...
For example to get the version number you might do the following
There is a gotcha in that the version number now has two attributes in the info.plist - but you get the idea? If you view your info.plist as source code (right click the info.plist - select Open As) then you will get to see all the various key names you can use.
You can also use the infoDictionary method on NSBundle:
Swift 4+ syntax for Damo's solution
Example