我有一个类UserObject(Object),它具有SessionObject(Object)的一个属性,而SessionObject具有其他Realm对象(TestObject,NewObject)的属性。 当我删除子对象后,父对象成功,应用程序崩溃与错误访问:EXC_BAD_ACCESS(代码= EXC_I386_GPFLT)
class UserObject: Object{
dynamic var uuid = ""
dynamic var username = ""
dynamic var session: SessionObject?
class SessionObject: Object{
dynamic var tokenType = ""
dynamic var refreshToken = ""
dynamic var test: TestObject?
dynamic var new: NewObject?
}
class TestObject: Object{
dynamic var test = ""
}
class NewObject: Object{
dynamic var test = ""
}
func deleteUser(){
guard let realm = self.realmInstance else{
return
}
guard let user = Array(realm.objects(UserObject.self)).first else{
return
}
do{
try realm.write {
if let session = user.session{
if let test = session.test{
realm.delete(test)
}
if let new = session.new{
realm.delete(new)
}
realm.delete(session)
}
realm.delete(user)
}
}catch{
}
}
答案 0 :(得分:3)
您正在运行ARC naming conventions,它适用于Swift类的NoSuchEmailException
属性。目前,Realm不会生成符合ARC对特殊命名方法所期望的访问器方法,当您具有以dynamic
,new
或{{1开头的属性名称时,会导致对象被双重删除}}