how much can i store in userdefaults

Asked on 08/02/2024

1 search

The amount of data you can store in UserDefaults is not explicitly limited by Apple, but it is generally recommended to keep it small. UserDefaults is designed for storing simple data types like String, Int, Double, Bool, URL, Data, and collections of these types. It is not intended for storing large amounts of data or complex objects.

For more complex or larger data storage needs, Apple provides other options such as Core Data, SQLite, or custom data stores using SwiftData. For example, in the session Create a custom data store with SwiftData, it is demonstrated how to implement a custom store that uses a JSON file to persist models.

If you need to track changes and history in your data, you might want to look into the session Track model changes with SwiftData history, which explains how to implement history tracking in custom data stores.

Relevant Sessions

  1. Create a custom data store with SwiftData
  2. Track model changes with SwiftData history