diff --git a/Realm/RLMError.h b/Realm/RLMError.h index c006ea4b8e..636833c240 100644 --- a/Realm/RLMError.h +++ b/Realm/RLMError.h @@ -199,6 +199,10 @@ typedef RLM_ERROR_ENUM(NSInteger, RLMError, RLMErrorDomain) { subscription or the server will reject the write. */ RLMErrorNoSubscriptionForWrite = 22, + / ** + Denotes an error that occurs when resolving thread safe reference returns a nil object. + */ + RLMErrorObjectNotFound = 23 }; #pragma mark - RLMSyncError diff --git a/Realm/RLMObjectBase.mm b/Realm/RLMObjectBase.mm index 0cc1b5a114..6e72c23c45 100644 --- a/Realm/RLMObjectBase.mm +++ b/Realm/RLMObjectBase.mm @@ -723,6 +723,13 @@ - (void)addNotificationBlock:(RLMObjectNotificationCallback)block return; } RLMObjectBase *obj = [_realm resolveThreadSafeReference:tsr]; + if (!obj) { + error = [NSError errorWithDomain:RLMAppErrorDomain + code:RLMErrorObjectNotFound + userInfo:nil]; + block(nil, nil, nil, nil, error); + return; + } _object = realm::Object(_realm->_realm, *obj->_info->objectSchema, obj->_row); _token = _object.add_notification_callback(ObjectChangeCallbackWrapper{block, obj},