iOS Development

Data Sources

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

3460:489 iOS Development Fall 2014

Data Sources


Resource plist

let petPath = NSBundle.mainBundle().pathForResource("Pets", ofType:"plist") as String?
let allPetData = NSArray(contentsOfFile: petPath)
let petData = allPetData[position] as [String:String]

URL plist

let peturl = NSURL(string: "")
let urlallpetdata = NSArray(contentsOfURL: peturl)
let urlpetdata = urlallpetdata[position] as [String:String]

URL plist (Hold On)

var url = NSURL(string: "")
var task = NSURLSession.sharedSession().dataTaskWithURL(url)
        (data, response, error) -> Void in
        // your code

Local File

let localpaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let localpetspath = localpaths.stringByAppendingPathComponent("Pets.plist")
let allPetData = NSArray(contentsOfFile: localpetspath)

Cloud File

Read-Only Data Source Priorities: (?)

User’s View