Louis. B
Louis. B

Reputation: 287

IOS (Swift) How to explore persistent file(s) during debug session?

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

Upvotes: 3

Views: 493

Answers (1)

Abhinav
Abhinav

Reputation: 38162

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.

Upvotes: 1

Related Questions