3

First post on StackOverflow, after extensively using it for a long time.

I'm building a small app (just to lear swift), and I have troubles with making some data persistent. I use NSCoding to achieve that. The problem is that when saving, the function NSKeyedArchiver.archiveRootObject() return true (so apparently it worked), but when, later, I try to retrieve these saved informations, the result of NSKeyedUnarchiver.unarchiveObjectWithFile() is nil.

Without posting all my code, I was just wondering if it were possible to explore the file in which persistent data are stored during a debug session. That would allow me to check whether I have a problem with the saving or the loading part of the process, and see if the data are indeed stored in the right file.

Thanks,

Lb

Louis. B
  • 287
  • 1
  • 8

1 Answers1

1

Per Apple Documentation, you get a nil with unarchiveObjectWithFile when there is no file at the mentioned path. I would advise to check your file path where you are archiving and saving your object.

As for the debugging, follow this:

  1. Print the file path when you are archiving and saving the object. So in this NSKeyedArchiver.archiveRootObject(myObject, toFile: filePath) print filePath.
  2. Open your terminal app and execute open <filePath> command to open the file path where data is being saved.
  3. Check out if your data file is created in there with right archiving.
Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • Thanks a lot. It helped finding out that actually there was a problem of types between the stored data and the data that I was trying to retrieve. It was indeed useful to check the file content, I would have expected such a built-in function within xCode... But anyway, thanks, problem solved. – Louis. B Oct 24 '15 at 06:06
  • Glad it helped. Cheers :)! – Abhinav Oct 24 '15 at 06:08