【发布时间】:2015-12-07 02:26:48
【问题描述】:
我在我的项目中使用了我朋友的代码,但我收到了这个错误(他的代码在他的项目中没有错误。)
错误:Cannot initialize return object of type 'id'with an rvalue of type 'AsyncTaskResult_e'
.m 文件发生错误(返回失败;)
这是.h文件
#ifndef AsyncTask_h
#define AsyncTask_h
#import <Foundation/Foundation.h>
typedef enum AsyncTaskResult_e {
Success,
Fail
}
AsyncTaskResult_t;
@protocol AsyncTaskInterface
@required
-(void)preExecute:(id)parameters;
-(id)doInBackground:(id)parameters;
-(void)postExecute:(id)result;
@end
// This interface is imitated AsyncTask of Android
@interface AsyncTask : NSObject<AsyncTaskInterface>
-(void) executeParameters:(id)parameters;
@end
#endif /* AsyncTask_h */
这是.m文件
#import "AsyncTask.h"
@implementation AsyncTask
-(void) executeParameters:(id)parameters {
[self preExecute:parameters];
__block id result;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
result = [self doInBackground:parameters];
dispatch_async(dispatch_get_main_queue(), ^{
[self postExecute:result];
});
});
}
-(void)preExecute:(id)parameters {
// Run on main thread (UIThread)
}
-(id)doInBackground:(id)parameters {
// Run on async thread (Background)
return Fail;
}
-(void)postExecute:(id)result {
// Run on main thread (UIThread)
}
@end
我是否缺少实现此代码的内容?
【问题讨论】:
-
Fail是一个枚举,返回它的函数返回id这是一个对象。枚举不能转换为对象。 -
为什么投反对票?问一个你不知道的问题是错误的吗?
-
@user3423040 您的问题没有理由投反对票,也没有理由投赞成票。您的问题显示了相关代码,它提出了一个明确的问题,并解释了您遇到的错误。
标签: objective-c enums