The Info.plist File in Xcode

Doug Galante
3 min readJan 9, 2017

--

In this post I’ll explain what the Info.plist file in your Xcode project is, what it’s doing, and how you can use it.

Before we get started there are a few terms to get familiar with.

Bundle: You can think of a bundle as the directory of your project. It’s an organized folder of all your files. When you need to access and file within your project you can do so by calling on properties and methods of the Bundle class. (apple documentation)

Metadata: “a set of data that describes and gives information about other data”

Property List: A property list is basically a dictionary of keys and values that can be stored in your file system with a .plist file extension, meaning its accessible through the Bundle class. Property lists are used as a lightweight and portable means to store a small amounts of data. They are commonly written in XML, but Xcode is fancy and is able to turn the XML file into the clean and editable version you see in your project. (apple documentation)

The Information Property List

Now that we know some of the terminology, we can better understand what the Info.plist file is and why we need it.

From the apple documentation:

An information property list file is a structured text file that contains essential configuration information for a bundled executable. The file itself is typically encoded using the Unicode UTF-8 encoding and the contents are structured using XML. The root XML node is a dictionary, whose contents are a set of keys and values describing different aspects of the bundle. The system uses these keys and values to obtain information about your app and how it is configured. As a result, all bundled executables (plug-ins, frameworks, and apps) are expected to have an information property list file.

So what does this mean? — Every application is expected to have an Info.plist file so the system can read it and work according to it’s contained values. When you create a new project you are given an Info.plist file with default settings all of which can be customized.

At the top of each column you can see “key”, “type”, and “value”. Sounds like a dictionary right? The key is a string value, and the value is of the type that is specified on the type column.

Something to note about the way Xcode displays the file, if you try to access a value using the key visible in the Info.Plist file you will get an error. The correct key can be found in the XML version of the file.

You can see the XML version of the plist by opening the file in a text editor such as Sublime Text or Atom. *Edit - you can also right click the Info.plist file and select Open As > Source Code.

Lets look at the “Main storyboard file base name”. We can access it’s value in our program using the following code:

let exampleValue = Bundle.main.object(forInfoDictionaryKey: "UIMainStoryboardFile") as! Stringprint(exampleValue)

running this code will print “Main” to the console, which is the value listed in the Info.pList file.

Notice the key is “UIMainStoryboardFile” and not “Main storyboard file base name”. being able to read the XML file is handy — you can find the correct key on line 25.

It’s also easy to add other properties to the plist by clicking the “+” sign when you hover over an existing property. This will add a new key to you plist and you will be prompted to select a key from a long list of things that you can customize — or create your unique key if you want. You can then access that value the same way as seen above.

Full list of keys and what they do

--

--

Doug Galante

Aspiring Coder with a Fine Arts Degree ~ Making Time for Climbing, Cooking, Video Games, and Sleep.