2
let nowURL = documentsDirectory.URLByAppendingPathComponent("now.plist")

Saving in app:

if let filePath = nowURL.path {
    NSKeyedArchiver.archiveRootObject(nowTasks, toFile: filePath)
}

Retrieving in app:

if let loadedNowArray = NSKeyedUnarchiver.unarchiveObjectWithFile(nowURL.path!) as? [Task] {
    nowTasks = loadedNowArray
}

How can I get the data from the .plist as an object from inside of the todayViewController.swift file?

I have tried the retrieving method as shown above but it does not recognize the "documentsDirectory" for the path...

Matt Butler
  • 476
  • 6
  • 21
  • try using a shared container folder http://stackoverflow.com/a/32653801/2303865 – Leo Dabus Feb 17 '16 at 03:27
  • Using `NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask).first!` and Preferences worked for saving/retrieving on the iphone itself. However, neither work for the today extension. I keep getting the error **Failed to inherit CoreMedia permissions from 44700: (null)** is there a way to find which permission is missing? – Matt Butler Feb 17 '16 at 03:27
  • All apps are sandboxed, so if you need them to share some preferences I think you need a shared container – Leo Dabus Feb 17 '16 at 03:43
  • Now I am getting this error **Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: ' -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class (AppName.Task) for key (NS.objects); the class may be defined in source code or a library that is not linked'** – Matt Butler Feb 17 '16 at 04:49
  • http://stackoverflow.com/a/33194374/2303865 – Leo Dabus Feb 17 '16 at 16:45
  • @LeoDabus Do you mind checking out my new form of this question? http://stackoverflow.com/questions/35474085/cannot-retrieve-data-from-nsuserdefaults-into-today-extension-swift – Matt Butler Feb 19 '16 at 04:38

0 Answers0