Swift 2 CLLocationManager Error updating

markutus picture markutus · Jun 25, 2015 · Viewed 11.2k times · Source

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'

Answer

Brandon Price picture Brandon Price · Jun 25, 2015

Just had the same issue as you, change

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

to

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