我正在尝试这样的代码:
the key "firstUseValue" exists?
if it does:
is valueForKey("firstUseValue") true?
print("USING FOR THE FIRST TIME")
setValueForKey("firstUseValue", false)
else
print("I HAVE BEEN USED BEFORE")
if it doesn't:
create bool for key "firstUseValue" with value true
print("USING FOR THE FIRST TIME")
但由于NSUserDefault已更改为UserDefaults(在swift中),我无法编写单行代码而没有编译错误(我无法理解)。
如何正确使用UserDefaults编写此代码?
答案 0 :(得分:5)