Docs Menu

Supported Property Types - iOS SDK

On this page

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

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.

Note

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.

Give Feedback
© 2021 MongoDB, Inc.

About

  • Careers
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2021 MongoDB, Inc.