Skip to content

Commit

Permalink
Merge branch 'release/0.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcheok committed Aug 25, 2014
2 parents a537412 + ba6727e commit fbd3b83
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Demo/Podfile
@@ -1,4 +1,4 @@
platform :ios, '6.0'

pod 'AFNetworking', '~> 2.3'
pod 'AFNetworking'
pod 'Realm+JSON', :path => '../'
6 changes: 3 additions & 3 deletions 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.'
Expand All @@ -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
10 changes: 10 additions & 0 deletions Realm+JSON/RLMObject+JSON.h
Expand Up @@ -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
32 changes: 32 additions & 0 deletions Realm+JSON/RLMObject+JSON.m
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

0 comments on commit fbd3b83

Please sign in to comment.