Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

dateFormat.1 + patch for importFromArray #394

Merged
merged 2 commits into from

3 participants

@stuffmc

Please check the first commit refering the post on alpha.

The second one is a pretty cool failover and if you're so kind to accept it please update the post on cimgf.com ;)

@casademora casademora merged commit 44282ad into magicalpanda:feature/experiemental
@tonyarnold
Owner

NEEDS MOAR TESTS :trollface:

@tonyarnold
Owner

Also needs less commented out code, but that's not trolling :thumbsup:

@casademora
Owner
@casademora
Owner
@stuffmc

Gosh... be65087 was more "in dev" thought, I wasn't meaning to push that commented out thing. Will push the version without comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 15, 2013
  1. @stuffmc
Commits on Jan 23, 2013
  1. @stuffmc
This page is out of date. Refresh to see the latest.
View
15 MagicalRecord/Categories/DataImport/NSAttributeDescription+MagicalDataImport.m
@@ -36,8 +36,19 @@ - (id) MR_valueForKeyPath:(NSString *)keyPath fromObjectData:(id)objectData;
{
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
52 MagicalRecord/Categories/NSManagedObject/NSManagedObject+MagicalDataImport.m
@@ -259,24 +259,44 @@ + (NSArray *) MR_importFromArray:(NSArray *)listOfObjectData
+ (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
Something went wrong with that request. Please try again.