iphone - writeToFile not saving new entry into plist

后端 未结 2 1754
梦谈多话
梦谈多话 2020-12-12 02:18

My writeToFile is not saving my data to my .plist.

- (IBAction)clickBtnDone:(id) sender {
 NSLog(@\"Done\");
 if ([txtGroupName.text length] > 0) {  
  [s         


        
2条回答
  •  长情又很酷
    2020-12-12 02:33

    NSString* plistPath = nil;
    NSFileManager* manager = [NSFileManager defaultManager];
     if ((plistPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"PathTo.plist"])) 
       {
        if ([manager isWritableFileAtPath:plistPath]) 
         {
           NSMutableDictionary* infoDict = [NSMutableDictionary dictionaryWithContentsOfFile:plistPath];
          [infoDict setObject:@"foo object" forKey:@"fookey"];
          [infoDict writeToFile:plistPath atomically:NO];
          [manager setAttributes:[NSDictionary dictionaryWithObject:[NSDate date] forKey:NSFileModificationDate] ofItemAtPath:[[NSBundle mainBundle] bundlePath] error:nil];
         }
       }
    

提交回复
热议问题