Skip to content

Commit

Permalink
Updated to include non null string transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewcheok committed May 23, 2015
1 parent 14a9c19 commit 2c8af22
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Realm+JSON.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Realm+JSON'
s.version = '0.2.9'
s.version = '0.2.10'
s.ios.deployment_target = '7.0'
s.osx.deployment_target = '10.9'
s.license = { :type => 'MIT', :file => 'LICENSE' }
Expand Down
15 changes: 15 additions & 0 deletions Realm+JSON/MCJSONNonNullStringTransformer.h
@@ -0,0 +1,15 @@
//
// MCJSONNonNullStringTransformer.h
// Pods
//
// Created by Matthew Cheok on 23/5/15.
//
//

#import <Foundation/Foundation.h>

@interface MCJSONNonNullStringTransformer : NSValueTransformer

+ (instancetype)valueTransformer;

@end
38 changes: 38 additions & 0 deletions Realm+JSON/MCJSONNonNullStringTransformer.m
@@ -0,0 +1,38 @@
//
// MCJSONNonNullStringTransformer.m
// Pods
//
// Created by Matthew Cheok on 23/5/15.
//
//

#import "MCJSONNonNullStringTransformer.h"

@implementation MCJSONNonNullStringTransformer

+ (instancetype)valueTransformer {
return [[self alloc] init];
}

+ (Class)transformedValueClass {
return [NSString class];
}

+ (BOOL)allowsReverseTransformation {
return YES;
}

- (id)transformedValue:(id)value {
if (value && ![value isKindOfClass:[NSNull class]]) {
return value;
}
else {
return @"";
}
}

- (id)reverseTransformedValue:(id)value {
return value;
}

@end

0 comments on commit 2c8af22

Please sign in to comment.