Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Renamed method argument class to aClass as class is a reserved keywor… #24

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions MTLManagedObjectAdapter.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Pod::Spec.new do |s|
s.name = "MTLManagedObjectAdapter"
s.version = "1.0.5"
s.license = "MIT"
s.summary = "Model framework for Cocoa and Cocoa Touch."
s.homepage = "https://github.com/Mantle/Mantle"
s.authors = { "GitHub" => "[email protected]" }
s.source = { :git => "https://github.com/peroper/MTLManagedObjectAdapter.git", :tag => s.version }
s.requires_arc = true
s.platforms = {
:ios => "5.0",
:osx => "10.7",
:watchos => "2.0",
:tvos => "9.0"
}
s.source_files = "MTLManagedObjectAdapter"
s.dependency "Mantle/extobjc", "~> 2.1.6"
s.frameworks = "Foundation", "CoreData"
end
30 changes: 1 addition & 29 deletions MTLManagedObjectAdapter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
5470B5241985122200E4D941 /* MTLManagedObjectAdapter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5470B5071985122200E4D941 /* MTLManagedObjectAdapter.framework */; };
5470B52C1985122300E4D941 /* MTLManagedObjectAdapterSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 5470B52B1985122300E4D941 /* MTLManagedObjectAdapterSpec.m */; };
5470B583198512AE00E4D941 /* MTLManagedObjectAdapter.h in Headers */ = {isa = PBXBuildFile; fileRef = 5470B5171985122200E4D941 /* MTLManagedObjectAdapter.h */; settings = {ATTRIBUTES = (Public, ); }; };
5470B5C819851F3900E4D941 /* EXTRuntimeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5470B5C219851F3900E4D941 /* EXTRuntimeExtensions.m */; };
5470B5CC19851F3900E4D941 /* EXTScope.m in Sources */ = {isa = PBXBuildFile; fileRef = 5470B5C419851F3900E4D941 /* EXTScope.m */; };
5470B5D51985208C00E4D941 /* MTLCoreDataObjects.m in Sources */ = {isa = PBXBuildFile; fileRef = 5470B5D21985208C00E4D941 /* MTLCoreDataObjects.m */; };
5470B5D71985208C00E4D941 /* MTLCoreDataTestModels.m in Sources */ = {isa = PBXBuildFile; fileRef = 5470B5D41985208C00E4D941 /* MTLCoreDataTestModels.m */; };
5470B5DB1985209E00E4D941 /* TestModel.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 5470B5D91985209E00E4D941 /* TestModel.xcdatamodeld */; };
Expand All @@ -29,8 +27,6 @@
D0EB705C1AB747F000BBB455 /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0EB70591AB747E300BBB455 /* CoreData.framework */; };
D0EB705E1AB7487D00BBB455 /* Mantle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0EB705D1AB7487D00BBB455 /* Mantle.framework */; };
D0EB705F1AB748C900BBB455 /* Mantle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0EB705D1AB7487D00BBB455 /* Mantle.framework */; };
D0EB70601AB748E700BBB455 /* EXTRuntimeExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5470B5C219851F3900E4D941 /* EXTRuntimeExtensions.m */; };
D0EB70611AB748E700BBB455 /* EXTScope.m in Sources */ = {isa = PBXBuildFile; fileRef = 5470B5C419851F3900E4D941 /* EXTScope.m */; };
D0EB70651AB74A0A00BBB455 /* Quick.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0EB70631AB74A0A00BBB455 /* Quick.framework */; };
D0EB70671AB74A2200BBB455 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0EB70661AB74A2200BBB455 /* Nimble.framework */; };
D0EB70681AB74A2200BBB455 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0EB70661AB74A2200BBB455 /* Nimble.framework */; };
Expand Down Expand Up @@ -84,12 +80,6 @@
5470B599198514F700E4D941 /* Mac-Framework.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Mac-Framework.xcconfig"; sourceTree = "<group>"; };
5470B59A198514F700E4D941 /* Mac-StaticLibrary.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Mac-StaticLibrary.xcconfig"; sourceTree = "<group>"; };
5470B59B198514F700E4D941 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = text; path = README.md; sourceTree = "<group>"; };
5470B5C019851F3900E4D941 /* EXTKeyPathCoding.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EXTKeyPathCoding.h; sourceTree = "<group>"; };
5470B5C119851F3900E4D941 /* EXTRuntimeExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EXTRuntimeExtensions.h; sourceTree = "<group>"; };
5470B5C219851F3900E4D941 /* EXTRuntimeExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EXTRuntimeExtensions.m; sourceTree = "<group>"; };
5470B5C319851F3900E4D941 /* EXTScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EXTScope.h; sourceTree = "<group>"; };
5470B5C419851F3900E4D941 /* EXTScope.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EXTScope.m; sourceTree = "<group>"; };
5470B5C519851F3900E4D941 /* metamacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = metamacros.h; sourceTree = "<group>"; };
5470B5D11985208C00E4D941 /* MTLCoreDataObjects.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTLCoreDataObjects.h; sourceTree = "<group>"; };
5470B5D21985208C00E4D941 /* MTLCoreDataObjects.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MTLCoreDataObjects.m; sourceTree = "<group>"; };
5470B5D31985208C00E4D941 /* MTLCoreDataTestModels.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MTLCoreDataTestModels.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,7 +202,6 @@
5470B5111985122200E4D941 /* Supporting Files */ = {
isa = PBXGroup;
children = (
5470B5BF19851F3900E4D941 /* libextobjc */,
D0EB70581AB747C300BBB455 /* Info.plist */,
);
name = "Supporting Files";
Expand Down Expand Up @@ -306,20 +295,6 @@
path = "Mac OS X";
sourceTree = "<group>";
};
5470B5BF19851F3900E4D941 /* libextobjc */ = {
isa = PBXGroup;
children = (
5470B5C019851F3900E4D941 /* EXTKeyPathCoding.h */,
5470B5C119851F3900E4D941 /* EXTRuntimeExtensions.h */,
5470B5C219851F3900E4D941 /* EXTRuntimeExtensions.m */,
5470B5C319851F3900E4D941 /* EXTScope.h */,
5470B5C419851F3900E4D941 /* EXTScope.m */,
5470B5C519851F3900E4D941 /* metamacros.h */,
);
name = libextobjc;
path = extobjc;
sourceTree = "<group>";
};
5470B5D01985202F00E4D941 /* Specs */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -447,6 +422,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 5470B4FD1985122200E4D941;
Expand Down Expand Up @@ -498,8 +474,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
5470B5CC19851F3900E4D941 /* EXTScope.m in Sources */,
5470B5C819851F3900E4D941 /* EXTRuntimeExtensions.m in Sources */,
5470B5191985122200E4D941 /* MTLManagedObjectAdapter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -520,8 +494,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D0EB70611AB748E700BBB455 /* EXTScope.m in Sources */,
D0EB70601AB748E700BBB455 /* EXTRuntimeExtensions.m in Sources */,
D0EB70531AB7479700BBB455 /* MTLManagedObjectAdapter.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
2 changes: 1 addition & 1 deletion MTLManagedObjectAdapter/MTLManagedObjectAdapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ extern const NSInteger MTLManagedObjectAdapterErrorInvalidManagedObjectMapping;
// nil.
//
// Returns a value transformer or nil if no transformation should be used.
+ (NSValueTransformer *)transformerForModelPropertiesOfClass:(Class)class;
+ (NSValueTransformer *)transformerForModelPropertiesOfClass:(Class)aClass;

// A value transformer that should be used for a properties of the given
// primitive type.
Expand Down
63 changes: 32 additions & 31 deletions MTLManagedObjectAdapter/MTLManagedObjectAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#import <Mantle/Mantle.h>

#import "EXTScope.h"
#import "EXTRuntimeExtensions.h"
#import <Mantle/MTLEXTScope.h>
#import <Mantle/MTLEXTRuntimeExtensions.h>

#import "MTLManagedObjectAdapter.h"

Expand Down Expand Up @@ -75,7 +75,7 @@ @interface MTLManagedObjectAdapter ()
//
// Returns a dictionary with the properties of modelClass that need
// transformation as keys and the value transformers as values.
- (NSDictionary *)valueTransformersForModelClass:(Class)class;
- (NSDictionary *)valueTransformersForModelClass:(Class)aClass;

// Initializes the receiver to serialize or deserialize a MTLModel of the given
// class.
Expand Down Expand Up @@ -166,12 +166,14 @@ - (id)modelFromManagedObject:(NSManagedObject *)managedObject processedObjects:(
// any cycles when processing its relationships.
CFDictionaryAddValue(processedObjects, (__bridge void *)managedObject, (__bridge void *)model);

__block NSError *tmpError;

BOOL (^setValueForKey)(NSString *, id) = ^(NSString *key, id value) {
// Mark this as being autoreleased, because validateValue may return
// a new object to be stored in this variable (and we don't want ARC to
// double-free or leak the old or new values).
__autoreleasing id replaceableValue = value;
if (![model validateValue:&replaceableValue forKey:key error:error]) return NO;
if (![model validateValue:&replaceableValue forKey:key error:&tmpError]) return NO;

[model setValue:replaceableValue forKey:key];
return YES;
Expand All @@ -191,7 +193,7 @@ - (id)modelFromManagedObject:(NSManagedObject *)managedObject processedObjects:(
id<MTLTransformerErrorHandling> errorHandlingTransformer = (id)transformer;

BOOL success = YES;
value = [errorHandlingTransformer transformedValue:value success:&success error:error];
value = [errorHandlingTransformer transformedValue:value success:&success error:&tmpError];

if (!success) return NO;
} else if (transformer != nil) {
Expand All @@ -213,7 +215,7 @@ - (id)modelFromManagedObject:(NSManagedObject *)managedObject processedObjects:(
NSMutableArray *models = [NSMutableArray arrayWithCapacity:[relationshipCollection count]];

for (NSManagedObject *nestedObject in relationshipCollection) {
id<MTLManagedObjectSerializing> model = [self.class modelOfClass:nestedClass fromManagedObject:nestedObject processedObjects:processedObjects error:error];
id<MTLManagedObjectSerializing> model = [self.class modelOfClass:nestedClass fromManagedObject:nestedObject processedObjects:processedObjects error:&tmpError];
if (model == nil) return nil;

[models addObject:model];
Expand All @@ -233,7 +235,7 @@ - (id)modelFromManagedObject:(NSManagedObject *)managedObject processedObjects:(

if (nestedObject == nil) return YES;

id<MTLManagedObjectSerializing> model = [self.class modelOfClass:nestedClass fromManagedObject:nestedObject processedObjects:processedObjects error:error];
id<MTLManagedObjectSerializing> model = [self.class modelOfClass:nestedClass fromManagedObject:nestedObject processedObjects:processedObjects error:&tmpError];
if (model == nil) return NO;

return setValueForKey(propertyKey, model);
Expand All @@ -242,17 +244,14 @@ - (id)modelFromManagedObject:(NSManagedObject *)managedObject processedObjects:(

BOOL (^deserializeProperty)(NSPropertyDescription *) = ^(NSPropertyDescription *propertyDescription) {
if (propertyDescription == nil) {
if (error != NULL) {
NSString *failureReason = [NSString stringWithFormat:NSLocalizedString(@"No property by name \"%@\" exists on the entity.", @""), managedObjectKey];

NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: NSLocalizedString(@"Could not deserialize managed object", @""),
NSLocalizedFailureReasonErrorKey: failureReason,
};
NSString *failureReason = [NSString stringWithFormat:NSLocalizedString(@"No property by name \"%@\" exists on the entity.", @""), managedObjectKey];

*error = [NSError errorWithDomain:MTLManagedObjectAdapterErrorDomain code:MTLManagedObjectAdapterErrorInvalidManagedObjectKey userInfo:userInfo];
}
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: NSLocalizedString(@"Could not deserialize managed object", @""),
NSLocalizedFailureReasonErrorKey: failureReason,
};

tmpError = [NSError errorWithDomain:MTLManagedObjectAdapterErrorDomain code:MTLManagedObjectAdapterErrorInvalidManagedObjectKey userInfo:userInfo];
return NO;
}

Expand All @@ -263,22 +262,24 @@ - (id)modelFromManagedObject:(NSManagedObject *)managedObject processedObjects:(
} else if ([propertyClassName isEqual:@"NSRelationshipDescription"]) {
return deserializeRelationship((id)propertyDescription);
} else {
if (error != NULL) {
NSString *failureReason = [NSString stringWithFormat:NSLocalizedString(@"Property descriptions of class %@ are unsupported.", @""), propertyClassName];

NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: NSLocalizedString(@"Could not deserialize managed object", @""),
NSLocalizedFailureReasonErrorKey: failureReason,
};
NSString *failureReason = [NSString stringWithFormat:NSLocalizedString(@"Property descriptions of class %@ are unsupported.", @""), propertyClassName];

*error = [NSError errorWithDomain:MTLManagedObjectAdapterErrorDomain code:MTLManagedObjectAdapterErrorUnsupportedManagedObjectPropertyType userInfo:userInfo];
}
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey: NSLocalizedString(@"Could not deserialize managed object", @""),
NSLocalizedFailureReasonErrorKey: failureReason,
};

tmpError = [NSError errorWithDomain:MTLManagedObjectAdapterErrorDomain code:MTLManagedObjectAdapterErrorUnsupportedManagedObjectPropertyType userInfo:userInfo];
return NO;
}
};

if (!deserializeProperty(managedObjectProperties[managedObjectKey])) return nil;
if (!deserializeProperty(managedObjectProperties[managedObjectKey])) {
if (tmpError && error) {
*error = tmpError;
}
return nil;
}
}

return model;
Expand Down Expand Up @@ -452,7 +453,7 @@ - (id)managedObjectFromModel:(id<MTLManagedObjectSerializing>)model insertingInt
id<MTLTransformerErrorHandling> errorHandlingTransformer = (id)transformer;

BOOL success = YES;
transformedValue = [errorHandlingTransformer reverseTransformedValue:value success:&success error:error];
transformedValue = [errorHandlingTransformer reverseTransformedValue:value success:&success error:&tmpError];

if (!success) return NO;
} else {
Expand Down Expand Up @@ -740,7 +741,7 @@ - (NSDictionary *)valueTransformersForModelClass:(Class)modelClass {

if (property == NULL) continue;

mtl_moa_propertyAttributes *attributes = mtl_moa_copyPropertyAttributes(property);
mtl_propertyAttributes *attributes = mtl_copyPropertyAttributes(property);
@onExit {
free(attributes);
};
Expand All @@ -761,10 +762,10 @@ - (NSDictionary *)valueTransformersForModelClass:(Class)modelClass {
return result;
}

+ (NSValueTransformer *)transformerForModelPropertiesOfClass:(Class)class {
NSParameterAssert(class != nil);
+ (NSValueTransformer *)transformerForModelPropertiesOfClass:(Class)aClass {
NSParameterAssert(aClass != nil);

SEL selector = MTLSelectorWithKeyPattern(NSStringFromClass(class), "EntityAttributeTransformer");
SEL selector = MTLSelectorWithKeyPattern(NSStringFromClass(aClass), "EntityAttributeTransformer");
if (![self respondsToSelector:selector]) return nil;

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:selector]];
Expand Down
68 changes: 0 additions & 68 deletions MTLManagedObjectAdapter/extobjc/EXTKeyPathCoding.h

This file was deleted.

Loading