Why after upgrading to Xcode 4.2 does MKAnnotation display a warning

泄露秘密 提交于 2019-12-12 10:05:45

问题


In Xcode 4.1 there was no problem, but upgrading to Xcode 4.2 I get the following warning:

Property 'title' 'copy' attribute does not match the property inherited from 'MKAnnotation'
Property 'subtitle' 'copy' attribute does not match the property inherited from 'MKAnnotation'

My code:

@interface MyAnnotation : NSObject <MKAnnotation> {
    CLLocationCoordinate2D coordinate;
    NSString *subtitle;  
    NSString *title; 
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *subtitle;  
@property (nonatomic, retain) NSString *title; 

-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;

@end

回答1:


Change it to:

@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *title;

The MKAnnotation protocol declares

@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;

You shouldn't change the storage type of a property, the only change you can / should make is from readonly to readwrite if needed;




回答2:


Try converting you application to ARC using Edit -> Refactor -> Convert to Objective-C ARC



来源:https://stackoverflow.com/questions/7760081/why-after-upgrading-to-xcode-4-2-does-mkannotation-display-a-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!