我从 Big Nerd Ranch iOS Programming 一书中获取了这段代码。在代码中,他们分配了两个实例变量,coordinate
并且title
. 为什么coordinate
直接赋值,title
调用setter来设置?
头文件
@interface BNRMapPoint : NSObject<MKAnnotation>
-(id)initWithCoordinate:(CLLocationCoordinate2D )c title:(NSString *)t;
@property(nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title;
@end
实施文件
-(id)initWithCoordinate:(CLLocationCoordinate2D)c title:(NSString *)t
{
self = [super init];
if(self){
coordinate = c;
[self setTitle:t];
}
return self;
}