Info.plist check for key and ensure a value

Hi to all,

i’m very new to Swift language (my background is JAVA) and i’ve see that in swift there are very elegant way to check for condition (if-let , guard and so on).

Now, i would like to read Info.plist and ensure that SOME key are set and ALL OF THEM have a value, otherwise the application must crash. I’m writing some library (for my personal use) and this key/value is a pre-requisite to continue.

Because this library do not need an instance, i have think to write it as Singleton and check this key/value, but i dont know if is the best way to do it, can someone help me to write good code? Thanks!!!

Hi @mistre83,
You can read the Info.plist into a dictionary and then check for the specific keys that you are after, if the key return a nil, then the key is not set (setting nil for a key removes it from the dictionary).

You don’t have to create a singleton, you can simply do this in the code at start that checks for the conditions, it would not make sense to have this available from anywhere else in the application later.

cheers,

Jayant