Не могу записать данные в файл plist в - цель c

Я пытаюсь читать и записывать данные в мой plist -файл, хотя часть для чтения идет хорошо, часть для записи ничего не делает.

Я могу быть ошибочно принят за часть записи - я не вижу никаких изменений в моем файле под моим пакетом - он все еще пуст после моих изменений, и когда я закрываю приложение и открываю его снова - я все еще вижу пустую строку адреса электронной почты.

Код для написания (и размещения plist в папке документов для будущих записей)

NSFileManager *fileManger=[NSFileManager defaultManager];
NSError *error;
NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *doumentDirectoryPath=[pathsArray objectAtIndex:0];
NSString *destinationPath= [doumentDirectoryPath stringByAppendingPathComponent:@"userData.plist"];

NSLog(@"plist path %@",destinationPath);
if ([fileManger fileExistsAtPath:destinationPath]){
    NSLog(@"database localtion %@",destinationPath);
    //return;
}

NSString *sourcePath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"userData.plist"];
[fileManger copyItemAtPath:sourcePath toPath:destinationPath error:&error];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: sourcePath];
NSString *emailAddress = (NSString *)[dict objectForKey: @"emailAddress"];
if([emailAddress isEqualToString:@""])
{
    // Do stuff
}

И для написания

NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString *doumentDirectoryPath =[pathsArray objectAtIndex:0];

NSString *destinationPath = [doumentDirectoryPath stringByAppendingPathComponent:@"userData.plist"];

NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile: destinationPath];

[plistDict setValue:@"myEmail@gmail.com" forKey:@"emailAddress"];
[plistDict writeToFile:destinationPath atomically: YES];

Но, как я уже сказал, ничего не изменилось в самом файле, и даже когда я сохраняю, закройте приложение и откройте его снова (строка всегда пуста в моей части чтения)

Любая помощь будет более чем приветствоваться.

0 ответов

Другие вопросы по тегам