I started trying Realm for IOS, so I created two classes:
Files Model
import Foundation
import RealmSwift
class FilesModel: Object {
@objc dynamic var id : Int = 0
@objc var fileName = ""
@objc dynamic var dateOfCreation = Date()
@objc dynamic var dateOfModification = Date()
@objc dynamic var type = ""
var file = List<Data>()
}
Groups Model
import Foundation
import RealmSwift
class GroupsModel: Object {
@objc dynamic var id : Int = 0
@objc dynamic var name = ""
@objc dynamic var dateOfCreation = Date()
@objc dynamic var dateOfModification = Date()
@objc dynamic var filesCount = Int()
var files = List<FilesModel>()
override static func primaryKey() -> String? {
return "id"
}
}
Now the thing is I am copying files into groups model file Object but I need to delete the parent object. think of it as a move I am moving files into the folder. what I have done is I save a copy of the file into the folder and delete the file from outside the folder.
Problem
when I delete the file outside the folder it will also delete the file inside.
My understanding of the problem
classes is a reference type so I am copying reference. So when I delete the reference it will delete the file from the whole project.
I have tried many solutions like deep copy and detached. Thanks in Advance.