ios - Error when assigning NSString variable in a block -
- (nsstring *) geocodeaddressfromcoordinate:(cllocationcoordinate2d)coordinate { cllocation *location = [[cllocation alloc]initwithlatitude:coordinate.latitude longitude:coordinate.longitude]; __block nsmutablestring * address = [nsmutablestring string]; geocoder = [[clgeocoder alloc]init]; [geocoder reversegeocodelocation:location completionhandler:^(nsarray *placemarks, nserror *error) { if (error) { nslog(@"%@", [error localizeddescription]); uialertview *alert = [[uialertview alloc]initwithtitle:@"no results found" message:@"try search" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:nil, nil]; alert.show; return; } if ([placemarks count]>0) { nslog([placemarks description]); clplacemark *placemark = [placemarks objectatindex:0]; nslog(placemark.locality); //this line makes error [address initwithstring:placemark.locality];** } }]; return address; }
got following runtime error:
* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* initialization method -initwithcharactersnocopy:length:freewhendone: cannot sent abstract object of class __nscfstring: create concrete instance!'
you should never call 'initwithstring:' without matching alloc. looks more want [address setstring:placemark.locality]
Comments
Post a Comment