Alexey  Milahin Alexey Milahin - 6 months ago 58
Swift Question

How to move objects in Realm

I have Realm data model

import RealmSwift

class Priority: Object {

dynamic var id = ""
dynamic var text = ""
dynamic var time = ""
}


And I can get all the stored objects

let realm = try! Realm()
let objects = realm.objects(Priority)


How to move an object from the index 7 in the index 3 and save the table?

Answer

You can put the Objects in Realm List, then you can use both move and swap methods to reorder.

Here is the List API: https://realm.io/docs/swift/latest/api/Classes/List.html