I am building a "mood" tracker application. I am currently trying to get the data saved and recovered. I have it saving the date to a plist called crazydata.plist. But I cannot figure out how to save more than 1 day's worth. Since I am only grabbing the data from index 0. I need to grab the data from however many index's there are until the end of file, add that to an array then add the currently selected mood and date to the file.
I was not sure what the best method was so I am just currently fumbling around (this is my first iphone app). Just looking for some guidance on where to look to go.
Should I even be using a plist? Maybe core data. I have another screen that I will read back the plist and extract the dates and mood to recall what the mood was on a particular day.
Any ideas? Just don't want to spend days going down the wrong path.
Here is what the plist looks like.
I was not sure what the best method was so I am just currently fumbling around (this is my first iphone app). Just looking for some guidance on where to look to go.
Should I even be using a plist? Maybe core data. I have another screen that I will read back the plist and extract the dates and mood to recall what the mood was on a particular day.
Any ideas? Just don't want to spend days going down the wrong path.
Code:
-(void) saveData: (NSString *) level and: (NSString *) date
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"crazydata.plist"];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:path];
//combine selected and dateString into one string with " | " as seperator
NSString *combinedData = [[NSString alloc] init];
selected = [selected stringByAppendingString: @" | "];
combinedData = [selected stringByAppendingString: dateString];
if (fileExists) {
//pulls data from existing file saves to oldvalues array
NSArray *oldvalues = [[NSArray alloc] init];
oldvalues = [NSArray arrayWithContentsOfFile:path];
NSString *oldDataString = [[NSString alloc] init];
NSLog(@"%@", oldvalues);
//only saving data from Index one, find someway to index++ loop until done
oldDataString = [oldvalues objectAtIndex:0];
NSArray *values = [[NSArray alloc] initWithObjects:combinedData, oldDataString, nil];
[values writeToFile:path atomically:YES];
[values autorelease];
}
else {
//create new crazydata.plist if non-existing
NSArray *values = [[NSArray alloc] initWithObjects:combinedData, nil];
NSLog(@"%@", values);
[values writeToFile:path atomically:YES];
[values autorelease];
}
Here is what the plist looks like.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<string>Crazy | 09 25 2010</string>
<string>Somewhat Crazy | 09 25 2010</string>
</array>
</plist>