Why doesen't it work to write this NSMutableArray to a plist?
Posted
by Emil
on Stack Overflow
See other posts from Stack Overflow
or by Emil
Published on 2010-04-27T15:09:19Z
Indexed on
2010/04/27
16:23 UTC
Read the original article
Hit count: 382
edited.
Hey, I am trying to write an NSMutableArray to a plist. The compiler does not show any errors, but it does not write to the plist anyway. I have tried this on a real device too, not just the Simulator.
Basically, what this code does, is that when you click the accessoryView
of a UITableViewCell
, it gets the indexPath
pressed, edits an NSMutableArray
and tries to write that NSMutableArray
to a plist. It then reloads the arrays mentioned (from multiple plists) and reloads the data in a UITableView
from the arrays.
Code:
NSIndexPath *indexPath = [table indexPathForRowAtPoint:[[[event touchesForView:sender] anyObject] locationInView:table]];
[arrayFav removeObjectAtIndex:[arrayFav indexOfObject:[NSNumber numberWithInt:[[arraySub objectAtIndex:indexPath.row] intValue]]]];
NSString *rootPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPath = [rootPath stringByAppendingPathComponent:@"arrayFav.plist"];
NSLog(@"%@ - %@", rootPath, plistPath);
[arrayFav writeToFile:plistPath atomically:YES];
// Reloads data into the arrays
[self loadDataFromPlists];
// Reloads data in tableView from arrays
[tableFarts reloadData];
© Stack Overflow or respective owner