Search code examples
cllocationmanagerswift2xcode7xcode7-beta2

Swift 2 CLLocationManager Error updating


i updated Xcode 6 to Xcode 7 beta with Swift 2. I get this error and i can't find out how to fix it, please help me. Thanks. This is my code :

 func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
    let location = locations.last as! CLLocation

    let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
    let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))

    self.map.setRegion(region, animated: true)
}

and i get this error :

Objective-C method 'locationManager:didUpdateLocations:' provided by method 'locationManager(_:didUpdateLocations:)' conflicts with optional requirement method 'locationManager(_:didUpdateLocations:)' in protocol 'CLLocationManagerDelegate'


Solution

  • Just had the same issue as you, change

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject])
    

    to

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])