Skip to content

Commit

Permalink
Merge pull request #334 from angelolloqui/develop
Browse files Browse the repository at this point in the history
Convert NSString to NSNumber when importing
  • Loading branch information
casademora committed Jan 25, 2013
2 parents 5d1cfd2 + 75381fb commit 435da59
Show file tree
Hide file tree
Showing 10 changed files with 433 additions and 57 deletions.
Expand Up @@ -11,6 +11,7 @@

NSDate * adjustDateForDST(NSDate *date);
NSDate * dateFromString(NSString *value, NSString *format);
NSNumber * numberFromString(NSString *value);
NSString * attributeNameFromString(NSString *value);
NSString * primaryKeyNameFromString(NSString *value);

Expand Down
4 changes: 4 additions & 0 deletions MagicalRecord/Categories/DataImport/MagicalImportFunctions.m
Expand Up @@ -43,6 +43,10 @@
return parsedDate;
}

NSNumber * numberFromString(NSString *value) {
return [NSNumber numberWithDouble:[value doubleValue]];
}

NSInteger* newColorComponentsFromString(NSString *serializedColor);
NSInteger* newColorComponentsFromString(NSString *serializedColor)
{
Expand Down
Expand Up @@ -41,6 +41,16 @@ - (id) MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData;
}
// value = adjustDateForDST(value);
}
else if (attributeType == NSInteger16AttributeType ||
attributeType == NSInteger32AttributeType ||
attributeType == NSInteger64AttributeType ||
attributeType == NSDecimalAttributeType ||
attributeType == NSDoubleAttributeType ||
attributeType == NSFloatAttributeType) {
if (![value isKindOfClass:[NSNumber class]] && value != [NSNull null]) {
value = numberFromString([value description]);
}
}
}

return value == [NSNull null] ? nil : value;
Expand Down
10 changes: 10 additions & 0 deletions MagicalRecord/Categories/DataImport/NSString+MagicalDataImport.m
Expand Up @@ -21,5 +21,15 @@ - (NSString *) MR_capitalizedFirstCharacterString;
return self;
}

- (id) MR_relatedValueForRelationship:(NSRelationshipDescription *)relationshipInfo
{
return self;
}

- (NSString *) MR_lookupKeyForAttribute:(NSAttributeDescription *)attributeInfo
{
return nil;
}

@end

Expand Up @@ -154,7 +154,7 @@ - (void) MR_setRelationships:(NSDictionary *)relationships forKeysWithObject:(id
}
};

if ([relationshipInfo isToMany])
if ([relationshipInfo isToMany] && [relatedObjectData isKindOfClass:[NSArray class]])
{
for (id singleRelatedObjectData in relatedObjectData)
{
Expand Down
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1810" systemVersion="12C54" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1811" systemVersion="12C60" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="AbstractRelatedEntity" representedClassName="AbstractRelatedEntity" isAbstract="YES">
<attribute name="sampleBaseAttribute" optional="YES" attributeType="String">
<userInfo/>
Expand Down Expand Up @@ -105,21 +105,39 @@
<entry key="dateFormat" value="M/d/yyyy H-mm-ss a"/>
</userInfo>
</attribute>
<attribute name="decimalAsStringTestAttribute" optional="YES" attributeType="Decimal" defaultValueString="0.0">
<userInfo/>
</attribute>
<attribute name="decimalTestAttribute" optional="YES" attributeType="Decimal" defaultValueString="0.0">
<userInfo/>
</attribute>
<attribute name="doubleAsStringTestAttribute" optional="YES" attributeType="Double" defaultValueString="0.0">
<userInfo/>
</attribute>
<attribute name="doubleTestAttribute" optional="YES" attributeType="Double" defaultValueString="0.0">
<userInfo/>
</attribute>
<attribute name="floatAsStringTestAttribute" optional="YES" attributeType="Float" defaultValueString="0">
<userInfo/>
</attribute>
<attribute name="floatTestAttribute" optional="YES" attributeType="Float" defaultValueString="0">
<userInfo/>
</attribute>
<attribute name="int16AsStringTestAttribute" optional="YES" attributeType="Integer 16" defaultValueString="0">
<userInfo/>
</attribute>
<attribute name="int16TestAttribute" optional="YES" attributeType="Integer 16" defaultValueString="0">
<userInfo/>
</attribute>
<attribute name="int32AsStringTestAttribute" optional="YES" attributeType="Integer 32" defaultValueString="0">
<userInfo/>
</attribute>
<attribute name="int32TestAttribute" optional="YES" attributeType="Integer 32" defaultValueString="0">
<userInfo/>
</attribute>
<attribute name="int64AsStringTestAttribute" optional="YES" attributeType="Integer 64" defaultValueString="0">
<userInfo/>
</attribute>
<attribute name="int64TestAttribute" optional="YES" attributeType="Integer 64" defaultValueString="0">
<userInfo/>
</attribute>
Expand Down Expand Up @@ -167,7 +185,7 @@
<element name="SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey" positionX="160" positionY="192" width="128" height="60"/>
<element name="SingleEntityRelatedToMappedEntityWithNestedMappedAttributes" positionX="160" positionY="192" width="128" height="60"/>
<element name="SingleEntityRelatedToMappedEntityWithSecondaryMappings" positionX="160" positionY="192" width="128" height="75"/>
<element name="SingleEntityWithNoRelationships" positionX="160" positionY="192" width="128" height="255"/>
<element name="SingleEntityWithNoRelationships" positionX="160" positionY="192" width="128" height="345"/>
<element name="SingleRelatedEntity" positionX="160" positionY="192" width="128" height="120"/>
</elements>
</model>
Expand Up @@ -11,5 +11,12 @@
"colorTestAttribute": "rgba(64,128,225,1)",
"mappedAttributeWithStringValue": "Mapped value",
"dateWithCustomFormat": "8/5/2011 1-56-04 AM",
"nullTestAttribute": null
"nullTestAttribute": null,
"int64AsStringTestAttribute": "42",
"int32AsStringTestAttribute": "32",
"int16AsStringTestAttribute": "256",
"decimalAsStringTestAttribute": "1.2",
"doubleAsStringTestAttribute": "124.3",
"floatAsStringTestAttribute": "10000000000",

}

0 comments on commit 435da59

Please sign in to comment.