Xcode 6:为什么这段代码现在不能编译?

问题描述:

我的代码被编译,直到我升级到Xcode的运行极大6.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; 
+0

好的。我们现在必须用@synthesize hash = _hash显式声明自动合成; – 2014-09-21 15:04:03

+0

查看本节[何时提供实例变量](http://useyourloaf.com/blog/2012/08/01/property-synthesis-with-xcode-4-dot-4.html)来自2012年的关于Xcode 4.4的文章 – 2014-09-21 15:30:03

+0

换句话说,命名你的财产什么,但“散列”。 – gnasher729 2014-09-21 15:44:08