From ba6727e4e47c1263afc7c87537b119a3b221a125 Mon Sep 17 00:00:00 2001 From: Matthew Cheok Date: Mon, 25 Aug 2014 10:27:55 +0800 Subject: [PATCH] Updated for Realm 0.83 --- Demo/Podfile | 2 +- Realm+JSON.podspec | 6 +++--- Realm+JSON/RLMObject+JSON.h | 10 ++++++++++ Realm+JSON/RLMObject+JSON.m | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Demo/Podfile b/Demo/Podfile index 0501205..47b0c08 100644 --- a/Demo/Podfile +++ b/Demo/Podfile @@ -1,4 +1,4 @@ platform :ios, '6.0' -pod 'AFNetworking', '~> 2.3' +pod 'AFNetworking' pod 'Realm+JSON', :path => '../' diff --git a/Realm+JSON.podspec b/Realm+JSON.podspec index f5d9a3b..9dc5fe7 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.1.2' + s.version = '0.1.3' s.ios.deployment_target = '6.0' s.license = { :type => 'MIT', :file => 'LICENSE' } s.summary = 'A concise Mantle-like way of working with Realm and JSON.' @@ -15,8 +15,8 @@ Pod::Spec.new do |s| s.source_files = 'Realm+JSON/*.{h,m}' s.public_header_files = 'Realm+JSON/*.h' - s.dependency 'Realm', '0.82.0' + s.dependency 'Realm', '0.83.0' s.xcconfig = { - 'FRAMEWORK_SEARCH_PATHS' => '$(PODS_ROOT)/Realm/realm-cocoapods-0.82.0/ios' + 'FRAMEWORK_SEARCH_PATHS' => '$(PODS_ROOT)/Realm/realm-cocoapods-0.83.0/ios' } end diff --git a/Realm+JSON/RLMObject+JSON.h b/Realm+JSON/RLMObject+JSON.h index c44af9d..fc35c09 100644 --- a/Realm+JSON/RLMObject+JSON.h +++ b/Realm+JSON/RLMObject+JSON.h @@ -18,4 +18,14 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)dictionary; - (NSDictionary *)JSONDictionary; +- (void)performInTransaction:(void (^)())transaction; +- (void)removeFromRealm; + @end + +@interface RLMArray (SWAdditions) + +- (NSArray *)NSArray; +- (NSArray *)JSONArray; + +@end \ No newline at end of file diff --git a/Realm+JSON/RLMObject+JSON.m b/Realm+JSON/RLMObject+JSON.m index 5540f3e..3d69013 100644 --- a/Realm+JSON/RLMObject+JSON.m +++ b/Realm+JSON/RLMObject+JSON.m @@ -72,6 +72,18 @@ - (NSDictionary *)JSONDictionary { return [self mc_createJSONDictionary]; } +- (void)performInTransaction:(void (^)())transaction { + NSAssert(transaction != nil, @"No transaction block provided"); + [self.realm transactionWithBlock:transaction]; +} + +- (void)removeFromRealm { + [self performInTransaction:^{ + [self.realm deleteObject:self]; + }]; +} + + #pragma mark - Private + (instancetype)mc_createFromJSONDictionary:(NSDictionary *)dictionary { @@ -397,3 +409,23 @@ - (NSString *)camelToSnakeCase { } @end + +@implementation RLMArray (SWAdditions) + +- (NSArray *)NSArray { + NSMutableArray *array = [NSMutableArray arrayWithCapacity:self.count]; + for (id object in self) { + [array addObject:object]; + } + return [array copy]; +} + +- (NSArray *)JSONArray { + NSMutableArray *array = [NSMutableArray array]; + for (RLMObject *object in self) { + [array addObject:[object JSONDictionary]]; + } + return [array copy]; +} + +@end \ No newline at end of file