Merge branch 'feature/experiemental' of github.com:magicalpanda/MagicalRecord into feature/experiemental

This commit is contained in:
Saul Mora
2013-01-24 17:29:42 -07:00
2 changed files with 49 additions and 18 deletions

View File

@@ -36,8 +36,19 @@
{
if (![value isKindOfClass:[NSDate class]])
{
NSString *dateFormat = [[self userInfo] valueForKey:kMagicalRecordImportCustomDateFormatKey];
value = dateFromString([value description], dateFormat ?: kMagicalRecordImportDefaultDateFormatString);
NSDate *convertedValue = nil;
NSString *dateFormat;
NSUInteger index = 0;
do {
NSMutableString *dateFormatKey = [kMagicalRecordImportCustomDateFormatKey mutableCopy];
if (index) {
[dateFormatKey appendFormat:@".%d", index];
}
index++;
dateFormat = [[self userInfo] valueForKey:dateFormatKey];
convertedValue = dateFromString([value description], dateFormat ?: kMagicalRecordImportDefaultDateFormatString);
} while (!convertedValue && dateFormat);
value = convertedValue;
}
// value = adjustDateForDST(value);
}

View File

@@ -259,24 +259,44 @@ NSString * const kMagicalRecordImportAttributeUseDefaultValueWhenNotPresent = @"
+ (NSArray *) MR_importFromArray:(NSArray *)listOfObjectData inContext:(NSManagedObjectContext *)context
{
NSMutableArray *objectIDs = [NSMutableArray array];
// NSMutableArray *objectIDs = [NSMutableArray array];
//
// [MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext)
// {
// [listOfObjectData enumerateObjectsWithOptions:0 usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
// {
// NSDictionary *objectData = (NSDictionary *)obj;
//
// NSManagedObject *dataObject = [self MR_importFromObject:objectData inContext:localContext];
//
// if ([context obtainPermanentIDsForObjects:[NSArray arrayWithObject:dataObject] error:nil])
// {
// [objectIDs addObject:[dataObject objectID]];
// }
// }];
// }];
//
// return [self MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"self IN %@", objectIDs] inContext:context];
[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext)
{
[listOfObjectData enumerateObjectsWithOptions:0 usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
NSDictionary *objectData = (NSDictionary *)obj;
NSManagedObject *dataObject = [self MR_importFromObject:objectData inContext:localContext];
if ([context obtainPermanentIDsForObjects:[NSArray arrayWithObject:dataObject] error:nil])
{
[objectIDs addObject:[dataObject objectID]];
}
}];
}];
return [self MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"self IN %@", objectIDs] inContext:context];
// See https://gist.github.com/4501089 and https://alpha.app.net/tonymillion/post/2397422
NSMutableArray *objects = [NSMutableArray array];
[listOfObjectData enumerateObjectsWithOptions:0
usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
{
NSDictionary * dict = obj;
if([dict isKindOfClass:[NSDictionary class]])
{
NSManagedObject *importedObject = [self MR_importFromObject:dict
inContext:context];
[objects addObject:importedObject];
}
}];
return objects;
}
@end