diff --git a/Demo/RealmJSONDemo/MCEpisode.m b/Demo/RealmJSONDemo/MCEpisode.m index debc0eb..57385a5 100644 --- a/Demo/RealmJSONDemo/MCEpisode.m +++ b/Demo/RealmJSONDemo/MCEpisode.m @@ -13,13 +13,13 @@ @implementation MCEpisode + (NSDictionary *)JSONInboundMappingDictionary { return @{ - @"episode.title": @"title", - @"episode.description": @"subtitle", - @"episode.id": @"episodeID", - @"episode.episode_number": @"episodeNumber", - @"episode.episode_type": @"episodeType", - @"episode.thumbnail_url": @"thumbnailURL", - @"episode.published_at": @"publishedDate", + @"title": @"title", + @"description": @"subtitle", + @"id": @"episodeID", + @"episode_number": @"episodeNumber", + @"episode_type": @"episodeType", + @"thumbnail_url": @"thumbnailURL", + @"published_at": @"publishedDate", }; } diff --git a/Demo/RealmJSONDemo/MCTableViewController.m b/Demo/RealmJSONDemo/MCTableViewController.m index 1e4b70d..693b2ce 100644 --- a/Demo/RealmJSONDemo/MCTableViewController.m +++ b/Demo/RealmJSONDemo/MCTableViewController.m @@ -29,7 +29,7 @@ @implementation MCTableViewController - (IBAction)reloadData { AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager GET:@"https://www.nsscreencast.com/api/episodes.json" parameters:nil success: ^(AFHTTPRequestOperation *operation, id responseObject) { - NSArray *array = responseObject; + NSArray *array = responseObject[@"episodes"]; dispatch_async(dispatch_get_main_queue(), ^{ RLMRealm *realm = [RLMRealm defaultRealm]; diff --git a/Realm+JSON.podspec b/Realm+JSON.podspec index 483e8c6..6565a62 100644 --- a/Realm+JSON.podspec +++ b/Realm+JSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Realm+JSON' - s.version = '0.2.10' + s.version = '0.2.11' s.ios.deployment_target = '7.0' s.osx.deployment_target = '10.9' s.license = { :type => 'MIT', :file => 'LICENSE' } @@ -16,5 +16,5 @@ Pod::Spec.new do |s| s.source_files = 'Realm+JSON/*.{h,m}' s.public_header_files = 'Realm+JSON/*.h' - s.dependency 'Realm', '~> 0.92' + s.dependency 'Realm', '~> 0.95' end diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index 3c7a8bf..6bb0b52 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -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];