What's best practice when it comes to Info.plist Variables in iOS development?
Asked Answered
D

1

6

I recently started developing iOS Apps, and I found a Environment Variables tab in my Info.plist file. What's best practice when it comes to these variables? Can I use them throughout my code base? As long as I reference them in the correct manner?

For example if I was trying to access a Var to change the background color I could access the value this way, but is it reliable? Is it best practice? I simply can see the benefit of being able to access these vars across multiple ViewControllers and Delegates.

enter image description here

Devonna answered 15/6, 2016 at 12:51 Comment(3)
Can you show me what you're talking about? I don't remember seeing a plist with tabs in Xcode before.Princeling
@Princeling Updated!Devonna
Constants like that should always be define in code. There's no good reason I can think of do so in the plist file. Remember that every forced unwrap or cast can potentially cause a crash in the future.Princeling
L
1

It's much easier to define constants like that in code.

  1. You know their type for sure -> no typecasting needed
  2. You could document them properly
  3. You don't have to remember their keys in the info.plist. Xcode's code-completion will help you when you use the constants
  4. Constants defined in code can't be manipulated by the user as easy as in the info.plist
Lohengrin answered 2/12, 2016 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.