how much can i store in userdefaults

Generated on 8/2/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
Create a custom data store with SwiftData

Create a custom data store with SwiftData

Combine the power of SwiftData’s expressive, declarative modeling API with your own persistence backend. Learn how to build a custom data store and explore how to progressively add persistence features in your app. To get the most out of this session, watch “Meet SwiftData” and “Model your schema with SwiftData” from WWDC23.

Track model changes with SwiftData history

Track model changes with SwiftData history

Reveal the history of your model’s changes with SwiftData! Use the history API to understand when data store changes occurred, and learn how to use this information to build features like remote server sync and out-of-process change handing in your app. We’ll also cover how you can build support for the history API into a custom data store.

Port advanced games to Apple platforms

Port advanced games to Apple platforms

Discover how simple it can be to reach players on Apple platforms worldwide. We’ll show you how to evaluate your Windows executable on Apple silicon, start your game port with code samples, convert your shader code to Metal, and bring your game to Mac, iPhone, and iPad. Explore enhanced Metal tools that understand HLSL shaders to validate, debug, and profile your ported shaders on Metal.

What’s new in SwiftData

What’s new in SwiftData

SwiftData makes it easy to add persistence to your app with its expressive, declarative API. Learn about refinements to SwiftData, including compound uniqueness constraints, faster queries with #Index, queries in Xcode previews, and rich predicate expressions. Join us to explore how you can use all of these features to express richer models and improve performance in your app. To discover how to build a custom data store or use the history API in SwiftData, watch “Create a custom data store with SwiftData” and “Track model changes with SwiftData history”.