Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #680 from JRG-Developer/Add_Support_For_Boolean_As…

…_String

Added support for boolean attribute provided as a string in data source
  • Loading branch information...
commit 98ec121bf767c495a2e887adeade7383b74a62f4 2 parents eb72053 + 4c91c4d
@casademora casademora authored
View
5 MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m
@@ -50,6 +50,11 @@ - (id) MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData;
value = numberFromString([value description]);
}
}
+ else if (attributeType == NSBooleanAttributeType) {
+ if (![value isKindOfClass:[NSNumber class]] && value != [NSNull null]) {
+ value = [NSNumber numberWithBool:[value boolValue]];
+ }
+ }
else if (attributeType == NSStringAttributeType) {
if (![value isKindOfClass:[NSString class]] && value != [NSNull null]) {
value = [value description];
View
5 Tests/DataImport/ImportSingleEntityWithNoRelationshipsTests.m
@@ -99,6 +99,11 @@ - (void)testImportNumberAsStringAttributeToEntity
XCTAssertEqualObjects(testEntity.numberAsStringTestAttribute, @"10248909829", @"numberAsStringTestAttribute did not contain expected value, instead found: %@", testEntity.numberAsStringTestAttribute);
}
+- (void)testImportBooleanAsStringAttributeToEntity
+{
+ XCTAssertTrue(testEntity.booleanAsStringTestAttribute, @"booleanFromStringTestAttribute did not contain expected value, instead found: %@", testEntity.booleanAsStringTestAttribute);
+}
+
- (void)testImportAttributeNotInJsonData
{
NSRange rangeOfString = [testEntity.notInJsonAttribute rangeOfString:@"Core Data Model"];
View
1  Tests/Fixtures/SingleEntityWithNoRelationships.json
@@ -19,4 +19,5 @@
"doubleAsStringTestAttribute": "124.3",
"floatAsStringTestAttribute": "10000000000",
"numberAsStringTestAttribute" : 10248909829,
+ "booleanAsStringTestAttribute": "true",
}
View
2  Tests/Fixtures/SingleEntityWithNoRelationships.plist
@@ -30,5 +30,7 @@
<string>8/5/2011 1-56-04 AM</string>
<key>nullTestAttribte</key>
<string></string>
+ <key>booleanAsStringTestAttribute</key>
+ <string>true</string>
</dict>
</plist>
View
1  Tests/Fixtures/TestModel.xcdatamodeld/TestModel.xcdatamodel/contents
@@ -67,6 +67,7 @@
</relationship>
</entity>
<entity name="SingleEntityWithNoRelationships" representedClassName="SingleEntityWithNoRelationships" syncable="YES">
+ <attribute name="booleanAsStringTestAttribute" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="booleanTestAttribute" optional="YES" attributeType="Boolean" syncable="YES"/>
<attribute name="colorTestAttribute" optional="YES" attributeType="Transformable" syncable="YES">
<userInfo>
View
26 Tests/Fixtures/TestModel/_SingleEntityWithNoRelationships.h
@@ -6,6 +6,7 @@
extern const struct SingleEntityWithNoRelationshipsAttributes {
+ __unsafe_unretained NSString *booleanAsStringTestAttribute;
__unsafe_unretained NSString *booleanTestAttribute;
__unsafe_unretained NSString *colorTestAttribute;
__unsafe_unretained NSString *dateTestAttribute;
@@ -76,6 +77,22 @@ extern const struct SingleEntityWithNoRelationshipsAttributes {
+@property (nonatomic, strong) NSNumber* booleanAsStringTestAttribute;
+
+
+
+
+@property (atomic) BOOL booleanAsStringTestAttributeValue;
+- (BOOL)booleanAsStringTestAttributeValue;
+- (void)setBooleanAsStringTestAttributeValue:(BOOL)value_;
+
+
+//- (BOOL)validateBooleanAsStringTestAttribute:(id*)value_ error:(NSError**)error_;
+
+
+
+
+
@property (nonatomic, strong) NSNumber* booleanTestAttribute;
@@ -276,6 +293,15 @@ extern const struct SingleEntityWithNoRelationshipsAttributes {
@interface _SingleEntityWithNoRelationships (CoreDataGeneratedPrimitiveAccessors)
+- (NSNumber*)primitiveBooleanAsStringTestAttribute;
+- (void)setPrimitiveBooleanAsStringTestAttribute:(NSNumber*)value;
+
+- (BOOL)primitiveBooleanAsStringTestAttributeValue;
+- (void)setPrimitiveBooleanAsStringTestAttributeValue:(BOOL)value_;
+
+
+
+
- (NSNumber*)primitiveBooleanTestAttribute;
- (void)setPrimitiveBooleanTestAttribute:(NSNumber*)value;
View
34 Tests/Fixtures/TestModel/_SingleEntityWithNoRelationships.m
@@ -5,6 +5,7 @@
const struct SingleEntityWithNoRelationshipsAttributes SingleEntityWithNoRelationshipsAttributes = {
+ .booleanAsStringTestAttribute = @"booleanAsStringTestAttribute",
.booleanTestAttribute = @"booleanTestAttribute",
.colorTestAttribute = @"colorTestAttribute",
.dateTestAttribute = @"dateTestAttribute",
@@ -55,6 +56,11 @@ - (SingleEntityWithNoRelationshipsID*)objectID {
+ (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key {
NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
+ if ([key isEqualToString:@"booleanAsStringTestAttributeValue"]) {
+ NSSet *affectingKey = [NSSet setWithObject:@"booleanAsStringTestAttribute"];
+ keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
+ return keyPaths;
+ }
if ([key isEqualToString:@"booleanTestAttributeValue"]) {
NSSet *affectingKey = [NSSet setWithObject:@"booleanTestAttribute"];
keyPaths = [keyPaths setByAddingObjectsFromSet:affectingKey];
@@ -97,6 +103,34 @@ + (NSSet*)keyPathsForValuesAffectingValueForKey:(NSString*)key {
+@dynamic booleanAsStringTestAttribute;
+
+
+
+- (BOOL)booleanAsStringTestAttributeValue {
+ NSNumber *result = [self booleanAsStringTestAttribute];
+ return [result boolValue];
+}
+
+
+- (void)setBooleanAsStringTestAttributeValue:(BOOL)value_ {
+ [self setBooleanAsStringTestAttribute:@(value_)];
+}
+
+
+- (BOOL)primitiveBooleanAsStringTestAttributeValue {
+ NSNumber *result = [self primitiveBooleanAsStringTestAttribute];
+ return [result boolValue];
+}
+
+- (void)setPrimitiveBooleanAsStringTestAttributeValue:(BOOL)value_ {
+ [self setPrimitiveBooleanAsStringTestAttribute:@(value_)];
+}
+
+
+
+
+
@dynamic booleanTestAttribute;
Please sign in to comment.
Something went wrong with that request. Please try again.