我要去YouTube影片,讓使用Xcode中的位置服務編程排序地圖的用戶界面到的一個基本的例子「未申報類型的使用」程序。我按照設置程序的視頻中的步驟進行操作,並在嘗試編譯應用程序時出現一個假設簡單的「使用未聲明類型」錯誤。斯威夫特:利用CLLocationManagerDelegate和CoreLocation.framework導致錯誤
https://www.youtube.com/watch?v=qrdIL44T6FQ - 鏈接到YouTube視頻。
的問題發生在類的創建線。
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate
{ //^Use of undeclared type
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
self.mapView.showsUserLocation = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreate-d.
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let center = CLLocationCoordinate2D(latitude: location!.coordingate.latitude, longitude: location!.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
self.mapView.setRegion(region, animated: true)
self.location.stopUpdatingLocation()
}
func locationManager(manager: CLLocationManager, difFailWithError error: NSError)
{
print("Errors: " + error.localizedDescription)
}
}
我不確定錯誤發生的原因。 我在「Link Binary With Libraries」部分添加了CoreLocation.framework。我確保將InfoL中的「NSLocationWhenInUseUsageDescription」添加到Info.plist中。 我在視頻中2:26將Map View Kit連接到代碼本身。
其他方式去這樣做是利益也。我只是試圖獲得基本的位置服務許可以便在程序中運行。
版本:版本的Xcode 7.3.1