Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  2. path = [path stringByAppendingPathComponent:@"List.plist"];
  3.  
  4. NSFileManager *fileManager = [NSFileManager defaultManager];
  5. if (![fileManager fileExistsAtPath:path]) {
  6. NSString *sourcePath = [[NSBundle mainBundle] pathForResource:CONTENT_DEFAULT ofType:PLIST];
  7. [fileManager copyItemAtPath:sourcePath toPath:path error:nil];
  8. }
  9.  
  10. NSArray* newContent = [[NSArray alloc]initWithContentsOfFile:path];
  11. NSDictionary *Dict = [[NSDictionary alloc]initWithDictionary:[newContent objectAtIndex:2]];
  12. [Dict setValue:@"NO" forKey:@"Enabled"];
  13. [Dict writeToFile:path atomically:YES];
  14.  
  15. *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSDictionaryI 0x15de7ff0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Enabled.', or Im wrong in something?
  16.  
  17. NSString *path = [[NSBundle mainBundle] pathForResource:@"List" ofType:@"plist"];
  18.  
  19. NSString *savingPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  20.  
  21. NSArray* newContent = [[NSArray alloc]initWithContentsOfFile:path];
  22. NSMutableDictionary *Dict = [[NSMutableDictionary alloc]initWithDictionary:[newContent objectAtIndex:2]];
  23. [Dict setValue:@"NO" forKey:@"Enabled"];
  24. savingPath = [savingPath stringByAppendingPathComponent:@"Modified.plist"];
  25. [Dict writeToFile:savingPath atomically:YES];
  26.  
  27. NSLog(@"newContent:%@",newContent);
  28. NSArray *newnew = [[NSArray alloc]initWithContentsOfFile:savingPath];
  29. NSLog(@"newnew:%@",newnew);
  30.  
  31. *** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (3) beyond bounds (2)'
  32.  
  33. NSString *path = [[NSBundle mainBundle] pathForResource:@"List" ofType:@"plist"];
  34.  
  35. NSString *savingPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
  36. savingPath = [savingPath stringByAppendingPathComponent:@"Modified.plist"];
  37. [Dict savingPath atomically:YES];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement