Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 通过领域中的createOrUpdateInRealm查找是否存在新对象_Ios_Objective C_Realm - Fatal编程技术网

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。我知道这种方法,但我想问一下这种方法能给我们带来什么。