Skip to content

Commit a366392

Browse files
committed
Merge branch 'release/0.2.11'
2 parents d952c0a + 9f0d90c commit a366392

File tree

4 files changed

+38
-17
lines changed

4 files changed

+38
-17
lines changed

Demo/RealmJSONDemo/MCEpisode.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ @implementation MCEpisode
1313

1414
+ (NSDictionary *)JSONInboundMappingDictionary {
1515
return @{
16-
@"episode.title": @"title",
17-
@"episode.description": @"subtitle",
18-
@"episode.id": @"episodeID",
19-
@"episode.episode_number": @"episodeNumber",
20-
@"episode.episode_type": @"episodeType",
21-
@"episode.thumbnail_url": @"thumbnailURL",
22-
@"episode.published_at": @"publishedDate",
16+
@"title": @"title",
17+
@"description": @"subtitle",
18+
@"id": @"episodeID",
19+
@"episode_number": @"episodeNumber",
20+
@"episode_type": @"episodeType",
21+
@"thumbnail_url": @"thumbnailURL",
22+
@"published_at": @"publishedDate",
2323
};
2424
}
2525

Demo/RealmJSONDemo/MCTableViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ @implementation MCTableViewController
2929
- (IBAction)reloadData {
3030
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
3131
[manager GET:@"https://www.nsscreencast.com/api/episodes.json" parameters:nil success: ^(AFHTTPRequestOperation *operation, id responseObject) {
32-
NSArray *array = responseObject;
32+
NSArray *array = responseObject[@"episodes"];
3333
dispatch_async(dispatch_get_main_queue(), ^{
3434
RLMRealm *realm = [RLMRealm defaultRealm];
3535

Realm+JSON.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Realm+JSON'
3-
s.version = '0.2.10'
3+
s.version = '0.2.11'
44
s.ios.deployment_target = '7.0'
55
s.osx.deployment_target = '10.9'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
1616
s.source_files = 'Realm+JSON/*.{h,m}'
1717
s.public_header_files = 'Realm+JSON/*.h'
1818

19-
s.dependency 'Realm', '~> 0.92'
19+
s.dependency 'Realm', '~> 0.95'
2020
end

Realm+JSON/RLMObject+Copying.m

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,42 @@ - (instancetype)shallowCopy {
2727
}
2828

2929
- (void)mergePropertiesFromObject:(id)object {
30+
31+
BOOL primaryKeyIsEmpty;
32+
id value;
33+
id selfValue;
34+
35+
BOOL (^valuesAreEqual)(id, id) = ^BOOL(id value1, id value2) {
36+
return ([[NSString stringWithFormat:@"%@", value1]
37+
isEqualToString:[NSString stringWithFormat:@"%@", value2]]);
38+
};
39+
3040
for (RLMProperty *property in self.objectSchema.properties) {
31-
// assume array
32-
if (property.type == RLMPropertyTypeArray) {
41+
42+
if (property.type != RLMPropertyTypeArray) {
43+
44+
// asume data
45+
value = [object valueForKeyPath:property.name];
46+
selfValue = [self valueForKeyPath:property.name];
47+
48+
primaryKeyIsEmpty = (property.isPrimary &&
49+
!valuesAreEqual(value, selfValue)
50+
);
51+
52+
if (primaryKeyIsEmpty || !property.isPrimary) {
53+
[self setValue:value forKeyPath:property.name];
54+
}
55+
56+
} else {
57+
// asume array
3358
RLMArray *thisArray = [self valueForKeyPath:property.name];
3459
RLMArray *thatArray = [object valueForKeyPath:property.name];
3560
[thisArray addObjects:thatArray];
3661
}
37-
// assume data
38-
else if (!property.isPrimary) {
39-
id value = [object valueForKeyPath:property.name];
40-
[self setValue:value forKeyPath:property.name];
41-
}
4262
}
4363
}
4464

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

0 commit comments

Comments
 (0)