gpt4 book ai didi

objective-c - 将 NSError ** 作为方法参数传递时出现编译器警告

转载 作者:行者123 更新时间:2023-12-03 17:30:56 26 4
gpt4 key购买 nike

在过去的 4 个小时里,我一直在为此绞尽脑汁,尝试各种小实验,但我似乎无法弄清楚出了什么问题。这可能是编译器错误吗?

测试.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):

warning: incompatible Objective-C types 'struct NSError **', expected 'struct NSDictionary **' when passing argument 2 of 'initWithContentsOfURL:error:' from distinct Objective-C type

我正在使用最新版本的 Xcode 和 Snow Leopard。

最佳答案

我怀疑它选择了不同的选择器实例,initWithContentsOfURL:error: - 可能是 NSAppleScript 中的一个。 。请记住,[NSObject alloc] 返回一个 id

您的代码在运行时是否按预期工作?

尝试将 [Test alloc] 的返回值转换为 Test*


Test *t = [(Test*)[Test alloc] initWithContentsOfURL:[NSURL fileURLWithPath:@"/"] error:&error];

关于objective-c - 将 NSError ** 作为方法参数传递时出现编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2591820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com