Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:matthewcheok/Realm-JSON into dev…
Browse files Browse the repository at this point in the history
…elop

# Conflicts:
#	Realm+JSON.podspec
  • Loading branch information
matthewcheok committed Aug 28, 2015
2 parents d952c0a + 036ccc1 commit 6bc1b70
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions Realm+JSON/RLMObject+Copying.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,42 @@ - (instancetype)shallowCopy {
}

- (void)mergePropertiesFromObject:(id)object {

BOOL primaryKeyIsEmpty;
id value;
id selfValue;

BOOL (^valuesAreEqual)(id, id) = ^BOOL(id value1, id value2) {
return ([[NSString stringWithFormat:@"%@", value1]
isEqualToString:[NSString stringWithFormat:@"%@", value2]]);
};

for (RLMProperty *property in self.objectSchema.properties) {
// assume array
if (property.type == RLMPropertyTypeArray) {

if (property.type != RLMPropertyTypeArray) {

// asume data
value = [object valueForKeyPath:property.name];
selfValue = [self valueForKeyPath:property.name];

primaryKeyIsEmpty = (property.isPrimary &&
!valuesAreEqual(value, selfValue)
);

if (primaryKeyIsEmpty || !property.isPrimary) {
[self setValue:value forKeyPath:property.name];
}

} else {
// asume array
RLMArray *thisArray = [self valueForKeyPath:property.name];
RLMArray *thatArray = [object valueForKeyPath:property.name];
[thisArray addObjects:thatArray];
}
// assume data
else if (!property.isPrimary) {
id value = [object valueForKeyPath:property.name];
[self setValue:value forKeyPath:property.name];
}
}
}


- (instancetype)deepCopy {
RLMObject *object = [[NSClassFromString(self.objectSchema.className) alloc] init];

Expand Down

0 comments on commit 6bc1b70

Please sign in to comment.