LoginSignup
0
1

More than 3 years have passed since last update.

UserDefaults register(defaults:) の勘違い

Posted at
let key = "hogehoge"
print(UserDefaults.standard.integer(forKey: key))
UserDefaults.standard.register(defaults: [key:12345])
print(UserDefaults.standard.integer(forKey: key))

これを実行すると、

0
12345

と出力されます。ここまでは問題なし。
そのままもう一回実行すると、

0
12345

また同じ出力になります。なんで最初0なん?:disappointed_relieved:

ドキュメントをよく見てみると、

原文:

The contents of the registration domain are not written to disk; you need to call this method each time your application starts.

DeepL:

登録ドメインの内容がディスクに書き込まれないので、アプリケーションが起動するたびにこのメソッドを呼び出す必要があります。

NOT WRITTEN! :scream:
書き込まれない!:scream:

ずっと書き込まれると思ってました。

0
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1