ObjectId

@objc(RealmSwiftObjectId)
public final class ObjectId : RLMObjectId, Decodable
extension ObjectId: BSON
extension ObjectId: Encodable
extension ObjectId: Comparable
extension ObjectId: _RealmCollectionValueInsideOptional

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:

  1. A 4 byte timestamp measuring the creation time of the ObjectId in seconds since the Unix epoch.
  2. A 5 byte random value
  3. 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.

Initializers

  • Creates a new zero-initialized ObjectId.

    Declaration

    Swift

    public override required init()
  • Creates a new randomly-initialized ObjectId.

    Declaration

    Swift

    public override class func generate() -> ObjectId
  • Creates a new ObjectId from the given 24-byte hexadecimal string.

    Throws if the string is not 24 characters or contains any characters other than 0-9a-fA-F.

    Declaration

    Swift

    public override required init(string: String) throws

    Parameters

    string

    The string to parse.

  • Creates a new ObjectId using the given date, machine identifier, process identifier.

    Declaration

    Swift

    public required init(timestamp: Date, machineId: Int, processId: Int)

    Parameters

    timestamp

    A timestamp as NSDate.

    machineId

    The machine identifier.

    processId

    The process identifier.

  • Creates a new ObjectId from the given 24-byte hexadecimal static string.

    Aborts if the string is not 24 characters or contains any characters other than 0-9a-fA-F. Use the initializer which takes a String to handle invalid strings at runtime.

    Declaration

    Swift

    public required init(_ str: StaticString)
  • Creates a new ObjectId by decoding from the given decoder.

    This initializer throws an error if reading from the decoder fails, or if the data read is corrupted or otherwise invalid.

    Declaration

    Swift

    public required init(from decoder: Decoder) throws

    Parameters

    decoder

    The decoder to read data from.

  • Encodes this ObjectId into the given encoder.

    This function throws an error if the given encoder is unable to encode a string.

    Declaration

    Swift

    public func encode(to encoder: Encoder) throws

    Parameters

    encoder

    The encoder to write data to.

  • Returns a Boolean value indicating whether the value of the first argument is less than that of the second argument.

    Declaration

    Swift

    public static func < (lhs: ObjectId, rhs: ObjectId) -> Bool

    Parameters

    lhs

    An ObjectId value to compare.

    rhs

    Another ObjectId value to compare.

  • Returns a Boolean value indicating whether the ObjectId of the first argument is less than or equal to that of the second argument.

    Declaration

    Swift

    public static func <= (lhs: ObjectId, rhs: ObjectId) -> Bool

    Parameters

    lhs

    An ObjectId value to compare.

    rhs

    Another ObjectId value to compare.

  • Returns a Boolean value indicating whether the ObjectId of the first argument is greater than or equal to that of the second argument.

    Declaration

    Swift

    public static func >= (lhs: ObjectId, rhs: ObjectId) -> Bool

    Parameters

    lhs

    An ObjectId value to compare.

    rhs

    Another ObjectId value to compare.

  • Returns a Boolean value indicating whether the ObjectId of the first argument is greater than that of the second argument.

    Declaration

    Swift

    public static func > (lhs: ObjectId, rhs: ObjectId) -> Bool

    Parameters

    lhs

    An ObjectId value to compare.

    rhs

    Another ObjectId value to compare.