Classes
The following classes are available globally.
-
List
is the container type in Realm used to define to-many relationships.Like Swift’s
Array
,List
is a generic type that is parameterized on the type it stores. This can be either anObject
subclass or one of the following types:Bool
,Int
,Int8
,Int16
,Int32
,Int64
,Float
,Double
,String
,Data
, andDate
(and their optional versions)Unlike Swift’s native collections,
List
s 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 moreList
type defined onObject
subclasses must be declared aslet
and cannot bedynamic
.Declaration
Swift
public final class List<Element> : ListBase where Element : RealmCollectionValue
-
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 theObject
class directly.class Dog: Object { @objc dynamic var name: String = "" @objc dynamic var adopted: Bool = false let siblings = List<Dog>() }
Supported property types
String
,NSString
Int
Int8
,Int16
,Int32
,Int64
Float
Double
Bool
Date
,NSDate
Data
,NSData
RealmOptional<Value>
for optional numeric propertiesObject
subclasses, to model many-to-one relationshipsList<Element>
, to model many-to-many relationships
String
,NSString
,Date
,NSDate
,Data
,NSData
andObject
subclass properties can be declared as optional.Int
,Int8
,Int16
,Int32
,Int64
,Float
,Double
,Bool
, andList
properties cannot. To store an optional number, useRealmOptional<Int>
,RealmOptional<Float>
,RealmOptional<Double>
, orRealmOptional<Bool>
instead, which wraps an optional numeric value.All property types except for
List
andRealmOptional
must be declared as@objc dynamic var
.List
andRealmOptional
properties must be declared as non-dynamiclet
properties. Swiftlazy
properties are not allowed.Note that none of the restrictions listed above apply to properties that are configured to be ignored by Realm.
Querying
You can retrieve all objects of a given type from a Realm by calling the
objects(_:)
instance method.Relationships
See our Cocoa guide for more details.
See moreDeclaration
Swift
@objc(RealmSwiftObject) open class Object : RLMObjectBase, ThreadConfined, RealmCollectionValue
-
A
RealmOptional
instance represents an optional value for types that can’t be directly declared as@objc
in Swift, such asInt
,Float
,Double
, andBool
.To change the underlying value stored by a
See moreRealmOptional
instance, mutate the instance’svalue
property.Declaration
Swift
public final class RealmOptional<Value> : RLMOptionalBase where Value : RealmOptionalType
-
A permission which can be applied to a Realm, Class, or specific Object.
Permissions are applied by adding the permission to the RealmPermission singleton object, the ClassPermission object for the desired class, or to a user-defined List
See moreproperty on a specific Object instance. The meaning of each of the properties of Permission depend on what the permission is applied to, and so are left undocumented here. See RealmPrivileges
,ClassPrivileges
, andObjectPrivileges
for details about what each of the properties mean when applied to that type.Declaration
Swift
@objc(RealmSwiftPermission) public class Permission : Object
-
A Role within the permissions system.
A Role consists of a name for the role and a list of users which are members of the role. Roles are granted privileges on Realms, Classes and Objects, and in turn grant those privileges to all users which are members of the role.
A role named
See moreeveryone
is automatically created in new Realms, and all new users which connect to the Realm are automatically added to it. Any other roles you wish to use are managed as normal Realm objects.Declaration
Swift
@objc(RealmSwiftPermissionRole) public class PermissionRole : Object
-
A representation of a sync user within the permissions system.
PermissionUser objects are created automatically for each sync user which connects to a Realm, and can also be created manually if you wish to grant permissions to a user which has not yet connected to this Realm. When creating a PermissionUser manually, you must also manually add it to the
See moreeveryone
Role.Declaration
Swift
@objc(RealmSwiftPermissionUser) public class PermissionUser : Object
-
A singleton object which describes Realm-wide permissions.
An object of this type is automatically created in the Realm for you, and more objects cannot be created manually.
See
See moreRealmPrivileges
for the meaning of permissions applied to a Realm.Declaration
Swift
@objc(RealmSwiftRealmPermission) public class RealmPermission : Object