gpt4 book ai didi

ios - 保存 Realm 对象时应用程序崩溃... RLMAccessor 将对象设置为 nil

转载 作者:搜寻专家 更新时间:2023-10-31 22:55:45 25 4
gpt4 key购买 nike

每当我保存 Realm 对象时,我都会崩溃,崩溃点指向类型为 SaleItemVariation 的属性,该属性从 RLMAccessor.mm 设置为 nil。

if (_promote_existing && [obj isKindOfClass:_info.rlmObjectSchema.objectClass] && !prop.swiftIvar) {
// set the ivars for object and array properties to nil as otherwise the
// accessors retain objects that are no longer accessible via the properties
// this is mainly an issue when the object graph being added has cycles,
// as it's not obvious that the user has to set the *ivars* to nil to
// avoid leaking memory
if (prop.type == RLMPropertyTypeObject) {
((void(*)(id, SEL, id))objc_msgSend)(obj, prop.setterSel, nil);
}
}

我的类(class):

final class SaleItem: Object, Mappable{
.....
@objc dynamic var variation: SaleItemVariation!
......

var singleQuantityPrice: Double {
return variation.price // Crash here, Fatal error: Unexpectedly found nil while unwrapping an Optional value
}
}

class SaleItemVariation: Object, Mappable{
@objc dynamic var price: Double = 0
}

我不知道为什么会这样?

注意:Realm 版本为 2.10.2

最佳答案

保存 Realm 对象必须在 Realm block 内。

try? realm.write {
//realm add
//realm update
//realm delete
}

关于ios - 保存 Realm 对象时应用程序崩溃... RLMAccessor 将对象设置为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48077146/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com