The following type aliases are available globally.
Swift
public typealias PropertyType = RLMPropertyType
An opaque token which is returned from methods which subscribe to changes to a Realm.
DeclarationSwift
public typealias NotificationToken = RLMNotificationToken
Object
is a class used to define Realm model objects.
In Realm you define your model classes by subclassing Object
and adding properties to be managed. You then instantiate and use your custom subclasses instead of using the Object
class directly.
class Dog: Object {
@Persisted var name: String
@Persisted var adopted: Bool
@Persisted var siblings: List<Dog>
}
Supported property types
String
Int
, Int8
, Int16
, Int32
, Int64
Float
Double
Bool
Date
Data
Decimal128
ObjectId
UUID
AnyRealmValue
PersistableEnum
.Object
subclasses, to model many-to-one relationshipsEmbeddedObject
subclasses, to model owning one-to-one relationshipsAll of the types above may also be Optional
, with the exception of AnyRealmValue
. Object
and EmbeddedObject
subclasses must be Optional.
In addition to individual values, three different collection types are supported:
List<Element>
: an ordered mutable collection similar to Array
.MutableSet<Element>
: an unordered uniquing collection similar to Set
.Map<String, Element>
: an unordered key-value collection similar to Dictionary
.The Element type of collections may be any of the supported non-collection property types listed above. Collections themselves may not be Optional, but the values inside them may be, except for lists and sets of Object
or EmbeddedObject
subclasses.
Finally, LinkingObjects
properties can be used to track which objects link to this one.
All properties which should be stored by Realm must be explicitly marked with @Persisted
. Any properties not marked with @Persisted
will be ignored entirely by Realm, and may be of any type.
You can retrieve all objects of a given type from a Realm by calling the objects(_:)
instance method.
See our Swift guide for more details.
DeclarationSwift
public typealias Object = RealmSwiftObject
EmbeddedObject
is a base class used to define embedded Realm model objects.
Embedded objects work similarly to normal objects, but are owned by a single parent Object (which itself may be embedded). Unlike normal top-level objects, embedded objects cannot be directly created in or added to a Realm. Instead, they can only be created as part of a parent object, or by assigning an unmanaged object to a parent object’s property. Embedded objects are automatically deleted when the parent object is deleted or when the parent is modified to no longer point at the embedded object, either by reassigning an Object property or by removing the embedded object from the List containing it.
Embedded objects can only ever have a single parent object which links to them, and attempting to link to an existing managed embedded object will throw an exception.
The property types supported on EmbeddedObject
are the same as for Object
, except for that embedded objects cannot link to top-level objects, so Object
and List<Object>
properties are not supported (EmbeddedObject
and List<EmbeddedObject>
are).
Embedded objects cannot have primary keys or indexed properties.
class Owner: Object {
@Persisted var name: String
@Persisted var dogs: List<Dog>
}
class Dog: EmbeddedObject {
@Persisted var name: String
@Persisted var adopted: Bool
@Persisted(originProperty: "dogs") var owner: LinkingObjects<Owner>
}
Declaration
Swift
public typealias EmbeddedObject = RealmSwiftEmbeddedObject
A struct that represents the coordinates of a point formed by a latitude and a longitude value.
Values outside this ranges will return nil when trying to create a GeoPoint
.
Note
There is no dedicated type to store Geospatial points, instead points should be stored as
GeoJson-shapedembedded object, as explained below. Geospatial queries (
geoWithin
) can only be executed in such a type of objects and will throw otherwise.
Persisting geo points in Realm is currently done using duck-typing, which means that any model class with a specific shape can be queried as though it contained a geographical location.
the following is required:
@Persisted var type: String = "Point"
.@Persisted private var coordinates: List<Double>
.The recommended approach is using an embedded object.
public class Location: EmbeddedObject {
@Persisted private var coordinates: List<Double>
@Persisted private var type: String = "Point"
public var latitude: Double { return coordinates[1] }
public var longitude: Double { return coordinates[0] }
convenience init(_ latitude: Double, _ longitude: Double) {
self.init()
// Longitude comes first in the coordinates array of a GeoJson document
coordinates.append(objectsIn: [longitude, latitude])
}
}
Warning
This structure cannot be persisted and can only be used to build other geospatial shapes such as (
GeoBox
,
GeoPolygon
and
GeoCircle
).
DeclarationSwift
public typealias GeoPoint = RLMGeospatialPoint
A class that represents a rectangle, that can be used in a geospatial geoWithin
query.
Warning
This class cannot be persisted and can only be use within a geospatial
geoWithin
query.
DeclarationSwift
public typealias GeoBox = RLMGeospatialBox
A class that represents a polygon, that can be used in a geospatial geoWithin
query.
A GeoPolygon
describes a shape conformed of and outer Polygon
, called outerRing
, and 0 or more inner Polygon
s, called holes
, which represents an unlimited number of internal holes inside the outer Polygon
. A Polygon
describes a shape conformed by at least three segments, where the last and the first GeoPoint
must be the same to indicate a closed polygon (meaning you need at least 4 points to define a polygon). Inner holes in a GeoPolygon
must be entirely inside the outer ring
A hole
has the following restrictions:
Only one nesting is allowed.
Warning
This class cannot be persisted and can only be use within a geospatial geoWithin
query.
Warning
Altitude is not used in any of the query calculations.
DeclarationSwift
public typealias GeoPolygon = RLMGeospatialPolygon
This structure is a helper to represent/convert a distance. It can be used in geospatial queries like those represented by a GeoCircle
Warning
DeclarationSwift
public typealias Distance = RLMDistance
A class that represents a circle, that can be used in a geospatial geoWithin
query.
Warning
This class cannot be persisted and can only be use within a geospatial
geoWithin
query.
DeclarationSwift
public typealias GeoCircle = RLMGeospatialCircle
The type of a migration block used to migrate a Realm.
DeclarationSwift
public typealias MigrationBlock = @Sendable (_ migration: Migration, _ oldSchemaVersion: UInt64) -> Void
Parameters migration
A Migration
object used to perform the migration. The migration object allows you to enumerate and alter any existing objects which require migration.
oldSchemaVersion
The schema version of the Realm being migrated.
An object class used during migrations.
DeclarationSwift
public typealias MigrationObject = DynamicObject
A block type which provides both the old and new versions of an object in the Realm. Object properties can only be accessed using subscripting.
Parameters oldObject
The object from the original Realm (read-only).
newObject
The object from the migrated Realm (read-write).
Migration
instances encapsulate information intended to facilitate a schema migration.
A Migration
instance is passed into a user-defined MigrationBlock
block when updating the version of a Realm. This instance provides access to the old and new database schemas, the objects in the Realm, and provides functionality for modifying the Realm during the migration.
Swift
public typealias Migration = RLMMigration
The Id of the asynchronous transaction.
DeclarationSwift
public typealias AsyncTransactionId = RLMAsyncTransactionId
The type of a block to run for notification purposes when the data in a Realm is modified.
DeclarationSwift
public typealias NotificationBlock = (_ notification: Realm.Notification, _ realm: Realm) -> Void
Logger
is used for creating your own custom logging logic.
You can define your own logger creating an instance of Logger
and define the log function which will be invoked whenever there is a log message.
let logger = Logger(level: .all) { level, message in
print("Realm Log - \(level): \(message)")
}
Set this custom logger as you default logger using Logger.shared
.
Logger.shared = inMemoryLogger
Note
By default default log threshold level is
.info
, and logging strings are output to Apple System Logger.
DeclarationSwift
public typealias Logger = RLMLogger
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4