Wednesday, 2 October 2013

Need help in trying to read and write from plist

Need help in trying to read and write from plist

I am trying to save an NSMutable Array and NSString into plist and then if
it exists initialize the value from plist. However when I re run the app,
the values do not get initialize as it is suppose to. So far the following
is what I have.
if (self = [super init]) {
NSString *path=[self getFileUrl];
NSFileManager *fm = [[NSFileManager alloc] init];
if ([fm fileExistsAtPath:path]) {
_history = [d objectForKey:@"stringKey"];
availableSeats=[d objectForKey: @"ArrayKey"];
}
else
{
//Initialize the string
_history=@"";
}
//Get the url of the plist method
-(NSString*)getFileUrl
{
NSArray *path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentDirectory=[path objectAtIndex:0];
return [documentDirectory
stringByAppendingPathComponent:@"savedResources.plist"];
}
NSDictionary *d;
//This is what I execute when the user presses the save button.
-(void)Save
{
d=@{@"StringKey" :_history, @"ArrayKey" :classes};
[d writeToFile:[self getFileUrl] atomically:YES];
}
However the values are not getting initialized as per the plist. Is it the
way I am extracting the values from the dictionary?

No comments:

Post a Comment