Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i define User Defined key at info.plist

Tags:

ios

iphone

Can i defined a user defined key with given name "SomeKey" and can i access with [[NSBundle mainBundle] objectForInfoDictionaryKey:@"SomeKey"]

like image 278
Jitesh Upadhyay Avatar asked Feb 16 '18 03:02

Jitesh Upadhyay


3 Answers

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

like image 112
Jake Avatar answered Oct 10 '22 11:10

Jake


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

like image 23
Santosh Botre Avatar answered Oct 10 '22 10:10

Santosh Botre


Short Answer: Yes.

Read: Custom Keys in Apple Docs

like image 44
Prachil Tambe Avatar answered Oct 10 '22 12:10

Prachil Tambe