Ios 通过领域中的createOrUpdateInRealm查找是否存在新对象
有没有办法确定新对象是否由Ios 通过领域中的createOrUpdateInRealm查找是否存在新对象,ios,objective-c,realm,Ios,Objective C,Realm,有没有办法确定新对象是否由createOrUpdateInRealm方法插入 RLMRealm *realm = [RLMRealm defaultRealm]; SampleRealmObject *object = [[SampleRealmObject alloc] init]; NSDictionary *item = @{@"id": @10, @"name": @"sampleName"}; for (RLMProperty *property in object.obje
createOrUpdateInRealm
方法插入
RLMRealm *realm = [RLMRealm defaultRealm];
SampleRealmObject *object = [[SampleRealmObject alloc] init];
NSDictionary *item = @{@"id": @10, @"name": @"sampleName"};
for (RLMProperty *property in object.objectSchema.properties) {
if([item objectForKey:property.name])
{
[object setValue:[item objectForKey:property.name] forKey:property.name];
}
}
// add or update the new object
[SampleRealmObject createOrUpdateInRealm:realm withValue:object];
否,
+createOrUpdateInRealm:withValue:
不指示对象是已创建还是已更新。如果需要知道具有给定主键的对象是否存在,可以在使用+createOrUpdateInRealm:withValue:
获取对象之前,使用+forPrimaryKey:
检索现有对象,如果不存在,请使用添加
或使用更新
@SachinVas。我知道这种方法,但我想问一下这种方法能给我们带来什么。