将'MapAnnotation*__ strong'发送到不兼容类型'id <MKAnnotation>'的参数

Sub*_*ubi 11 iphone

我在下面提到的一行中收到警告:

[self.mapView addAnnotation:addressAnnotation];
Run Code Online (Sandbox Code Playgroud)

警告是:

Sending 'MapAnnotation *__strong' to parameter of incompatible type 'id<MKAnnotation>'
Run Code Online (Sandbox Code Playgroud)

由于我提到类似的帖子,我不得不提一下,这个类的头文件包括<MKAnnotation>,类的前向声明MapAnnotation也可用.

请建议.

Mil*_*deh 37

要摆脱警告,您有两种选择:

  1. 在声明中声明self类(无论该类是什么)@interface,以符合协议.

  2. 通过更改以下内容来抑制警告:

    [self.mapView addAnnotation:addressAnnotation];

    对此:

    [self.mapView addAnnotation:(id)addressAnnotation];

  • 这是正确的答案,为什么没有标记?谢谢. (3认同)