I am trying to save a UIColor to an NSMutableDictionary with other items when I use the back button my my NavController. Everything saves and loads again when I click on a button to create the ViewController from the plist file except for the UIColor which is 'null'? I added some NSLogs to see what was happening.
If I delete my plist and start fresh here is what happens. This method checks for the plist file and creates it if it is not there, or loads the information.
When I write to my plist I have an NSLog that checks to see what is going to be saved.
The console print out is this for the NSLog
But when I try to reload it is returning a 'null'
What am I over looking?
If I delete my plist and start fresh here is what happens. This method checks for the plist file and creates it if it is not there, or loads the information.
Code:
- (void)readPlist{
NSString *filePath = [self dataFilePath];
if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
savedList = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSArray *tempArray = [[NSArray alloc] initWithArray: [savedList objectForKey:@"monthly"]];
checkNumbers = [[NSMutableArray alloc] initWithArray: tempArray copyItems:YES];
[tempArray release];
NSArray *tempArrayTwo = [[NSArray alloc] initWithArray: [savedList objectForKey:@"total"]];
totalPayments = [[NSMutableArray alloc] initWithArray: tempArrayTwo copyItems:YES];
[tempArrayTwo release];
NSArray *tempArrayThree = [[NSArray alloc] initWithArray: [savedList objectForKey:@"item"]];
NSLog(@"TempArrayThree %@", tempArrayThree);
clientList = [[NSMutableArray alloc] initWithArray: tempArrayThree copyItems:YES];
[tempArrayThree release];
[COLOR="Red"]CGColorRef tmpColor = [[savedList objectForKey:@"backgroundColor"] CGColor];
NSLog(@" Temp Color Loaded %@",[savedList objectForKey:@"backgroundColor"]);
backDropColor = [[UIColor alloc] initWithCGColor:tmpColor];
[COLOR="Blue"]NSLog(@"Color Loaded %@", backDropColor);[/COLOR][/COLOR]
}
else{
savedList = [[NSMutableDictionary alloc] init];
[savedList writeToFile: filePath atomically:YES]; // if it can't find it, it writes a blank file.
NSLog(@"No Plist on file - created new one");
checkNumbers = [[NSMutableArray alloc] init];
totalPayments = [[NSMutableArray alloc] init];
clientList = [[NSMutableArray alloc] init];
[COLOR="Red"] backDropColor = [[UIColor alloc] initWithRed: 0.7 green:0.7 blue:0.7 alpha:1.0];[/COLOR]
[COLOR="Blue"]NSLog(@"BackGround Color load:%@ ", backDropColor);[/COLOR]
}
}
When I write to my plist I have an NSLog that checks to see what is going to be saved.
Code:
- (void)writePlist{
[COLOR="Blue"] NSLog(@"BackGround Color to be saved:%@ ", backDropColor);[/COLOR]
[savedList setObject:clientList forKey:@"item"];
[savedList setObject:checkNumbers forKey:@"monthly"];
[savedList setObject:totalPayments forKey:@"total"];
[COLOR="Red"][savedList setObject: backDropColor forKey:@"backgroundColor"];[/COLOR]
[savedList writeToFile:[self dataFilePath] atomically:YES];
}
BackGround Color to be saved:UIDeviceRGBColorSpace 0.567326 0.501412 0.595574 1
But when I try to reload it is returning a 'null'
Code:
CGColorRef tmpColor = [[savedList objectForKey:@"backgroundColor"] CGColor];
[COLOR="Red"]NSLog(@" Temp Color Loaded %@",[savedList objectForKey:@"backgroundColor"]);[/COLOR]
backDropColor = [[UIColor alloc] initWithCGColor:tmpColor];
NSLog(@"Color Loaded %@", backDropColor);
2011-10-15 14:28:02.761 MoneyList[2581:207] Temp Color Loaded (null)
What am I over looking?