In my code I have this line, but I was wondering if there is way to check whether @\"SomeController\" exists before I use it with the \"instantiateViewControllerWit
You can use valueForKey:
on UIStoryboard
s. UIStoryboard
s have a key called "identifierToNibNameMap", its value is an NSDictionary
with the UIViewController
s in that storyboard. This inner NSDictionary
uses the viewcontroller's names as keys so you can actually check if a viewcontroller exists in a storyboard with the following code:
if ([[storyboard valueForKey:@"identifierToNibNameMap"] objectForKey:myViewControllerName]) {
// the view controller exists, instantiate it here
UIViewController* myViewController = [storyboard instantiateViewControllerWithIdentifier:myViewControllerName];
} else {
//the view controller doesn't exist, do fallback here
}
Note: Apple has been known to reject apps that query the underlying properties of cocoa classes using valueForKey:
. These underlying properties could change at any time in the future, breaking app functionality without warning. There is no deprecation process for these things.