Permalink
Browse files

Merge branch 'master' of https://github.com/magicalpanda/MagicalRecord

Conflicts:
	Source/Categories/NSManagedObject+MagicalDataImport.m
  • Loading branch information...
2 parents fa4a287 + 6b4ef06 commit 49e51b7fbe8a4f1100f99cd1c464871a9117efc4 @duanefields duanefields committed Dec 18, 2011
Showing with 485 additions and 107 deletions.
  1. +15 −6 Magical Record.xcodeproj/project.pbxproj
  2. +15 −0 Source/Categories/DataImport/NSString+MagicalDataImport.h
  3. +21 −0 Source/Categories/DataImport/NSString+MagicalDataImport.m
  4. +4 −1 Source/Categories/NSManagedObject+MagicalDataImport.h
  5. +34 −16 Source/Categories/NSManagedObject+MagicalDataImport.m
  6. +4 −9 Source/Categories/NSManagedObject+MagicalRecord.m
  7. +39 −12 Source/Categories/NSManagedObjectContext+MagicalRecord.m
  8. +1 −1 Source/Categories/NSPersistentStoreCoordinator+MagicalRecord.m
  9. +11 −2 Source/CoreData+MagicalRecord.h
  10. +0 −1 Source/MRCoreDataAction.m
  11. +2 −1 Source/MagicalRecordShorthand.h
  12. +12 −10 Unit Tests/Fixtures/FixtureHelpers.m
  13. +11 −1 Unit Tests/Fixtures/iOS/TestEntities/_AbstractRelatedEntity.h
  14. +10 −0 Unit Tests/Fixtures/iOS/TestEntities/_AbstractRelatedEntity.m
  15. +11 −1 Unit Tests/Fixtures/iOS/TestEntities/_ConcreteRelatedEntity.h
  16. +10 −0 Unit Tests/Fixtures/iOS/TestEntities/_ConcreteRelatedEntity.m
  17. +9 −0 Unit Tests/Fixtures/iOS/TestEntities/_DifferentClassNameMapping.h
  18. +9 −0 Unit Tests/Fixtures/iOS/TestEntities/_DifferentClassNameMapping.m
  19. +17 −4 Unit Tests/Fixtures/iOS/TestEntities/_MappedEntity.h
  20. +13 −0 Unit Tests/Fixtures/iOS/TestEntities/_MappedEntity.m
  21. +13 −2 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.h
  22. +11 −0 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToManyMappedEntitiesUsingMappedPrimaryKey.m
  23. +13 −2 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityUsingDefaults.h
  24. +11 −0 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityUsingDefaults.m
  25. +11 −1 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.h
  26. +10 −0 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityUsingMappedPrimaryKey.m
  27. +11 −1 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.h
  28. +10 −0 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityWithNestedMappedAttributes.m
  29. +13 −2 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityWithSecondaryMappings.h
  30. +11 −0 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityRelatedToMappedEntityWithSecondaryMappings.m
  31. +37 −14 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityWithNoRelationships.h
  32. +23 −0 Unit Tests/Fixtures/iOS/TestEntities/_SingleEntityWithNoRelationships.m
  33. +19 −5 Unit Tests/Fixtures/iOS/TestEntities/_SingleRelatedEntity.h
  34. +14 −0 Unit Tests/Fixtures/iOS/TestEntities/_SingleRelatedEntity.m
  35. +11 −11 Unit Tests/ImportSingleRelatedEntityTests.m
  36. +1 −0 Unit Tests/MagicalDataImportTestCase.m
  37. +2 −3 Unit Tests/MagicalRecordHelperTests.m
  38. +16 −1 Unit Tests/NSManagedObjectContextHelperTests.m
@@ -47,6 +47,8 @@
C738127B141039900054EEF0 /* SingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeys.json in Resources */ = {isa = PBXBuildFile; fileRef = C7381275141037E80054EEF0 /* SingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeys.json */; };
C753897413DB61CE002B2F57 /* GHUnitTestMain.m in Sources */ = {isa = PBXBuildFile; fileRef = C753897313DB61CE002B2F57 /* GHUnitTestMain.m */; };
C753897613DB6322002B2F57 /* GHUnit.framework in Copy GHUnit into App Bundle */ = {isa = PBXBuildFile; fileRef = C721C84113D0C6460097AB6F /* GHUnit.framework */; };
+ C758AFD51493C6DC0051E570 /* NSString+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C758AFD41493C6DC0051E570 /* NSString+MagicalDataImport.m */; };
+ C758AFD61493C6DC0051E570 /* NSString+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C758AFD41493C6DC0051E570 /* NSString+MagicalDataImport.m */; };
C75A4E7313D0D88D00790CEB /* NSManagedObject+MagicalDataImport.m in Sources */ = {isa = PBXBuildFile; fileRef = C75A4E7213D0D88D00790CEB /* NSManagedObject+MagicalDataImport.m */; };
C75C7D6A147220D400D0C2FE /* generateShorthandFile.rb in Resources */ = {isa = PBXBuildFile; fileRef = C75C7D69147220D300D0C2FE /* generateShorthandFile.rb */; };
C75C7D6B147220D400D0C2FE /* generateShorthandFile.rb in Resources */ = {isa = PBXBuildFile; fileRef = C75C7D69147220D300D0C2FE /* generateShorthandFile.rb */; };
@@ -246,6 +248,8 @@
C7381275141037E80054EEF0 /* SingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeys.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = SingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeys.json; path = "Unit Tests/Fixtures/SingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeys.json"; sourceTree = "<group>"; };
C73812781410383B0054EEF0 /* ImportSingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeysTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ImportSingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeysTests.m; path = "Unit Tests/Fixtures/ImportSingleEntityRelatedToManyMappedEntitiesUsingListOfPrimaryKeysTests.m"; sourceTree = "<group>"; };
C753897313DB61CE002B2F57 /* GHUnitTestMain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHUnitTestMain.m; sourceTree = "<group>"; };
+ C758AFD31493C6DC0051E570 /* NSString+MagicalDataImport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSString+MagicalDataImport.h"; path = "DataImport/NSString+MagicalDataImport.h"; sourceTree = "<group>"; };
+ C758AFD41493C6DC0051E570 /* NSString+MagicalDataImport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSString+MagicalDataImport.m"; path = "DataImport/NSString+MagicalDataImport.m"; sourceTree = "<group>"; };
C75A4E7113D0D88D00790CEB /* NSManagedObject+MagicalDataImport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSManagedObject+MagicalDataImport.h"; sourceTree = "<group>"; };
C75A4E7213D0D88D00790CEB /* NSManagedObject+MagicalDataImport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSManagedObject+MagicalDataImport.m"; sourceTree = "<group>"; };
C75C7D69147220D300D0C2FE /* generateShorthandFile.rb */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.ruby; path = generateShorthandFile.rb; sourceTree = "<group>"; };
@@ -382,6 +386,8 @@
children = (
C7F5EEB0148DC76700964607 /* NSObject+MagicalDataImport.h */,
C7F5EEB1148DC76700964607 /* NSObject+MagicalDataImport.m */,
+ C758AFD31493C6DC0051E570 /* NSString+MagicalDataImport.h */,
+ C758AFD41493C6DC0051E570 /* NSString+MagicalDataImport.m */,
C75A4E7113D0D88D00790CEB /* NSManagedObject+MagicalDataImport.h */,
C75A4E7213D0D88D00790CEB /* NSManagedObject+MagicalDataImport.m */,
C7005F1014140F9B0061B9F4 /* NSNumber+MagicalDataImport.h */,
@@ -924,7 +930,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
- shellScript = "cd \"Unit Tests/Fixtures/iOS\" && mogenerator -m TestModel.xcdatamodeld/TestModel.xcdatamodel -O TestEntities";
+ shellScript = "cd \"Unit Tests/Fixtures/iOS\" && mogenerator -m TestModel.xcdatamodeld/TestModel.xcdatamodel -O TestEntities --template-var arc=true";
};
/* End PBXShellScriptBuildPhase section */
@@ -967,6 +973,7 @@
C7005F1A14140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m in Sources */,
C7005F2214153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m in Sources */,
C7F5EEB2148DC76700964607 /* NSObject+MagicalDataImport.m in Sources */,
+ C758AFD51493C6DC0051E570 /* NSString+MagicalDataImport.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1028,6 +1035,7 @@
C7005F1B14140FD30061B9F4 /* NSRelationshipDescription+MagicalDataImport.m in Sources */,
C7005F2314153A060061B9F4 /* NSEntityDescription+MagicalDataImport.m in Sources */,
C7F5EEB3148DC76700964607 /* NSObject+MagicalDataImport.m in Sources */,
+ C758AFD61493C6DC0051E570 /* NSString+MagicalDataImport.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1173,7 +1181,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- CLANG_ENABLE_OBJC_ARC = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
@@ -1188,11 +1196,12 @@
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "iOS App Unit Tests/iOS App Unit Tests-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
+ "MR_SHORTHAND=1",
"DEBUG=1",
"$(inherited)",
);
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
- GCC_VERSION = "";
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
@@ -1210,7 +1219,7 @@
);
MOMC_NO_INVERSE_RELATIONSHIP_WARNINGS = YES;
MOMC_NO_WARNINGS = YES;
- OTHER_CFLAGS = "-DMR_SHORTHAND";
+ OTHER_CFLAGS = "-DMR_ENABLE_LOGGING";
OTHER_LDFLAGS = (
"-all_load",
"-ObjC",
@@ -1230,7 +1239,7 @@
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
- CLANG_ENABLE_OBJC_ARC = NO;
+ CLANG_ENABLE_OBJC_ARC = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
FRAMEWORK_SEARCH_PATHS = (
@@ -1241,7 +1250,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "iOS App Unit Tests/iOS App Unit Tests-Prefix.pch";
- GCC_VERSION = "";
+ GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNKNOWN_PRAGMAS = YES;
@@ -0,0 +1,15 @@
+//
+// NSString+MagicalRecord_MagicalDataImport.h
+// Magical Record
+//
+// Created by Saul Mora on 12/10/11.
+// Copyright (c) 2011 Magical Panda Software LLC. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface NSString (MagicalRecord_DataImport)
+
+- (NSString *) MR_capitalizedFirstCharaterString;
+
+@end
@@ -0,0 +1,21 @@
+//
+// NSString+MagicalRecord_MagicalDataImport.m
+// Magical Record
+//
+// Created by Saul Mora on 12/10/11.
+// Copyright (c) 2011 Magical Panda Software LLC. All rights reserved.
+//
+
+#import "NSString+MagicalDataImport.h"
+
+
+@implementation NSString (MagicalRecord_DataImport)
+
+- (NSString *) MR_capitalizedFirstCharaterString;
+{
+ NSString *firstChar = [[self substringToIndex:1] capitalizedString];
+ return [firstChar stringByAppendingString:[self substringFromIndex:1]];
+}
+
+@end
+
@@ -17,7 +17,7 @@ extern NSString * const kMagicalRecordImportRelationshipMapKey;
extern NSString * const kMagicalRecordImportRelationshipPrimaryKey;
extern NSString * const kMagicalRecordImportRelationshipTypeKey;
-@interface NSManagedObject (NSManagedObject_DataImport)
+@interface NSManagedObject (MagicalRecord_DataImport)
- (void) MR_importValuesForKeysWithDictionary:(id)objectData;
- (void) MR_updateValuesForKeysWithDictionary:(id)objectData;
@@ -31,4 +31,7 @@ extern NSString * const kMagicalRecordImportRelationshipTypeKey;
+ (id) MR_updateFromDictionary:(id)objectData;
+ (id) MR_updateFromDictionary:(id)objectData inContext:(NSManagedObjectContext *)context;
++ (NSArray *) MR_updateFromArray:(NSArray *)listOfObjectData;
++ (NSArray *) MR_updateFromArray:(NSArray *)listOfObjectData inContext:(NSManagedObjectContext *)context;
+
@end
@@ -20,16 +20,6 @@
NSString * const kMagicalRecordImportRelationshipPrimaryKey = @"primaryRelationshipKey";
NSString * const kMagicalRecordImportRelationshipTypeKey = @"type";
-@implementation NSString (MagicalRecord_DataImport)
-
-- (NSString *) MR_capitalizedFirstCharaterString;
-{
- NSString *firstChar = [[self substringToIndex:1] capitalizedString];
- return [firstChar stringByAppendingString:[self substringFromIndex:1]];
-}
-
-@end
-
@implementation NSManagedObject (MagicalRecord_DataImport)
- (id) MR_valueForAttribute:(NSAttributeDescription *)attributeInfo fromObjectData:(NSDictionary *)objectData forKeyPath:(NSString *)keyPath
@@ -123,14 +113,14 @@ - (void) MR_addObject:(NSManagedObject *)relatedObject forRelationship:(NSRelati
if ([relationshipInfo isToMany])
{
addRelationMessageFormat = @"add%@Object:";
- if ([relationshipInfo isOrdered])
+ if ([relationshipInfo respondsToSelector:@selector(isOrdered)] && [relationshipInfo isOrdered])
{
//Need to get the ordered set
NSString *selectorName = [[relationshipInfo name] stringByAppendingString:@"Set"];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
relationshipSource = [self performSelector:NSSelectorFromString(selectorName)];
-#pragma clang diagnostic pop
+#pragma cland diagnostic pop
addRelationMessageFormat = @"addObject:";
}
}
@@ -182,7 +172,7 @@ - (void) MR_setRelationships:(NSDictionary *)relationships forKeysWithDictionary
{
for (id singleRelatedObjectData in relatedObjectData)
{
- if (implementsShouldImport && !(BOOL)[self performSelector:shouldImportSelector withObject:singleRelatedObjectData])
+ if (implementsShouldImport && ![[self performSelector:shouldImportSelector withObject:singleRelatedObjectData] boolValue])
{
continue;
}
@@ -320,13 +310,41 @@ + (NSArray *) MR_importFromArray:(NSArray *)listOfObjectData
+ (NSArray *) MR_importFromArray:(NSArray *)listOfObjectData inContext:(NSManagedObjectContext *)context
{
NSMutableArray *objectIDs = [NSMutableArray array];
+
+ [MRCoreDataAction saveDataWithBlock:^(NSManagedObjectContext *localContext)
+ {
+ [listOfObjectData enumerateObjectsWithOptions:0 usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
+ {
+ NSDictionary *objectData = (NSDictionary *)obj;
+
+ NSManagedObject *dataObject = [self MR_importFromDictionary: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];
+}
+
++ (NSArray *) MR_updateFromArray:(NSArray *)listOfObjectData;
+{
+ return [self MR_updateFromArray:listOfObjectData inContext:[NSManagedObjectContext MR_defaultContext]];
+}
+
++ (NSArray *) MR_updateFromArray:(NSArray *)listOfObjectData inContext:(NSManagedObjectContext *)context;
+{
+ NSMutableArray *objectIDs = [NSMutableArray array];
+
[MRCoreDataAction saveDataWithBlock:^(NSManagedObjectContext *localContext)
{
- [listOfObjectData enumerateObjectsWithOptions:0 usingBlock:^(id obj, NSUInteger idx, BOOL *stop)
- {
+ [listOfObjectData enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
+
NSDictionary *objectData = (NSDictionary *)obj;
- NSManagedObject *dataObject = [self MR_importFromDictionary:objectData inContext:localContext];
+ NSManagedObject *dataObject = [self MR_updateFromDictionary:objectData inContext:localContext];
if ([context obtainPermanentIDsForObjects:[NSArray arrayWithObject:dataObject] error:nil])
{
@@ -283,10 +283,8 @@ + (NSFetchRequest *) MR_requestFirstByAttribute:(NSString *)attribute withValue:
+ (NSFetchRequest *) MR_requestFirstByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context;
{
- NSFetchRequest *request = [self MR_createFetchRequestInContext:context];
+ NSFetchRequest *request = [self MR_requestAllWhere:attribute isEqualTo:searchValue inContext:context];
[request setFetchLimit:1];
- [request setPropertiesToFetch:[NSArray arrayWithObject:attribute]];
- [request setPredicate:[NSPredicate predicateWithFormat:@"%K = %@", attribute, searchValue]];
return request;
}
@@ -535,7 +533,7 @@ + (id) MR_findFirst
+ (id) MR_findFirstByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context
{
NSFetchRequest *request = [self MR_requestFirstByAttribute:attribute withValue:searchValue inContext:context];
- [request setPropertiesToFetch:[NSArray arrayWithObject:attribute]];
+ // [request setPropertiesToFetch:[NSArray arrayWithObject:attribute]];
return [self MR_executeFetchRequestAndReturnFirstObject:request inContext:context];
}
@@ -613,9 +611,7 @@ + (id) MR_findFirstWithPredicate:(NSPredicate *)searchTerm sortedBy:(NSString *)
+ (NSArray *) MR_findByAttribute:(NSString *)attribute withValue:(id)searchValue inContext:(NSManagedObjectContext *)context
{
- NSFetchRequest *request = [self MR_createFetchRequestInContext:context];
-
- [request setPredicate:[NSPredicate predicateWithFormat:@"%K = %@", attribute, searchValue]];
+ NSFetchRequest *request = [self MR_requestAllWhere:attribute isEqualTo:searchValue inContext:context];
return [self MR_executeFetchRequest:request inContext:context];
}
@@ -680,7 +676,6 @@ + (BOOL) MR_deleteAllMatchingPredicate:(NSPredicate *)predicate inContext:(NSMan
{
NSFetchRequest *request = [self MR_requestAllWithPredicate:predicate inContext:context];
[request setReturnsObjectsAsFaults:YES];
- [request setIncludesSubentities:NO];
[request setIncludesPropertyValues:NO];
NSArray *objectsToTruncate = [self MR_executeFetchRequest:request inContext:context];
@@ -714,7 +709,7 @@ + (BOOL) MR_truncateAll
return YES;
}
-- (NSNumber *) maxValueFor:(NSString *)property
+- (NSNumber *) MR_maxValueFor:(NSString *)property
{
NSManagedObject *obj = [[self class] MR_findFirstByAttribute:property
withValue:[NSString stringWithFormat:@"max(%@)", property]];
Oops, something went wrong.

0 comments on commit 49e51b7

Please sign in to comment.