gpt4 book ai didi

iphone - Xcode "AppDelegate *const __strong' 到不兼容类型的参数”错误

转载 作者:可可西里 更新时间:2023-11-01 05:01:46 27 4
gpt4 key购买 nike

当我如下声明 appDelegate 接口(interface)以设置 NSXMLParserDelegate 时,我从其他使用 [[UIApplication sharedApplication] delegate] 的 View 收到一些警告;

@interface AppDelegate : UIResponder <UIApplicationDelegate, NSXMLParserDelegate>

warning: Initializing 'AppDelegate *__strong' with an expression of incompatible type 'id'

但是,如果我删除它,由于 xmlParser 的 self 设置会出现另一个警告,

@interface AppDelegate : UIResponder <UIApplicationDelegate>

warning: Sending 'AppDelegate *const __strong' to parameter of incompatible type 'id'

    xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
[xmlParser setDelegate:self];

如何删除两者?谢谢

最佳答案

你真的不应该让你的 AppDelegate 公开暴露接口(interface)。它在所有代码之间创建了非常紧密的耦合。如果其他代码(在您的 AppDelegate 之外)需要 NSXMLParserDelegate,您应该为它创建一个不同的类。

看起来您的 AppDelegate 需要成为其自身目的的委托(delegate)。您可以通过在 AppDelegate.m 文件中进行类扩展来“私下”实现接口(interface)。

@interface AppDelegate() <NSXMLParserDelegate>
@end

执行上述操作将删除您在此处收到的警告:

[xmlParser setDelegate:self];

关于iphone - Xcode "AppDelegate *const __strong' 到不兼容类型的参数”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11147239/

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