From ec5e95626a197fa8def2a6d6cca239b522d476a1 Mon Sep 17 00:00:00 2001 From: "J.P. Illanes" Date: Fri, 9 Jan 2015 10:21:09 +0900 Subject: [PATCH 1/5] Added deepShallowCopy --- Realm+JSON/RLMObject+Copying.h | 1 + Realm+JSON/RLMObject+Copying.m | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Realm+JSON/RLMObject+Copying.h b/Realm+JSON/RLMObject+Copying.h index 0cc5d45..623013d 100644 --- a/Realm+JSON/RLMObject+Copying.h +++ b/Realm+JSON/RLMObject+Copying.h @@ -11,6 +11,7 @@ @interface RLMObject (Copying) - (instancetype)shallowCopy; +- (instancetype)deepShallowCopy; - (void)mergePropertiesFromObject:(id)object; @end diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index 94d9e53..9e530ec 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -35,4 +35,38 @@ - (void)mergePropertiesFromObject:(id)object { } } +- (instancetype)deepShallowCopy { + Class class = NSClassFromString([[self class] className]); + + RLMObject *object = [[class alloc] init]; + + for (RLMProperty *property in self.objectSchema.properties) { + // assume array + + if (property.type == RLMPropertyTypeArray) { + RLMArray *thisArray = [self valueForKeyPath:property.name]; + RLMArray *newArray = [object valueForKeyPath:property.name]; + + for (RLMObject *currentObject in thisArray) + { + [newArray addObject:[currentObject deepShallowCopy]]; + } + + } + else if (property.type == RLMPropertyTypeObject) + { + RLMObject *value = [self valueForKeyPath:property.name]; + [object setValue:[value deepShallowCopy] forKeyPath:property.name]; + }else + { + id value = [self valueForKeyPath:property.name]; + [object setValue:value forKeyPath:property.name]; + } + } + + return object; +} + + + @end From d4d5a702ce9249f7fda44e643bb64d93534e9cd0 Mon Sep 17 00:00:00 2001 From: "J.P. Illanes" Date: Fri, 9 Jan 2015 10:33:50 +0900 Subject: [PATCH 2/5] Removed extra comment --- Realm+JSON/RLMObject+Copying.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index 9e530ec..f5036f9 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -41,8 +41,7 @@ - (instancetype)deepShallowCopy { RLMObject *object = [[class alloc] init]; for (RLMProperty *property in self.objectSchema.properties) { - // assume array - + if (property.type == RLMPropertyTypeArray) { RLMArray *thisArray = [self valueForKeyPath:property.name]; RLMArray *newArray = [object valueForKeyPath:property.name]; From 592f29578185af0d45549cdce8a8ced92daa3764 Mon Sep 17 00:00:00 2001 From: "J.P. Illanes" Date: Fri, 9 Jan 2015 10:35:23 +0900 Subject: [PATCH 3/5] Adjusted indentation --- Realm+JSON/RLMObject+Copying.m | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index f5036f9..8d8a084 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -46,18 +46,16 @@ - (instancetype)deepShallowCopy { RLMArray *thisArray = [self valueForKeyPath:property.name]; RLMArray *newArray = [object valueForKeyPath:property.name]; - for (RLMObject *currentObject in thisArray) - { + for (RLMObject *currentObject in thisArray) { [newArray addObject:[currentObject deepShallowCopy]]; } } - else if (property.type == RLMPropertyTypeObject) - { + else if (property.type == RLMPropertyTypeObject) { RLMObject *value = [self valueForKeyPath:property.name]; [object setValue:[value deepShallowCopy] forKeyPath:property.name]; - }else - { + } + else{ id value = [self valueForKeyPath:property.name]; [object setValue:value forKeyPath:property.name]; } From bd4c0ce54ca36f9b28dfae37210ee8535d0133f8 Mon Sep 17 00:00:00 2001 From: "J.P. Illanes" Date: Fri, 9 Jan 2015 10:36:13 +0900 Subject: [PATCH 4/5] Adjusted indentation --- Realm+JSON/RLMObject+Copying.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index 8d8a084..3d3353f 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -55,7 +55,7 @@ - (instancetype)deepShallowCopy { RLMObject *value = [self valueForKeyPath:property.name]; [object setValue:[value deepShallowCopy] forKeyPath:property.name]; } - else{ + else { id value = [self valueForKeyPath:property.name]; [object setValue:value forKeyPath:property.name]; } From 7a5398371a34e2a4675eff8a63d628762baa43a7 Mon Sep 17 00:00:00 2001 From: "J.P. Illanes" Date: Fri, 9 Jan 2015 12:26:38 +0900 Subject: [PATCH 5/5] Renamed deepShallowCopy as deepCopy --- Realm+JSON/RLMObject+Copying.h | 2 +- Realm+JSON/RLMObject+Copying.m | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Realm+JSON/RLMObject+Copying.h b/Realm+JSON/RLMObject+Copying.h index 623013d..21030e6 100644 --- a/Realm+JSON/RLMObject+Copying.h +++ b/Realm+JSON/RLMObject+Copying.h @@ -11,7 +11,7 @@ @interface RLMObject (Copying) - (instancetype)shallowCopy; -- (instancetype)deepShallowCopy; +- (instancetype)deepCopy; - (void)mergePropertiesFromObject:(id)object; @end diff --git a/Realm+JSON/RLMObject+Copying.m b/Realm+JSON/RLMObject+Copying.m index 3d3353f..bbc09c2 100644 --- a/Realm+JSON/RLMObject+Copying.m +++ b/Realm+JSON/RLMObject+Copying.m @@ -35,7 +35,7 @@ - (void)mergePropertiesFromObject:(id)object { } } -- (instancetype)deepShallowCopy { +- (instancetype)deepCopy { Class class = NSClassFromString([[self class] className]); RLMObject *object = [[class alloc] init]; @@ -47,13 +47,13 @@ - (instancetype)deepShallowCopy { RLMArray *newArray = [object valueForKeyPath:property.name]; for (RLMObject *currentObject in thisArray) { - [newArray addObject:[currentObject deepShallowCopy]]; + [newArray addObject:[currentObject deepCopy]]; } } else if (property.type == RLMPropertyTypeObject) { RLMObject *value = [self valueForKeyPath:property.name]; - [object setValue:[value deepShallowCopy] forKeyPath:property.name]; + [object setValue:[value deepCopy] forKeyPath:property.name]; } else { id value = [self valueForKeyPath:property.name];