首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSDictionary writeToFile未写入

NSDictionary writeToFile未写入
EN

Stack Overflow用户
提问于 2012-05-03 08:06:28
回答 1查看 3.4K关注 0票数 1

我使用有效的字典运行以下代码,但仍然得到"not written":

代码语言:javascript
复制
 NSFileManager* fm = [[NSFileManager alloc] init];
 __autoreleasing NSError* err = nil;

 NSURL* DD = [fm URLForDirectory:NSDocumentDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:&err];
 if (!err) {
     NSString* debugPath = [[DD path] stringByAppendingPathComponent:@"debug.plist"];

     NSLog(@"login-signup write that file!");
     NSDictionary* remMe = [NSDictionary dictionaryWithObjectsAndKeys:[userJSON objectForKey:kRememberMeToken],kRememberMeToken,[userJSON objectForKey:@"id"],@"id",nil];

     NSMutableDictionary* toStore = [NSMutableDictionary dictionaryWithDictionary:dict];
     [toStore setObject:Password.text forKey:kPassword];
     NSMutableDictionary* toStoreTwo = nil;
     if([fm fileExistsAtPath:debugPath]){
           toStoreTwo = [NSMutableDictionary dictionaryWithContentsOfFile:debugPath];
           [toStoreTwo setObject:[toStore copy] forKey:@"signup"];
           [toStoreTwo setObject:remMe forKey:@"login"];
     }
     else{
           toStoreTwo = [NSMutableDictionary dictionaryWithObject:[toStore copy] forKey:@"signup"];
           [toStoreTwo setObject:remMe forKey:@"login"];
     }

     NSDictionary* sDict = [NSDictionary dictionaryWithObject:toStoreTwo forKey:[NSString stringWithFormat:@"signup-debug-%@",[NSDate date]]];

     NSLog(@"saving %@ to file",sDict);
     BOOL success = [sDict writeToFile:debugPath atomically:NO];
     if(!success){
            NSLog(@"not written");
     }
     else{
            NSLog(@"written");
     }
   }

任何帮助都是最好的!

Stackoverflow需要更多的内容来解释代码,但我认为很容易看到发生了什么,如果你有任何问题,请发表意见!

EN

回答 1

Stack Overflow用户

发布于 2012-07-03 13:45:17

看看这个问题,write to file fails。我有一些问题,但在检查了我的字典中的所有数据类型后发现了错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10423419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档