Classes
The following classes are available globally.
-
A 128-bit IEEE 754-2008 decimal floating point number.
This type is similar to Swift’s built-in Decimal type, but allocates bits differently, resulting in a different representable range. (NS)Decimal stores a significand of up to 38 digits long and an exponent from -128 to 127, while this type stores up to 34 digits of significand and an exponent from -6143 to 6144.
See moreDeclaration
Swift
@objc(RealmSwiftDecimal128) public final class Decimal128 : RLMDecimal128, Decodable, @unchecked Sendableextension Decimal128: BSONextension Decimal128: Encodableextension Decimal128: ExpressibleByIntegerLiteralextension Decimal128: ExpressibleByFloatLiteralextension Decimal128: ExpressibleByStringLiteralextension Decimal128: Comparableextension Decimal128: Numericextension Decimal128: _PersistableInsideOptional, _DefaultConstructibleextension Decimal128: _QueryNumericextension Decimal128: _RealmCollectionValueInsideOptionalextension Decimal128: MinMaxTypeextension Decimal128: AddableTypeextension Decimal128: SortableType -
A 12-byte (probably) unique object identifier.
ObjectIds are similar to a GUID or a UUID, and can be used to uniquely identify objects without a centralized ID generator. An ObjectID consists of:
- A 4 byte timestamp measuring the creation time of the ObjectId in seconds since the Unix epoch.
- A 5 byte random value
- A 3 byte counter, initialized to a random value.
ObjectIds are intended to be fast to generate. Sorting by an ObjectId field will typically result in the objects being sorted in creation order.
See moreDeclaration
Swift
@objc(RealmSwiftObjectId) public final class ObjectId : RLMObjectId, Decodable, @unchecked Sendableextension ObjectId: BSONextension ObjectId: _PersistableInsideOptional, _DefaultConstructible, _PrimaryKey, _Indexableextension ObjectId: Encodableextension ObjectId: Comparableextension ObjectId: _RealmCollectionValueInsideOptional -
Listis the container type in Realm used to define to-many relationships.Like Swift’s
Array,Listis a generic type that is parameterized on the type it stores. This can be either anObjectsubclass or one of the following types:Bool,Int,Int8,Int16,Int32,Int64,Float,Double,String,Data,Date,Decimal128, andObjectId(and their optional versions)Unlike Swift’s native collections,
Lists are reference types, and are only immutable if the Realm that manages them is opened as read-only.Lists can be filtered and sorted with the same predicates as
Results<Element>.Properties of
See moreListtype defined onObjectsubclasses must be declared asletand cannot bedynamic.Declaration
Swift
public final class List<Element> : RLMSwiftCollectionBase, RealmCollectionImpl where Element : RealmCollectionValueextension List: ObservableObject, RealmSubscribableextension List: _ObjcBridgeableextension List: MutableCollectionextension List: _RealmSchemaDiscoverable, SchemaDiscoverable where Element: _RealmSchemaDiscoverableextension List: _HasPersistedType, _Persistable, _DefaultConstructible where Element: _Persistableextension List: Decodable where Element: Decodableextension List: Encodable where Element: Encodable -
MutableSetis the container type in Realm used to define to-many relationships with distinct values as objects.Like Swift’s
Set,MutableSetis a generic type that is parameterized on the type it stores. This can be either anObjectsubclass or one of the following types:Bool,Int,Int8,Int16,Int32,Int64,Float,Double,String,Data,Date,Decimal128, andObjectId(and their optional versions)Unlike Swift’s native collections,
MutableSets are reference types, and are only immutable if the Realm that manages them is opened as read-only.MutableSet’s can be filtered and sorted with the same predicates as
Results<Element>.Properties of
See moreMutableSettype defined onObjectsubclasses must be declared asletand cannot bedynamic.Declaration
Swift
public final class MutableSet<Element> : RLMSwiftCollectionBase, RealmCollectionImpl where Element : RealmCollectionValueextension MutableSet: ObservableObject, RealmSubscribableextension MutableSet: _ObjcBridgeableextension MutableSet: _RealmSchemaDiscoverable, SchemaDiscoverable where Element: _RealmSchemaDiscoverableextension MutableSet: _HasPersistedType, _Persistable, _DefaultConstructible where Element: _Persistableextension MutableSet: Decodable where Element: Decodableextension MutableSet: Encodable where Element: Encodable -
Map is a key-value storage container used to store supported Realm types.
Map is a generic type that is parameterized on the type it stores. This can be either an Object subclass or one of the following types: Bool, Int, Int8, Int16, Int32, Int64, Float, Double, String, Data, Date, Decimal128, and ObjectId (and their optional versions)
Note
Optional versions of the above types exceptObjectare only supported in non-synchronized Realms.Map only supports String as a key.
Unlike Swift’s native collections,
Maps is a reference types, and are only immutable if the Realm that manages them is opened as read-only.A Map can be filtered and sorted with the same predicates as
Results<Value>.Properties of
See moreMaptype defined onObjectsubclasses must be declared asletand cannot bedynamic.Declaration
Swift
public final class Map<Key, Value> : RLMSwiftCollectionBase where Key : _MapKey, Value : RealmCollectionValueextension Map: ObservableObject, RealmSubscribableextension Map: Sequenceextension Map: RealmKeyedCollectionextension Map: _RealmSchemaDiscoverable, SchemaDiscoverable where Value: _RealmSchemaDiscoverableextension Map: _HasPersistedType, _Persistable, _DefaultConstructible where Value: _Persistableextension Map: Decodable where Key: Decodable, Value: Decodableextension Map: Encodable where Key: Encodable, Value: Encodable -
A
RealmOptionalinstance represents an optional value for types that can’t be directly declared as@objcin Swift, such asInt,Float,Double, andBool.To change the underlying value stored by a
See moreRealmOptionalinstance, mutate the instance’svalueproperty.Declaration
Swift
@available(*, deprecated, renamed: "RealmProperty", message: "RealmOptional<T> has been deprecated, use RealmProperty<T?> instead.") public final class RealmOptional<Value> : RLMSwiftValueStorage where Value : RealmOptionalTypeextension RealmOptional: SchemaDiscoverable, _RealmSchemaDiscoverable where Value: _RealmSchemaDiscoverableextension RealmOptional: Equatable where Value: Equatableextension RealmOptional: Codable where Value: Codable, Value: _RealmSchemaDiscoverable -
A
RealmPropertyinstance represents an polymorphic value for supported types.To change the underlying value stored by a
RealmPropertyinstance, mutate the instance’svalueproperty.See moreNote
AnRealmPropertyshould not be declared as@objc dynamicon a Realm Object. Useletinstead.Declaration
Swift
public final class RealmProperty<Value> : RLMSwiftValueStorage where Value : RealmPropertyTypeextension RealmProperty: _RealmSchemaDiscoverable, SchemaDiscoverableextension RealmProperty: Equatable where Value: Equatableextension RealmProperty: Codable where Value: Codable
-
Projectionis a light weight model of the original RealmObjectorEmbeddedObject. You can useProjectionas a view model to minimize boilerplate.Example of usage:
public class Person: Object { @Persisted var firstName = "" @Persisted var lastName = "" @Persisted var address: Address? = nil @Persisted var friends = List<Person>() @Persisted var reviews = List<String>() } public class Address: EmbeddedObject { @Persisted var city: String = "" @Persisted var country = "" } class PersonProjection: Projection<Person> { @Projected(\Person.firstName) var firstName @Projected(\Person.lastName.localizedUppercase) var lastNameCaps @Projected(\Person.address.city) var homeCity @Projected(\Person.friends.projectTo.firstName) var friendsFirstName: ProjectedCollection<String> }### Supported property types
Projection can transform the original
@Persistedproperties in several ways:Passthrough-Projection‘s property will have same name and type as original object. SeePersonProjection.firstName.Rename- Projection’s property will have same type as original object just with the new name.Keypath resolution- you can access the certain properties of the projectedObject. SeePersonProjection.lastNameCapsandPersonProjection.homeCity.Collection mapping-ListandMutableSetofObjects orEmbeddedObjects can be projected as a collection of primitive values. SeePersonProjection.friendsFirstName.Exclusion- all properties of the original Realm object that were not defined in the projection model will be excluded from projection. Any changes happened on those properties will not trigger a change notification for theProjection. You still can access the originalObjectorEmbeddedObjectand observe notifications directly on it.
Note
each@Persistedproperty can be@Projectedin different ways in the same Projection class. EachObjectorEmbeddedObjectcan have sevaral projections of same or different classes at once.Querying
You can retrieve all Projections of a given type from a Realm by calling the
objects(_:)of Realm orinit(projecting:)of Projection’s class:
See morelet projections = realm.object(PersonProjection.self) let personObject = realm.create(Person.self) let singleProjection = PersonProjection(projecting: personObject)Declaration
Swift
open class Projection<Root> : RealmCollectionValue, ProjectionObservable where Root : RLMObjectBase, Root : RealmCollectionValueextension Projection: KeypathSortableextension Projection: ThreadConfined where Root: ThreadConfinedextension Projection: ObservableObject, RealmSubscribable where Root: ThreadConfined
-
A property wrapper type that may be passed between threads.
A
@ThreadSafeproperty contains a thread-safe reference to the underlying wrapped value. This reference is resolved to the thread on which the wrapped value is accessed. A new thread safe reference is created each time the property is accessed.Warning
This property wrapper should not be used for properties on long lived objects.
@ThreadSafeproperties contain aThreadSafeReferencewhich can pin the source version of the Realm in use. This means that this property wrapper is better suited for function arguments and local variables that get captured by an aynchronously dispatched block.See
Declaration
Swift
@propertyWrapper public final class ThreadSafe<T> where T : ThreadConfinedextension ThreadSafe: @unchecked Sendable
View on GitHub
Install in Dash
Classes Reference