Swift 2 CLLocationManager错误

Swift 2 CLLocationManager错误,swift,swift2,cllocationmanager,cllocation,Swift,Swift2,Cllocationmanager,Cllocation,我以前看过一篇关于这个的帖子,但是没有一个解决方案适合我 我得到这个错误: 目标C方法“位置管理器:didUpdateLocations:”由提供 方法“locationManager(uIdUpdateLocations:)”与冲突 可选的需求方法“locationManager(ux0:didUpdateLocations:)” 在协议“CLLocationManagerDelegate”中 使用以下代码: func locationManager(manager: CLLocationMa

我以前看过一篇关于这个的帖子,但是没有一个解决方案适合我

我得到这个错误:

目标C方法“位置管理器:didUpdateLocations:”由提供 方法“locationManager(uIdUpdateLocations:)”与冲突 可选的需求方法“locationManager(ux0:didUpdateLocations:)” 在协议“CLLocationManagerDelegate”中

使用以下代码:

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location = locations.last
    let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
    self.mapView.setRegion(region, animated: true)
    self.locationManager.stopUpdatingLocation()
}

你的问题无法重现。这是我机器上iOS项目中Swift文件的完整内容;它在Swift 2.1下编译得非常愉快:

import UIKit
import CoreLocation
import MapKit
class MapViewController : UIViewController, CLLocationManagerDelegate {
    var mapView : MKMapView!
    var locationManager : CLLocationManager!
    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let location = locations.last
        let center = CLLocationCoordinate2D(latitude: location!.coordinate.latitude, longitude: location!.coordinate.longitude)
        let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 1, longitudeDelta: 1))
        self.mapView.setRegion(region, animated: true)
        self.locationManager.stopUpdatingLocation()
    }
}
当然,该代码实际上不会做任何事情(没有实际的地图视图);这只是一些代码。但是没有编译器错误


如果您仍在使用早期版本的Swift,请更新您的Xcode副本。如果您使用的是Xcode 7.1,那么您的错误是无法解释的。

只是为了确认一下,您是否将coreLocation框架
导入coreLocation
投票关闭作为不可复制的