我使用+[NSUserDefaults standardUserDefaults]来存储应用程序设置。它由大约12个字符串值组成。是否可以永久删除这些值,而不是将它们设置为默认值?


当前回答

我发现了这个:

osascript -e 'tell application "iOS Simulator" to quit'
xcrun simctl list devices | grep -v '^[-=]' | cut -d "(" -f2 | cut -d ")" -f1 | xargs -I {} xcrun simctl erase "{}"

来源:https://gist.github.com/ZevEisenberg/5a172662cb576872d1ab

其他回答

我发现了这个:

osascript -e 'tell application "iOS Simulator" to quit'
xcrun simctl list devices | grep -v '^[-=]' | cut -d "(" -f2 | cut -d ")" -f1 | xargs -I {} xcrun simctl erase "{}"

来源:https://gist.github.com/ZevEisenberg/5a172662cb576872d1ab

所有以上的答案都是非常相关的,但如果有人仍然无法重置用户默认删除的应用程序,那么你可以重置模拟器的内容设置,它将工作。

NSDictionary *defaultsDictionary = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
for (NSString *key in [defaultsDictionary allKeys]) {
                    [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
}

迅速:

let defaults = NSUserDefaults.standardUserDefaults()
defaults.dictionaryRepresentation().keys.forEach { defaults.removeObjectForKey($0) }

你试过使用-removeObjectForKey吗?

 [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"defunctPreference"];