The App I am current working on for some time now with no build errors has, since upgrading to xCode 4, been giving me an incompatible type warning for the last line of this code...
locationManager = [[CLLocationManager alloc] init];
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
locationManager.delegate = self;
The funny thing about it is that after a clean and build, xCodes reports no issues. However, if I go to the class containing this code the build error suddenly appears and remains until I do a clean again.
the actual warning is...
warning: Semantic Issue: Incompatible pointer types assigning to 'id' from 'Class'
CLLocationmanager works fine and my delegate methods are getting called so everything appears to be working properly. I would like to get rid of this warning. Should I just ignore it?
Did you declare your delegate object to follow the CLLocationManagerDelegate protocol? I'd usually do this in a class extension instead of the header file for MyObject.
@interface MyObject()<CLLocationManagerDelegate>
@end
or in Swift
@objc class MyObject: NSObject, CLLocationManagerDelegate
{
// implement whichever of the optional protocol functions you need
}
The inconsistent warnings seem like a bug. But the real question is whether self
's class in the above code has been declared as implementing the CLLocationManagerDelegate
protocol. If you implement the right methods then it'll work regardless of how it's declared. But if the class declaration doesn't include <CLLocationManagerDelegate>
in it then the compiler will complain. If you don't have that then fixing the class declaration should fix the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With