Question

It seems like the writeToFile method appends to the currently existing file path as long as the method calls happen during the same application runtime. Is this true?

Are there any other ways to ensure appending to an existing file while an application session is running? I would like the file to be overwritten on a new session.

FYI, I am using an NSMutableDictionary as the receiver to the writeToFile message.

Was it helpful?

Solution

To ensure the file is overwritten for each new session, simply delete the file when a new session starts.

To append to a file, you can use an NSOutputStream to write the data. Open the file for appending. But if you are writing a plist file from an NSDictionary, then this won't work. The better solution would be to load the dictionary at app startup, update it in memory as the apps runs, and write the dictionary to a file when the app enters the background. This assumes your "session" isn't defined by app startups (or background/foreground transitions).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top