Reputation: 2171
I am writing a word puzzle game. I want to have a plist file where i keep track of the users solutions to my puzzles. In other words, I want to save data whenever the user finishes or pauses a level.
The game consists of 20 levels in each of 5 categories (so 100 levels total). The questions are loaded from a plist when the user starts the game. The objective is basically to unscramble the message and i want them to be able to come back to started levels later. Their solutions must then be stored in some sort of editable (mutable?) array.
I'm fairly new to coding and I've looked online but didn't find any answers. I just dont know how to implement it.
My Question: If I create a .plist file to store the users' solutions (with 5 array keys for each category, each array having a set of 20 blank string values) is it possible to edit entries as the user plays the levels?
Upvotes: 1
Views: 229
Reputation: 8991
It is easy to write an NSDictionary or NSArray to a .plist file using the method
- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag
So, why not load your state information from the plist into an array, each containing an NSMutableDictionary with the user's answers. Then, when the user sets a new answer, set a new object for that question key. When finished, write the parent NSArray to file using the method above - voila.
EDIT - NSArray would work better in this instance
Upvotes: 3