iOS Development

Data Sources

Michael L. Collard, Ph.D.

Department of Computer Science, The University of Akron

Data Sources

  • Where we get the data for our apps to display
  • Source and need for updates, user entry, etc.

Categories:

  • Fixed, constant data that very rarely needs to be updated
    • E.g., University departments
  • Fixed data with periodic need for updates
    • E.g., faculty office numbers
    • E.g., outside hall of dept office
  • User data
    • E.g., names of our friends pets (?), "white kitty"

Resource plist

  • Local resource, bundled in app, guaranteed to exist
  • Can only be updated when app is updated
let petPath = NSBundle.mainBundle().pathForResource("Pets", ofType:"plist") as String?
let allPetData = NSArray(contentsOfFile: petPath)
let petData = allPetData[position] as [String:String]

URL plist

  • Remote resource
  • All apps (when opened) can be updated with app update
  • Data access may not exist when app is first opened, or may disappear at any point in time
  • May take too long
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)

  • That "too long" part
  • Need to do asynchronously
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

  • Very fast access
  • Does not exist when app is first run
  • Stored on the user's device
  • May disappear, e.g., clearing space for iOS update
let localpaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let localpetspath = localpaths.stringByAppendingPathComponent("Pets.plist")
let allPetData = NSArray(contentsOfFile: localpetspath)

Cloud File

  • Similar to URL plist, but from cloud source and may be private
  • Access depends on cloud service being used, e.g., Azure, CloudKit, etc.
  • Generally must copy from Cloud directory to own

Read-Only Data Source Priorities: (?)

  • Local plist
  • URL plist
  • Cloud plist
  • Resource plist

User's View

  • Want most recent information possible
  • Don't want to wait
  • Are only viewing a small amount of data at a time
  • Expect the data to be the same or fresher next time they use the app