Skip to content

Loading…

Pull Request: Added MR_Safe_Set define option for additional (optional) attribute type checks. #244

Closed
wants to merge 1 commit into from

2 participants

@JRG-Developer

Added MR_Safe_Set define option. To use, #define MR_SAFE_Set 1. This add adds additional type checks prior to setting value for key.

@JRG-Developer JRG-Developer Added MR_Safe_Set define option. To use, #define MR_SAFE_Set 1. This …
…adds additional attribute type checks prior to setting value for key.
05e73ce
@blackgold9
Magical Panda Software member

Please add tests that verify this behavior

@blackgold9
Magical Panda Software member

Closing due to lack of response.

@blackgold9 blackgold9 closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 5, 2012
  1. @JRG-Developer

    Added MR_Safe_Set define option. To use, #define MR_SAFE_Set 1. This …

    JRG-Developer committed
    …adds additional attribute type checks prior to setting value for key.
Showing with 21 additions and 0 deletions.
  1. +21 −0 MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m
View
21 MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m
@@ -41,6 +41,27 @@ - (id) MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData;
}
value = adjustDateForDST(value);
}
+
+ #ifdef MR_SAFE_SET
+ else if (((attributeType == NSInteger16AttributeType) ||
+ (attributeType == NSInteger32AttributeType) ||
+ (attributeType == NSInteger64AttributeType) ||
+ (attributeType == NSBooleanAttributeType))
+ && ([value isKindOfClass:[NSString class]]))
+ {
+ value = [NSNumber numberWithInteger:[value integerValue]];
+ }
+ else if (((attributeType == NSFloatAttributeType) || (attributeType == NSDoubleAttributeType))
+ && ([value isKindOfClass:[NSString class]]))
+ {
+ value = [NSNumber numberWithDouble:[value doubleValue]];
+ }
+ else if ((attributeType == NSStringAttributeType) && ([value isKindOfClass:[NSNumber class]]))
+ {
+ value = [value stringValue];
+ }
+ #endif
+
}
return value == [NSNull null] ? nil : value;
Something went wrong with that request. Please try again.