Can i defined a user defined key with given name "SomeKey" and can i access with [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SomeKey"]
Of course!
Apple Docs:
Custom Keys
iOS and macOS ignore custom keys you include in an Info.plist file. If you want to include app-specific configuration information in your Info.plist file, you can do so freely as long as your key names do not conflict with the ones Apple uses. When defining custom key names, prefix them with a unique prefix, such as your app’s bundle ID or your company’s domain name, to prevent conflicts.
And you can get the value by doing something like this:
Objective-C
[[NSBundle mainBundle].infoDictionary objectForKey:@"SomeKey"];
or
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"SomeKey"];
Swift
Bundle.main.infoDictionary?["SomeKey"]
Reference:
Info Plist Docs
Reserved Keys
We do access the application bundle info.plist like shown below,
Objective-C
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *appDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
Swift
let appDisplayName = Bundle.main.infoDictionary?["CFBundleDisplayName"]
Similarly, If you have added any custom key-value pair in the info.plist you can surely access it. Just replace the CFBundleDisplayName with your key.
Refere this
Short Answer: Yes.
Read: Custom Keys in Apple Docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With