Navigation

Supported Property Types - iOS SDK

You can use the following types to define your object model properties:

Type
Required
Optional
Bool
@objc dynamic var value = false
let value = RealmOptional<Bool>()
Int, Int8, Int16, Int32, Int64
@objc dynamic var value = 0
let value = RealmOptional<Int>()
Float
@objc dynamic var value: Float = 0.0
let value = RealmOptional<Float>()
Double
@objc dynamic var value: Double = 0.0
let value = RealmOptional<Double>()
String
@objc dynamic var value = ""
@objc dynamic var value: String? = nil
Data
@objc dynamic var value = Data()
@objc dynamic var value: Data? = nil
Date
@objc dynamic var value = Date()
@objc dynamic var value: Date? = nil
Decimal128
@objc dynamic var decimal: Decimal128 = 0
@objc dynamic var decimal: Decimal128?
@objc dynamic var objectId = ObjectId.generate()
@objc dynamic var objectId: ObjectId?
let value = List<Type>()
User-defined Object
N/A
@objc dynamic var value: MyClass?

Additionally:

You can use RealmOptional to represent integers, doubles, and other types as optional.

CGFloat properties are discouraged, as the type is not platform independent.

Give Feedback