0

Somehow, the below mentioned code seems to delete my ~/Library/Preferences/NAME.PRODUCT.plist

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setValue:NO forKey:@"ViewFirstShown"];
    [defaults synchronize];

I can confirm the plist file exists before these lines are called. But the plist file disappears immediately after running the above codes.

I thought synchronise writes the values to the disk immediately. I tried waiting a while too, but the plist just doesn't re-appear.

Am I missing anything?

Thanks in advance.

4

1 回答 1

1

这里没有足够的信息来真正回答您的问题。

在执行上述代码时,“ViewFirstShown”键是首选项 plist 中的唯一键吗?如果是这样,那么-setValue:forKey:调用将删除首选项中的最后一个键,这将删除首选项 plist。

需要注意的另一件事是,您正在使用-[NSUserDefaults setValue:forKey:]whichid取值。因为NOis0L并且这实际上nil是你删除了这里的任何值。您可能想-[NSUserDefaults setBool:forKey:]改用。

于 2011-10-20T21:37:33.300 回答