我有一个CLregions数组,这是我的代码:
NSArray *_regionArray;
NSArray *_geofences_regions;
... in the ViewDidLoad
_geofences_regions = [self buildGeofenceData];
....
- (NSArray*) buildGeofenceData {
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"regions" ofType:@"plist"];
_regionArray = [NSArray arrayWithContentsOfFile:plistPath];
NSMutableArray *geofences = [NSMutableArray array];
for(NSDictionary *regionDict in _regionArray) {
CLRegion *region = [self mapDictionaryToRegion:regionDict];
[geofences addObject:region];
}
return [NSArray arrayWithArray:geofences];
}
- (CLRegion*)mapDictionaryToRegion:(NSDictionary*)dictionary {
NSString *title = [dictionary valueForKey:@"title"];
CLLocationDegrees latitude = [[dictionary valueForKey:@"latitude"] doubleValue];
CLLocationDegrees longitude =[[dictionary valueForKey:@"longitude"] doubleValue];
CLLocationCoordinate2D centerCoordinate = CLLocationCoordinate2DMake(latitude, longitude);
CLLocationDistance regionRadius = [[dictionary valueForKey:@"radius"] doubleValue];
return [[CLRegion alloc] initCircularRegionWithCenter:centerCoordinate
radius:regionRadius
identifier:title];
}在下面的代码中,the property identifier is not found on object of type id。
为什么会这样呢?_geofences_regios[i]不应该返回一个CLRegion吗?
/*check for region*/
CLLocationCoordinate2D coordinate = [bestLocation coordinate];
for (int i=0; i<[_geofences_regions count]; i++) {
if ([_geofences_regions[i] containsCoordinate:coordinate]) {
[self.delegate locationManager:self regionEntered:_geofences_regions[i].identifier ];}}区域/的/end检查
请回答以上问题,不要建议我使用其他委托方法,如didEnterRegion。
谢谢!
发布于 2013-09-08 13:26:49
这是因为数组返回的对象(默认情况下是没有id属性的identifier类型),可以执行强制转换以避免错误:
[self.delegate locationManager:self regionEntered:((CLRegion*)_geofences_regions[i]).identifier ];https://stackoverflow.com/questions/18684096
复制相似问题