SWIFT – How to use registerDefaults ()

I searched everywhere and couldn’t find an explanation of how to use registerDefaults(). Every post asking how to set default values ​​was answered by “use registerDefaults()”, one I encountered The small problem is that I don’t know how to use registerDefaults(). Can someone tell me exactly what code to write and where to put it. My question: I have 5 values ​​(Int) that need to have specific default values, but I can later Changed by the user. I checked the Xcode documentation, youtube and google, but couldn’t find the answer.
just pass the key value For dictionary:

NSUserDefaults.standardUserDefaults().registerDefaults([
"SomeKey": 123,
"SomeArrayKey": [1, 2, 3, 4, 5]
])

I searched everywhere and couldn’t find an explanation of how to use registerDefaults(). Each asked how to set the default value The posts are all answered by “use registerDefaults()”. One small problem I encountered is that I don’t know how to use registerDefaults(). Can someone tell me exactly what code to write and where to put it. My question: I There are 5 values ​​(Int) that need to have specific default values, but they can be changed by the user later. I checked the Xcode documentation, youtube and google, and couldn’t find the answer.

Simply pass a dictionary of key-value pairs:

NSUserDefaults.standardUserDefaults().registerDefaults([
"SomeKey": 123,
" SomeArrayKey": [1, 2, 3, 4, 5]
])

Leave a Comment

Your email address will not be published.