我使用有效的字典运行以下代码,但仍然“未写入”:
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 需要更多内容来解释代码,但我认为很容易看到发生了什么,如果您有任何问题,请发表评论!