Load Data from Property List in iOS8 with Swift

Property Lists offer a convenient way to store simple structural data. It usually appears in XML format. You can’t use property lists to save all types of data. The items of data in a property list are of a limited number of types including arrays,dictionaries, strings, etc. In general. It is always better to separate static data from the code, especially when you have lots of items. Using property lists is easier to change items, less error-prone and you can even delegate the maintenance to other people. In this tutorial we will create a table, which imports the data form the property list. This tutorial is made in iOS8.3 with Xcode 6.3.

Open Xcode and create a new Single View Application. For product name, use IOS8SwiftProperyListTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and make sure only iPhone is selected in Devices.

Remove the View Controller from the Storyboard and drag a Navigation Controller to the empty canvas. When the initial View Controller is deleted there isn't a starting point defined. Select the Navigation Controller and go to the Attribute Inspector. In the View Controller Section select the "Is Initial View Controller" checkbox.

Double-click on the Navigation Bar in The Table View Controller and set the title to "Devices". Select the Table View Cell and go to the Attributes Inspector. In the Table View Cell section set the Identifier  to "Cell".

The Storyboard should look like this.

Since we have deleted the View Controller from the Storyboard we can also delete the ViewController.swift file. Add a New File to the project, select iOS->Source->Cocoa Touch Class. Name it TableViewController and make it a subclass of UITableViewController.

Go to the TableViewController.swift file and add the following property

var tableData = [String]()

Add  a new property list. Add a New File to the Project. Choose  iOS -> Resource -> Property List. Give the property list a title of TableData 

Open the property list. Right-click and Select Add Row. Add an Array named AppleDevice containing multiple Strings.

When you select the Property List.plist file, and open it as source code , you can view the created  XML code.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
        <string>Apple Watch</string>

Change the viewDidLoad method to

override func viewDidLoad() {

    let path = NSBundle.mainBundle().pathForResource("TableData", ofType: "plist")
    let dict = NSDictionary(contentsOfFile: path!)
    tableData = dict!.objectForKey("AppleDevice") as! [String]

Before reading the “tableData.plist” file, you have to first retrieve the full path of the resource. Then the key-value pair of the dictionary will be read. In the TableViewController class some methods are already implemented and only needs some minor changes. Change the following methods

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
    // Return the number of sections.
    return 1

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // Return the number of rows in the section.
    return tableData.count
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell

    // Configure the cell...
    cell.textLabel!.text = tableData[indexPath.row]

    return cell


  1. Only 1 section is used
  2. The number of rows is equals to the number of items in our array
  3. For each row we assign the value of the array's item to the text label of the cell

Go to the Storyboard and Select the Table View Controller. Go to the Identity Inspector and in the Custom Class section change the class to TableViewController

Build and Run the project, the devices loaded from the property list should be displayed inside the Table View.

You can download the source code of the IOS8SwiftProperyListTutorial at the ioscreator repository on Github.