How to auto increment

After reading the documentation, I was unable to figure out how to create a table with an integer number of primary keys with an autoincrement attribute. Im using fast.

import UIKit
import Realm

class Person: RLMObject {
    var name = ""
    var birthdate = NSDate(timeIntervalSince1970: 1)
    var dogs = RLMArray(objectClassName: Dog.className())
}

      

Thanks in advance

+3


source to share


1 answer


I think to set the primary key (assuming you are ok with strings) you should use:

class Person: RLMObject {
    var id = ""
    var name = ""
    var birthdate = NSDate(timeIntervalSince1970: 1)
    var dogs = RLMArray(objectClassName: Dog.className())

    override class func primaryKey() -> String {
        return "id"
    }
}

      



Then you need to use a unique id when you set Person.id. Here is a related question that discusses what How to set Auto Grow Key in Realm?

0


source







All Articles