[英]Xcode 6: Why this code doesn't compile now?
在升級到Xcode 6之前,我的代碼一直在編譯並且運行良好。
定義顯示警告:自動屬性合成不會合成屬性“哈希”,因為它是“讀寫”的,但會通過另一個屬性合成為“只讀”
@property (nonatomic, strong) NSString *hash; // (get/compute) hash code of the place (master hash of images)
每當我訪問_hash時,實現都會顯示錯誤:使用未聲明的標識符'_hash'
-(NSString *)hash {
if (_hash) return _hash;
// If place id, take it as the hash code
NSString *poiID = self.info[@"id"];
if (poiID) {
_hash = [NSString stringWithFormat:@"id-%lu",(unsigned long)[self.address hash]];
}
else if (CLLocationCoordinate2DIsValid(self.location.coordinate)) {
NSString *seed = [NSString stringWithFormat:@"%f,%f", self.location.coordinate.latitude, self.location.coordinate.longitude];
_hash = [NSString stringWithFormat:@"location-%lu",(unsigned long)[seed hash]];
}
else if (self.address) {
NSString *seed = self.address;
_hash = [NSString stringWithFormat:@"address-%lu",(unsigned long)[seed hash]];
}
else {
_hash = @"POI-unknownIDLocationOrAddress";
}
return _hash;
}
您需要添加以下行以自動生成setter方法:
@synthesize hash = _hash;
如果您不希望使用setter方法,而只希望使用只讀屬性:
@property (nonatomic, strong, readonly) NSString *hash;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.