我正在为 RESTFUL Web 服务使用 Restkit 框架。
我的 Resoucemanager 即 TaskManager 和 TaskDashboardCountManager 发生冲突。当我调用方法时
[[TaskDashboardCountManager sharedManager] loadTaskCount:^(NSDictionary *task) {}];
我得到了例外
'NSInvalidArgumentException',原因:'-[TaskDashboardCountManager loadTask:failure:]:
loadTask 是 TaskManager 的方法,但它是使用 TaskDashboardCountManger 调用的。我该如何解决?
**RKObjectManager.h**
@interface AKObjectManager : RKObjectManager
+ (instancetype) sharedManager;
- (void) setupRequestDescriptors;
- (void) setupResponseDescriptors;
@end
**RKObjectManager.m**
static AKObjectManager *sharedManager = nil;
@implementation AKObjectManager
+ (instancetype)sharedManager {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSURL *url = [NSURL URLWithString:BASE_DEVELOPMENT_URL];
sharedManager = [self managerWithBaseURL:url];
sharedManager.requestSerializationMIMEType = RKMIMETypeJSON;
/*
THIS CLASS IS MAIN POINT FOR CUSTOMIZATION:
- setup HTTP headers that should exist on all HTTP Requests
- override methods in this class to change default behavior for all HTTP Requests
- define methods that should be available across all object managers
*/
[sharedManager setupRequestDescriptors];
[sharedManager setupResponseDescriptors];
AppDelegate *delegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];
[sharedManager.HTTPClient setDefaultHeader:@"Authorization" value: [NSString stringWithFormat:@"token %@", delegate.key]];
});
return sharedManager;
}
- (void) setupRequestDescriptors {
}
- (void) setupResponseDescriptors {
}
**TaskManager.m**
@implementation TaskManager
+ (id)sharedInstance {
static TaskManager *__sharedInstance=nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__sharedInstance = [[self alloc] init];
[__sharedInstance setupResponseDescriptors];
});
return __sharedInstance;
}
- (void) loadTask:(void (^)(NSArray *task))success failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure{
});
**#import "TaskDashboardCountManager.h"**
static TaskDashboardCountManager *sharedManager = nil;
@implementation TaskDashboardCountManager
+ (id)sharedInstance {
static TaskDashboardCountManager *__sharedInstance=nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__sharedInstance = [[self alloc] init];
[__sharedInstance setupResponseDescriptors];
});
return __sharedInstance;
}
- (void) loadTaskCount:(void (^)(NSDictionary *task))success failure:(void (^)(RKObjectRequestOperation *operation, NSError *error))failure{
});