views:

50

answers:

1

Hi,

I couldn't get any replies on my previous (related) question, so I'm wondering if slightly paraphrasing it will be of any help.

I'm encoding a few complex objects with NSKeyedArchiver and saving it to disk. Say, something like -

Class member {
    int *id;
    NSString *name;
    NSMutableArray *array;
    TempClass *object;
}

The functionality I'm trying to build is for the user to be able to save his work, lets say, while creating a new member and come back to it later. When the user finishes up, he clicks post and the data will be transmitted to a web service. If not, he just clicks save and leaves the screen and the data is persisted, so that the app can resume from that point when the user comes back. Now, once I've posted the data to the web service, I do not want to keep the data in the disk anymore and I can't really find a way to delete it.

Now, my encoding and decoding classes are functioning fine. I can use NSKeyedArchiver to save the data to disk and retrieve it using NSKeyedUnarchiver. But, my question is, how can I delete the data that I don't need anymore? Do I have to manually delete the file on the disk? Is there any way to get NSKeyedUnarchiver to delete the data that's it's returning?

Thanks,
Teja.

+2  A: 

A very simple way to just delete it programmatically once you have posted the data:

- (BOOL) deleteFile:(NSString *) fileNameToDelete error:(NSError **)err {
    NSFileManager *fm = [NSFileManager defaultManager;
    BOOL exists = [fm fileExistsAtPath:fileNameToDelete];
    if(exists == YES) return [fm removeItemAtPath:fileNameToDelete error:err];
    return exists;
}
Frank C.
Thanks. But, How do I get the name of the file? If I archive multiple objects, will they get saved as multiple files?
Tejaswi Yerukalapudi
Okay, realized that was a stupid question. I'm not rewriting my save code to write to a different file for each archive I create. I can then delete them whenever I want to.
Tejaswi Yerukalapudi