From 4d2505779c786bd14d73849facceb81f9ae6aa97 Mon Sep 17 00:00:00 2001 From: mpaulsonco Date: Tue, 31 Mar 2015 13:19:48 -0500 Subject: [PATCH 1/4] Updated documentation to reflect breaking changes in v0.2.7 --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a082458..a34c080 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,7 @@ A concise [Mantle](https://github.com/Mantle/Mantle)-like way of working with [R ## Breaking Change +- Method `- deepCopy` replaces the previous functionality of `- shallowCopy`, which no longer maintains an object's primary key - Updated to use native primary key support in Realm 0.85.0 - Update your code to use methods `-createOrUpdateInRealm:withJSONArray:` or `-createOrUpdateInRealm:withJSONDictionary:` - You must wrap these methods in a write transaction (between `[realm beginWriteTransaction];` and `[realm commitWriteTransaction];`) @@ -124,6 +125,7 @@ Methods `- shallowCopy` and `- mergePropertiesFromObject:` are provided. The lat [episode mergePropertiesFromObject:anotherEpisode]; }]; +Additionally, method `- deepCopy` is provided. Unlike `- shallowCopy`, it maintains the object's primary key. ## License From 0480c3e4dde7379ef83c591ad4e655b4199693fb Mon Sep 17 00:00:00 2001 From: Camilo Castro Date: Tue, 25 Aug 2015 15:47:50 -0300 Subject: [PATCH 2/4] enable merge of empty primary properties and bumped to 0.2.8 --- Realm+JSON.podspec | 2 +- Realm+JSON/RLMObject+Copying.m | 37 +++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Realm+JSON.podspec b/Realm+JSON.podspec index 0399474..4b9a38d 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.7' + s.version = '0.2.8' s.ios.deployment_target = '7.0' s.osx.deployment_target = '10.9' s.license = { :type => 'MIT', :file => 'LICENSE' } diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index 370ab0b..a37bb85 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -29,18 +29,41 @@ - (instancetype)shallowCopy { } - (void)mergePropertiesFromObject:(id)object { + + BOOL primaryKeyIsEmpty; + id value; + id selfValue; + + BOOL (^valueIsEmpty)(id) = ^BOOL(id value) { + return (value == nil || + [value isKindOfClass:[NSNull class]] || + ([value respondsToSelector:@selector(length)] && + [(NSData *) value length] <= 0) + ); + }; + 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 && + ![selfValue isEqual:value] && + valueIsEmpty(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]; - } } } From 311e693cce542b38ad2a62c5463f205b4b9adfbe Mon Sep 17 00:00:00 2001 From: Camilo Castro Date: Tue, 25 Aug 2015 17:54:17 -0300 Subject: [PATCH 3/4] fixed primary keys for numeric types --- Realm+JSON/RLMObject+Copying.m | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index a37bb85..a0ee930 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -34,12 +34,9 @@ - (void)mergePropertiesFromObject:(id)object { id value; id selfValue; - BOOL (^valueIsEmpty)(id) = ^BOOL(id value) { - return (value == nil || - [value isKindOfClass:[NSNull class]] || - ([value respondsToSelector:@selector(length)] && - [(NSData *) value length] <= 0) - ); + BOOL (^valuesAreEqual)(id, id) = ^BOOL(id value1, id value2) { + return ([[NSString stringWithFormat:@"%@", value1] + isEqualToString:[NSString stringWithFormat:@"%@", value2]]); }; for (RLMProperty *property in self.objectSchema.properties) { @@ -51,8 +48,8 @@ - (void)mergePropertiesFromObject:(id)object { selfValue = [self valueForKeyPath:property.name]; primaryKeyIsEmpty = (property.isPrimary && - ![selfValue isEqual:value] && - valueIsEmpty(selfValue)); + !valuesAreEqual(value, selfValue) + ); if (primaryKeyIsEmpty || !property.isPrimary) { [self setValue:value forKeyPath:property.name]; @@ -67,6 +64,7 @@ - (void)mergePropertiesFromObject:(id)object { } } + - (instancetype)deepCopy { Class class = NSClassFromString([[self class] className]); From 9f0d90c44fd6778482de0a184cddbf9a2da1054d Mon Sep 17 00:00:00 2001 From: Matthew Cheok Date: Thu, 27 Aug 2015 20:33:34 -0700 Subject: [PATCH 4/4] Updated version and demo --- Demo/RealmJSONDemo/MCEpisode.m | 14 +++++++------- Demo/RealmJSONDemo/MCTableViewController.m | 2 +- Realm+JSON.podspec | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) 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