Docs Menu

Supported Property Types - Swift SDK

On this page

  • Property Cheat Sheet
  • Setting Default Values
  • Type Projection
  • Unique Identifiers
  • Size Limitations

New in version 10.20.0.

You can map unsupported types to supported types to persist in Realm Database. This enables you to work with Swift types that Realm does not support, but store them as types that Realm does support.

You could store a URL as a String, for example, but read it from Realm and use it in your application as though it were a URL.

New in version 10.8.0: UUID type

ObjectId is a MongoDB-specific 12-byte unique value. UUID is a 16-byte globally-unique value. You can index both types, and use either as a primary key.


When declaring default values for @Persisted UUID or ObjectId property attributes, both of these syntax types are valid:

  • @Persisted var value: UUID
  • @Persisted var value = UUID()

However, the second will result in poorer performance. This is because the latter creates a new identifier that is never used any time an object is read from the realm, while the former only creates them when needed.

@Persisted var id: ObjectId has equivalent behavior to @objc dynamic var _id = ObjectId.generate(). They both make random ObjectIds.

@Persisted var _id = ObjectId() has equivalent behavior to @objc dynamic var _id = ObjectId(). They both make zero-initialized ObjectIds.

Data and string properties cannot hold more than 16MB. To store larger amounts of data, either:

  • Break the data into 16MB chunks, or
  • Store data directly on the file system and store paths to the files in the realm.

Realm throws a runtime exception if your app attempts to store more than 16MB in a single property.

To avoid size limitations and a performance impact, it is best not to store large blobs, such as image and video files, directly in a realm. Instead, save the file to a file store and keep only the location of the file and any relevant metadata in the realm.

←  Realm Data Types - Swift SDKType Projection - Swift SDK →
Give Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.