Skip to content

Commit

Permalink
moving method to more appropriate category
Browse files Browse the repository at this point in the history
  • Loading branch information
casademora committed Mar 25, 2012
1 parent 94cf4b8 commit 9f35eee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
@interface NSAttributeDescription (MagicalRecord_DataImport)

- (NSString *) MR_primaryKey;
- (id) MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,32 @@ - (NSString *) MR_primaryKey;
return nil;
}

- (id) MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData;
{
id value = [objectData valueForKeyPath:keyPath];

NSAttributeType attributeType = [self attributeType];
NSString *desiredAttributeType = [[self userInfo] valueForKey:kMagicalRecordImportAttributeValueClassNameKey];
if (desiredAttributeType)
{
if ([desiredAttributeType hasSuffix:@"Color"])
{
value = colorFromString(value);
}
}
else
{
if (attributeType == NSDateAttributeType)
{
if (![value isKindOfClass:[NSDate class]])
{
NSString *dateFormat = [[self userInfo] valueForKey:kMagicalRecordImportCustomDateFormatKey];
value = dateFromString([value description], dateFormat ?: kMagicalRecordImportDefaultDateFormatString);
}
value = adjustDateForDST(value);
}
}

return value == [NSNull null] ? nil : value;
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,6 @@

@implementation NSManagedObject (MagicalRecord_DataImport)

- (id) MR_valueForAttribute:(NSAttributeDescription *)attributeInfo fromObjectData:(NSDictionary *)objectData forKeyPath:(NSString *)keyPath
{
id value = [objectData valueForKeyPath:keyPath];

NSAttributeType attributeType = [attributeInfo attributeType];
NSString *desiredAttributeType = [[attributeInfo userInfo] valueForKey:kMagicalRecordImportAttributeValueClassNameKey];
if (desiredAttributeType)
{
if ([desiredAttributeType hasSuffix:@"Color"])
{
value = colorFromString(value);
}
}
else
{
if (attributeType == NSDateAttributeType)
{
if (![value isKindOfClass:[NSDate class]])
{
NSString *dateFormat = [[attributeInfo userInfo] valueForKey:kMagicalRecordImportCustomDateFormatKey];
value = dateFromString([value description], dateFormat ?: kMagicalRecordImportDefaultDateFormatString);
}
value = adjustDateForDST(value);
}
}

return value == [NSNull null] ? nil : value;
}

- (BOOL) MR_importValue:(id)value forKey:(NSString *)key
{
NSString *selectorString = [NSString stringWithFormat:@"import%@:", [key MR_capitalizedFirstCharaterString]];
Expand All @@ -79,7 +50,7 @@ - (void) MR_setAttributes:(NSDictionary *)attributes forKeysWithDictionary:(id)o

if (lookupKeyPath)
{
id value = [self MR_valueForAttribute:attributeInfo fromObjectData:objectData forKeyPath:lookupKeyPath];
id value = [attributeInfo MR_valueForKeyPath:lookupKeyPath fromObjectData:objectData];
if (![self MR_importValue:value forKey:attributeName])
{
[self setValue:value forKey:attributeName];
Expand Down

0 comments on commit 9f35eee

Please sign in to comment.