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

Categories:

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: "https://gist.githubusercontent.com/mlcollard/d4e836e5a75223bba649/raw/ef2d575443949a0a2c2841ad6b59dd51a8b598d4/Pets.plist")
let urlallpetdata = NSArray(contentsOfURL: peturl)
let urlpetdata = urlallpetdata[position] as [String:String]

URL plist (Hold On)

var url = NSURL(string: "https://gist.githubusercontent.com/mlcollard/d4e836e5a75223bba649/raw/ef2d575443949a0a2c2841ad6b59dd51a8b598d4/Pets.plist")
var task = NSURLSession.sharedSession().dataTaskWithURL(url)
 {
        (data, response, error) -> Void in
        // your code
}
task.resume()

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