Xcode "AppDelegate *const __strong' to parameter of incompatible type"错误



当我声明appDelegate接口如下以设置NSXMLParserDelegate时,我收到来自其他使用[[UIApplication sharedApplication]委托]的视图的警告;

@interface AppDelegate : UIResponder <UIApplicationDelegate, NSXMLParserDelegate>

警告:使用表达式初始化"应用程序委托 *__strong" 不兼容的类型"ID"

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

@interface AppDelegate : UIResponder <UIApplicationDelegate>

警告:将"应用程序委托 *常量__strong"发送到参数 不兼容的类型"ID"

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

如何删除两者?谢谢

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

看起来您的应用程序代表需要成为其自身目的的委托。您可以通过在 AppDelegate.m 文件中创建类扩展来"私下"实现接口。

@interface AppDelegate() <NSXMLParserDelegate>
@end

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

[xmlParser setDelegate:self];

相关内容