Self Location Manager Delegate error in Xcode 6

2019-08-03 03:51发布

问题:

I'm using code from: http://www.veasoftware.com/tutorials/2014/6/17/xcode-5-tutorial-ios-7-simple-compass-app In Xcode 6 I get the error below. The app still runs, but this error is really annoying me.

self.locationManager.delegate = self;
//Assigning to 'id<CLLocationManagerDelegate>' from incompatible type 'ViewController *const __strong'

回答1:

I guess you forgot to comply with the Core Location Delegate protocol by adding <CLLocationManagerDelegate> after @interface in the header file.



回答2:

Try this:

1)Make your class import the below:

#import<CoreLocation/CoreLocation.h>

2) Make you class adopt the protocol:

interface YourClassName : UIViewController <CLLocationManagerDelegate>

3) In Last option to suppress it by doing:

self.locationManager.delegate = (id)self; 

The warning should be gone now.



回答3:

self.locationManager.delegate = (id)self;