tôi đã cập nhật Xcode 6 lên Xcode 7 beta bằng Swift 2. Tôi gặp lỗi này và tôi không thể tìm ra cách sửa lỗi, vui lòng giúp tôi. Cảm ơn. Đây là mã của tôi:Swift 2 CLLocationManager Lỗi cập nhật
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)
}
và tôi nhận được lỗi này:
Objective-C method 'locationManager:didUpdateLocations:' provided by method 'locationManager(_:didUpdateLocations:)' conflicts with optional requirement method 'locationManager(_:didUpdateLocations:)' in protocol 'CLLocationManagerDelegate'
'AnyObject' là siêu kiểu của' CLLocation'. Cả hai sẽ hoạt động. – akashivskyy
Tôi biết điều đó nhưng khi tôi thay đổi từ [AnyObject] thành [CLLocation] thì lỗi đã biến mất. –
đã thử rằng, nó hoạt động nhưng sau đó nó đã cho tôi một lỗi trên dòng này: 'let location = locations.last as! CLLocation' nói rằng locations.last không thể là một CLLocation – markutus