mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-01 22:42:51 +08:00
Convert RKConnectionMapping into a subclass of RKPropertyMapping. Add delegate callback for tracking the connection of relationships.
This commit is contained in:
@@ -21,12 +21,11 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <CoreData/CoreData.h>
|
||||
#import "RKMapping.h"
|
||||
#import "RKPropertyMapping.h"
|
||||
|
||||
@class RKConnectionMapping, RKDynamicMappingMatcher;
|
||||
@protocol RKManagedObjectCaching;
|
||||
|
||||
typedef id (^RKObjectConnectionBlock)(RKConnectionMapping *mapping, id source);
|
||||
|
||||
// Defines the rules for connecting relationsips
|
||||
/**
|
||||
Instructs RestKit to connect a relationship of the object being mapped to the
|
||||
@@ -93,11 +92,10 @@ typedef id (^RKObjectConnectionBlock)(RKConnectionMapping *mapping, id source);
|
||||
@see connectRelationship:withObjectForPrimaryKeyAttribute:
|
||||
*/
|
||||
|
||||
@interface RKConnectionMapping : NSObject
|
||||
@interface RKConnectionMapping : RKPropertyMapping
|
||||
|
||||
@property (nonatomic, strong, readonly) NSRelationshipDescription *relationship;
|
||||
@property (nonatomic, strong, readonly) NSString *sourceKeyPath;
|
||||
@property (nonatomic, strong, readonly) NSString *destinationKeyPath;
|
||||
|
||||
@property (nonatomic, strong, readonly) RKDynamicMappingMatcher *matcher; // Can be nil
|
||||
|
||||
// Returns YES if the receiver describes a connection between entities that is established
|
||||
|
||||
@@ -41,31 +41,6 @@
|
||||
|
||||
@implementation RKConnectionMapping
|
||||
|
||||
//+ (RKConnectionMapping *)connectionMappingForRelationship:(NSString *)relationshipName fromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(RKMapping *)objectOrDynamicMapping
|
||||
//{
|
||||
// RKConnectionMapping *mapping = [[self alloc] initWithRelationshipName:relationshipName sourceKeyPath:sourceKeyPath destinationKeyPath:destinationKeyPath mapping:objectOrDynamicMapping matcher:nil];
|
||||
// return mapping;
|
||||
//}
|
||||
//
|
||||
//+ (RKConnectionMapping*)connectionMappingForRelationship:(NSString *)relationshipName fromKeyPath:(NSString *)sourceKeyPath toKeyPath:(NSString *)destinationKeyPath withMapping:(RKMapping *)objectOrDynamicMapping matcher:(RKDynamicMappingMatcher *)matcher
|
||||
//{
|
||||
// RKConnectionMapping *mapping = [[self alloc] initWithRelationshipName:relationshipName sourceKeyPath:sourceKeyPath destinationKeyPath:destinationKeyPath mapping:objectOrDynamicMapping matcher:matcher];
|
||||
// return mapping;
|
||||
//}
|
||||
//
|
||||
//- (id)initWithRelationshipName:(NSString *)relationshipName sourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath mapping:(RKMapping *)objectOrDynamicMapping matcher:(RKDynamicMappingMatcher *)matcher
|
||||
//{
|
||||
// self = [super init];
|
||||
// if (self) {
|
||||
// self.relationshipName = relationshipName;
|
||||
// self.sourceKeyPath = sourceKeyPath;
|
||||
// self.destinationKeyPath = destinationKeyPath;
|
||||
// self.mapping = objectOrDynamicMapping;
|
||||
// self.matcher = matcher;
|
||||
// }
|
||||
// return self;
|
||||
//}
|
||||
|
||||
- (Class)connectionMappingClassForRelationship:(NSRelationshipDescription *)relationship sourceKeyPath:(NSString *)sourceKeyPath destinationKeyPath:(NSString *)destinationKeyPath
|
||||
{
|
||||
NSEntityDescription *sourceEntity = relationship.entity;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#import "RKObjectMapping.h"
|
||||
#import "RKAttributeMapping.h"
|
||||
|
||||
@class RKMappingOperation, RKDynamicMapping;
|
||||
@class RKMappingOperation, RKDynamicMapping, RKConnectionMapping;
|
||||
@protocol RKMappingOperationDataSource;
|
||||
|
||||
/**
|
||||
@@ -88,6 +88,21 @@
|
||||
*/
|
||||
- (void)mappingOperation:(RKMappingOperation *)operation didSelectObjectMapping:(RKObjectMapping *)objectMapping forDynamicMapping:(RKDynamicMapping *)dynamicMapping;
|
||||
|
||||
#ifdef _COREDATADEFINES_H
|
||||
|
||||
/**
|
||||
Tells the delegate that the mapping operation has connected a relationship.
|
||||
|
||||
Only sent when mapping an `RKEntityMapping` object that contains connection mappings.
|
||||
|
||||
@param operation The mapping operation.
|
||||
@param relationship The relationship that was connected.
|
||||
@param connectionMapping The mappings that was used to connect the relationship.
|
||||
*/
|
||||
- (void)mappingOperation:(RKMappingOperation *)operation didConnectRelationship:(NSRelationshipDescription *)relationship usingMapping:(RKConnectionMapping *)connectionMapping;
|
||||
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user