1

I have a very simple question, I just can't find a proper answer. That's

[NSKeyedArchiver archiveRootObject:value toFile:filePath];

according to apple documentation here, the above function:

Archives an object graph rooted at a given object by encoding it into a data object then atomically writes the resulting data object to a file at a given path, and returns a Boolean value that indicates whether the operation was successful.

My question is, if I call this function multiple times with same file path, does it overwrite the previous value in this file? and Can I write empty array to the file by using this function?

Sunil Sharma
  • 2,653
  • 1
  • 25
  • 36
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • 1
    Have you tried it? – rmaddy Jun 18 '16 at 17:00
  • Try it as @rmaddy suggests. As simple as that. Anyhow, the answer to both questions is yes and yes. It overrides the file so it overrides the value. As for the empty array - empty array is an array and is a root object so you can write it using this function. – tonymontana Jun 18 '16 at 18:01

1 Answers1

2

Yes, it will overwrite the previous value, and yes you can write an empty array to the file by using that function.

The implementation of that method doesn't care about what's there, it will overwrite whatever it is.

Kevin Stewart
  • 415
  • 6
  • 16