Assigning itself to CLLocationManager.delegate generates an incompatible type warning

The application that I have been working with for some time, without build errors, from the moment I upgraded to xCode 4, gave 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 is that after cleaning and assembling xcodes does not cause any problems. However, if I go to the class containing this code, a build error will suddenly appear and remain until I do a clean one again.

actual warning ...

warning: Semantic Issue: Incompatible pointer types assigning 'id' from 'Class'

CLLocationmanager works fine, and my delegation methods are called, so everything works correctly. I would like to get rid of this warning. Should I just ignore him?

+4
source share
5 answers

I think you should file a bug report with Apple, and until they do nothing, I think that all you can do is ignore it.

+2
source

Have you announced that your delegate object conforms to the CLLocationManagerDelegate protocol? I usually do this in a class extension instead of a 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 } 
+23
source

Inconsistent warnings seem like an error. But the real question is whether the self class is declared in the above code as an implementation of the CLLocationManagerDelegate protocol. If you implement the correct methods, then it will work no matter how it is declared. But if the class declaration does not include <CLLocationManagerDelegate> , then the compiler will complain. If you do not have this, then fixing the class declaration should fix the warning.

+4
source

I think you need to add CLLocationManagerDelegate to your .h file as

 @interface MyViewController : UIViewController <CLLocationManagerDelegate> 
+2
source

I have the same situation.

add the line below, then the warning message will disappear.

 #import <CoreLocation/CLLocationManagerDelegate.h> 
+2
source

Source: https://habr.com/ru/post/1346975/


All Articles