编译器警告传递NSERROR **作为方法参数
-
25-09-2019 - |
题
在过去的四个小时中,我一直在抓先了解这一点,尝试了各种小实验,但我似乎无法弄清楚发生了什么问题。这可以是编译器错误吗?
test.m:
- (id)initWithContentsOfURL:(NSURL *)aURL error:(NSError **)error
{
if (!(self = [super init])) {
return nil;
}
return self;
}
main.m:
NSError *error;
Test *t = [[Test alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"/"] error:&error];
这是编译器警告(来自main.m):
警告:不兼容的Objective-C类型“ struct nSerror **”,预期的'struct'struct nsdictionary **'传递“ InitwithContentsofurl:错误:”来自不同的Objective-C类型的参数2
我正在使用Xcode和Snow Leopard的最新版本。
解决方案
我怀疑它正在拾取选择器的另一个实例, initWithContentsOfURL:error:
- 也许是 NSAppleScript
. 。记住这一点 [NSObject alloc]
返回 id
.
您的代码在运行时是否可以按预期工作?
尝试投射回归 [Test alloc]
至 Test*
.
IE
Test *t = [(Test*)[Test alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"/"] error:&error];
不隶属于 StackOverflow