Swift: Creating Plist Programmatically

It’s practical to use plist in files for iOS projects either to store configuration settings or to store any other information you may need in the execution of your application.

The plist or property list structure is key-value relation:

example:

plist

Before we try to generate the plist file we can check if the plist exists:

In case the file doesn’t exist:

To generate the plist file lets start with the content. In this case we are going to use the capitals of the states:

Now we are going to convert the dictionary content to NSDictionary:

With the content already in NSDictionary we can try to write to disk:

We can check if write to disk was successful

Please let me know if you have any questions by leaving a comment below or on twitter @luisemedr