当我访问RLMResults计数时,我遇到了一个奇怪的崩溃, 这种崩溃有时会发生,有时候大多数时候我都没有看到,当RLMResult有0结果时它会崩溃。
我也在GitHub上看到了类似的问题,但不知怎的,它在没有解析的情况下被关闭了 https://github.com/realm/realm-cocoa/issues/4960
我的代码
-(BOOL)checkIfSyncRequired{
NSPredicate *predicate=[NSPredicate predicateWithFormat:@"self.appLocalEditTimeStamp > self.lastSyncServerTimestamp"];
RLMResults *results = [HKCrashObject objectsWithPredicate:predicate];
if (results.count) {//crash occurs on calls.count
//do something with results but it crashes before only
return true;
}else{
return false;
}
}
HKCrashObject CLASS
@interface HKCrashObject : RLMObject
@property (nonatomic, strong) NSString * customId;
@property (nonatomic, assign) long lastSyncServerTimestamp;
@property (nonatomic, assign) long appLocalEditTimeStamp;
@property (nonatomic, strong) NSString * otherProperties;
@end
STACK TRACE
(lldb) bt
Realm was compiled with optimization - stepping may behave oddly; variables may not be available.
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
frame #0: 0x000000010ec69f9c Realm`bool realm::Array::compare_leafs_4<realm::Greater, (realm::Action)0, 32ul, bool (*)(long long), 32ul>(realm::Array const*, unsigned long, unsigned long, unsigned long, realm::QueryState<long long>*, bool (*)(long long)) const + 172
frame #1: 0x000000010ec688c8 Realm`bool realm::Array::compare_leafs<realm::Greater, (realm::Action)0, 32ul, bool (*)(long long)>(realm::Array const*, unsigned long, unsigned long, unsigned long, realm::QueryState<long long>*, bool (*)(long long)) const + 504
frame #2: 0x000000010ec68210 Realm`bool realm::Array::compare_leafs<realm::Greater, (realm::Action)0, bool (*)(long long)>(realm::Array const*, unsigned long, unsigned long, unsigned long, realm::QueryState<long long>*, bool (*)(long long)) const + 736
frame #3: 0x000000010ec67b90 Realm`realm::TwoColumnsNode<realm::Column<long long>, realm::Greater>::find_first_local(unsigned long, unsigned long) + 384
frame #4: 0x000000010ecbff93 Realm`realm::ParentNode::aggregate_local(realm::QueryStateBase*, unsigned long, unsigned long, unsigned long, realm::SequentialGetterBase*) + 83
frame #5: 0x000000010ec48a2a Realm`realm::Query::aggregate_internal(realm::Action, realm::DataType, bool, realm::ParentNode*, realm::QueryStateBase*, unsigned long, unsigned long, realm::SequentialGetterBase*) const + 314
frame #6: 0x000000010ec4eb00 Realm`realm::Query::count(unsigned long, unsigned long, unsigned long) const + 480
frame #7: 0x000000010e9c5b2f Realm`realm::Results::size(this=<unavailable>) at results.cpp:136 [opt]
* frame #8: 0x000000010ea5b3b0 Realm`::-[RLMResults count]() [inlined] -[RLMResults count]::$_1::operator()() const at RLMResults.mm:137 [opt]
frame #9: 0x000000010ea5b3a2 Realm`::-[RLMResults count]() [inlined] auto translateRLMResultsErrors<-[RLMResults count]::$_1>(aggregateMethod=<unavailable>) at RLMResults_Private.hpp:57 [opt]
frame #10: 0x000000010ea5b3a2 Realm`::-[RLMResults count](self=<unavailable>, _cmd=<unavailable>) at RLMResults.mm:137 [opt]
frame #11: 0x000000010c31842f Jobi`-[myCallsViewController checkIfSyncRequired](self=0x00007fd2b174b990, _cmd="checkIfSyncRequired") at myCallsViewController.m:415
frame #12: 0x000000010c313939 Jobi`-[myCallsViewController viewWillAppear:](self=0x00007fd2b174b990, _cmd="viewWillAppear:", animated=YES) at myCallsViewController.m:85
frame #13: 0x000000010f61cdc0 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 442
frame #14: 0x000000010f61d62f UIKit`-[UIViewController __viewWillAppear:] + 131
frame #15: 0x000000010f67b9c0 UIKit`-[UITabBarController viewWillAppear:] + 291
frame #16: 0x000000010f61cdc0 UIKit`-[UIViewController _setViewAppearState:isAnimating:] + 442
frame #17: 0x000000010f61d62f UIKit`-[UIViewController __viewWillAppear:] + 131
frame #18: 0x000000010f648d5c UIKit`-[UINavigationController _startCustomTransition:] + 1183
frame #19: 0x000000010f65f5e2 UIKit`-[UINavigationController _startDeferredTransitionIfNeeded:] + 714
frame #20: 0x000000010f6608cc UIKit`-[UINavigationController __viewWillLayoutSubviews] + 150
frame #21: 0x000000010f8b8bd7 UIKit`-[UILayoutContainerView layoutSubviews] + 231
frame #22: 0x000000012c9d761c UIKit`-[UILayoutContainerViewAccessibility layoutSubviews] + 42
frame #23: 0x000000010f542808 UIKit`-[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1515
frame #24: 0x000000010e7ec61a QuartzCore`-[CALayer layoutSublayers] + 177
frame #25: 0x000000010e7f082b QuartzCore`CA::Layer::layout_if_needed(CA::Transaction*) + 395
frame #26: 0x000000010e77729f QuartzCore`CA::Context::commit_transaction(CA::Transaction*) + 343
frame #27: 0x000000010e7a4940 QuartzCore`CA::Transaction::commit() + 568
frame #28: 0x000000010e7a56be QuartzCore`CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 76
frame #29: 0x00000001126fa607 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
frame #30: 0x00000001126fa55e CoreFoundation`__CFRunLoopDoObservers + 430
frame #31: 0x00000001126deb81 CoreFoundation`__CFRunLoopRun + 1537
frame #32: 0x00000001126de30b CoreFoundation`CFRunLoopRunSpecific + 635
frame #33: 0x00000001154fda73 GraphicsServices`GSEventRunModal + 62
frame #34: 0x000000010f4730b7 UIKit`UIApplicationMain + 159
frame #35: 0x000000010c2df85f Jobi`main(argc=1, argv=0x00007ffee3a450d8) at main.m:14
frame #36: 0x000000011399f955 libdyld.dylib`start + 1
frame #37: 0x000000011399f955 libdyld.dylib`start + 1