每当我保存一个领域对象时,我都会遇到崩溃,崩溃点是一个类型为SaleItemVariation的属性,它从 Installing package into ‘/home/nomani/R/x86_64-pc-linux-gnu-library/3.4’
(as ‘lib’ is unspecified)
trying URL
'https://cran.rstudio.com/src/contrib/cplexAPI_1.3.3.tar.gz'
Content type 'application/x-gzip' length 404918 bytes (395 KB)
==================================================
downloaded 395 KB
* installing *source* package ‘cplexAPI’ ...
** package ‘cplexAPI’ successfully unpacked and MD5 sums checked
checking for gcc... gcc -std=gnu99
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc -std=gnu99 accepts -g... yes
checking for gcc -std=gnu99 option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for cplex... NONE
configure: error: CPLEX interactive optimizer not found
ERROR: configuration failed for package ‘cplexAPI’
* removing ‘/home/nomani/R/x86_64-pc-linux-gnu-library/3.4/cplexAPI’
Warning in install.packages :
installation of package ‘cplexAPI’ had non-zero exit status
The downloaded source packages are in
‘/tmp/RtmpBEFSoC/downloaded_packages’
设置nil。
RLMAccessor.mm
我的课程:
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);
}
}
我不知道为什么会这样?
注意:Realm版本为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
}
答案 0 :(得分:1)
保存领域对象必须位于领域区域内。
try? realm.write {
//realm add
//realm update
//realm delete
}