spl*_*cer 0 cocoa objective-c compiler-warnings compiler-bug
在过去的4个小时里,我一直在摸不着头脑,尝试各种小实验,但我似乎无法弄清楚出了什么问题.这可能是编译器错误吗?
Test.m:
- (id)initWithContentsOfURL:(NSURL *)aURL error:(NSError **)error
{
if (!(self = [super init])) {
return nil;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
main.m文件:
NSError *error;
Test *t = [[Test alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"/"] error:&error];
Run Code Online (Sandbox Code Playgroud)
这是编译器警告(来自main.m):
警告:不兼容的Objective-C类型'struct NSError**',当从'initWithContentsOfURL:error:'传递参数2时,期望'struct NSDictionary**'来自不同的Objective-C类型
我正在使用最新版本的Xcode和Snow Leopard.
我怀疑它正在选择一个不同的选择器实例,initWithContentsOfURL:error:也许是其中的一个NSAppleScript.请记住,[NSObject alloc]返回一个id.
您的代码在运行时是否按预期工作?
尝试铸造返回[Test alloc]到Test*.
即
Test *t = [(Test*)[Test alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"/"] error:&error];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
579 次 |
| 最近记录: |