- while I was using a block, it aways prompt block type confit,
原因如下:
Redefinition of 'responseObject' with a different type: 'sucessBlock
(__strong' (aka 'void (^__strong)(__strong id)') vs 'id _Nullable
__strong' // here is the block declare: #import <Foundation/Foundation.h> typedef void(^sucessBlock)(id
respondseObject); typedef void(^failureBlock)(NSError * error);
#import <Foundation/Foundation.h>
typedef void(^sucessBlock)(id respondseObject);
typedef void(^failureBlock)(NSError * error);
@interface TRAFNetWorkManager : NSObject
+(void)sendGetRequestWithUrl:(NSString*)urlStr paramenters:(NSDictionary*)paramDic sucess:(sucessBlock)suscess failure:(failureBlock)failure;
@end
//这是补码#import
#import "TRAFNetWorkManager.h"
#import "AFNetworking.h"
@implementation TRAFNetWorkManager
+(void)sendGetRequestWithUrl:(NSString *)urlStr paramenters:(NSDictionary *)paramDic sucess:(sucessBlock)suscess failure:(failureBlock)failure {
AFHTTPSessionManager* manager=[AFHTTPSessionManager manager];
[manager GET:urlStr parameters:paramDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
sucessBlock(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSError*error1=nil;
failureBlock(error1);
}];
}
@end
最佳答案
successBlock
和failureBlock
是块类型的名称。您不能将它们用于调用。相反,您需要使用块变量的名称,在您的情况下为success
和failure
:
+(void)sendGetRequestWithUrl:(NSString *)urlStr
paramenters:(NSDictionary *)paramDic
success:(successBlock)success
failure:(failureBlock)failure {
AFHTTPSessionManager* manager=[AFHTTPSessionManager manager];
[manager GET:urlStr parameters:paramDic progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
success(responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSError*error1=nil;
failure(error1);
}];
}
关于ios - 块类型限制,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34785582/