UserDeafults Bug.?

In the last part of my playground proyect i'm trying to use "Userdeafults.standard" and it seems not to be working.

Thanks!

Accepted Reply

Actually you can't use UserDefaults you have to use the PlaygroundKeyValueStore. This makes the data persist between playground pages if that's what you are looking for. Here's the relevant documentation: https://developer.apple.com/library/content/documentation/Xcode/Conceptual/swift_playgrounds_doc_format/PlaygroundKeyValueStoreClass.html

Replies

From what I understand, playgrounds can't make anything that persist (user defaults, writing files, etc).

This is because your playground is unlike an app, it doesn't need to save data for the user's next session and most likely could provide the same functionality with variables or just not having the data persist between playground sessions.


More specifically behind it, this topic appears to demonstrate that the playground doesn't have access to the sandboxed environment at all, and is not something that you can use.


Hope this helps.

Actually you can't use UserDefaults you have to use the PlaygroundKeyValueStore. This makes the data persist between playground pages if that's what you are looking for. Here's the relevant documentation: https://developer.apple.com/library/content/documentation/Xcode/Conceptual/swift_playgrounds_doc_format/PlaygroundKeyValueStoreClass.html