mirror of
https://github.com/zhigang1992/MagicalRecord.git
synced 2026-01-12 22:48:38 +08:00
Merge branch 'feature/experiemental' of github.com:magicalpanda/MagicalRecord into feature/experiemental
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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];
|
||||
// See https://gist.github.com/4501089 and https://alpha.app.net/tonymillion/post/2397422
|
||||
|
||||
if ([context obtainPermanentIDsForObjects:[NSArray arrayWithObject:dataObject] error:nil])
|
||||
NSMutableArray *objects = [NSMutableArray array];
|
||||
|
||||
[listOfObjectData enumerateObjectsWithOptions:0
|
||||
usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
|
||||
{
|
||||
[objectIDs addObject:[dataObject objectID]];
|
||||
NSDictionary * dict = obj;
|
||||
|
||||
if([dict isKindOfClass:[NSDictionary class]])
|
||||
{
|
||||
NSManagedObject *importedObject = [self MR_importFromObject:dict
|
||||
inContext:context];
|
||||
[objects addObject:importedObject];
|
||||
}
|
||||
}];
|
||||
}];
|
||||
|
||||
return [self MR_findAllWithPredicate:[NSPredicate predicateWithFormat:@"self IN %@", objectIDs] inContext:context];
|
||||
return objects;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user