Assigning to 'id<MKMapViewDelegate>' from incompatible type 'ViewController *const __strong'
發生於 mapView.delegate = self;,表示 ViewController 未遵循 MKMapViewDelegate 協定。
ViewController.h。@interface ViewController : UIViewController <MKMapViewDelegate>ViewController.m 實作代理方法,如 - (void)mapView:didUpdateUserLocation: 等。#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController <MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet MKMapView *mapView;
@end
@synthesize mapView; 在現代 Xcode (LLVM 4.0+) 可省略,屬性會自動合成。MKMapView 的 delegate Outlet 已連線至 View Controller。MKMapView 預設顯示用戶位置需在 Info.plist 加入 NSLocationWhenInUseUsageDescription。