나는 나에게 다음과 같은 충돌 보고서를 제공 내 응용 프로그램의 충돌을 받고있다 :왜 NSOperation이이 크래시를 트리거합니까?
http://crashes.to/s/bed19f6404b
문제를 교반하는 방법이 하나입니다 충돌이 응용 프로그램 이후에 발생
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
let MapThread = NSOperationQueue()
MapThread.name = "Map Update"
MapThread.addOperationWithBlock() {
if self.StartandStop.titleLabel?.text == "Start Flight" || self.StartandStop.titleLabel?.text == "Démarrez" {
if let location = locations.first as? CLLocation {
let lastLocation = locations.last as? CLLocation
var altitude = lastLocation?.altitude
dispatch_async(dispatch_get_main_queue(),{
self.mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 17, bearing: 0, viewingAngle: 0)
});
}
}
if self.StartandStop.titleLabel?.text == "Stop Flight" || self.StartandStop.titleLabel?.text == "Arrêtez" {
if let mylocation = self.mapView.myLocation as CLLocation? { // This is the line indicated in the stack trace
let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
if CMAltimeter.isRelativeAltitudeAvailable() {
println("Check")
appDelegate.maxAltitude = NSString(format: "%.01f", self.maxAlt*3.28084) + " Ft"
}
else {
let relativeAlt = (self.mapView.myLocation as CLLocation).altitude - appDelegate.elevation
appDelegate.altitudes.append(Float(relativeAlt)*3.28084)
self.altitude = Float(relativeAlt)
if appDelegate.maxAltitude == "" {
appDelegate.maxAltitude = "0.0 Ft"
}
}
var lastDistance = self.Distance(self.lastLocation, Coordinate2: (self.mapView.myLocation as CLLocation).coordinate)
self.distance += lastDistance
var lastSpeed = Float((self.mapView.myLocation as CLLocation).speed)
if self.groundspeed > lastSpeed {
appDelegate.groundspeed = NSString(format: "%.01f", Float((self.mapView.myLocation as CLLocation).speed)*1.94384) + " Kts"
}
self.groundspeed = lastSpeed
self.path.addCoordinate(self.mapView.myLocation.coordinate)
dispatch_async(dispatch_get_main_queue(),{
GMSPolyline(path: self.path).map = self.mapView
self.mapView.camera = GMSCameraPosition(target: self.mapView.myLocation.coordinate as CLLocationCoordinate2D, zoom: 17, bearing: 0, viewingAngle: 0)
});
self.lastLocation = (self.mapView.myLocation as CLLocation).coordinate
}
}
}
}
이 방법을 자주 실행하면 오랜 시간 동안 배경에 남아 있습니다. NSOperation이 나에게 어려움을주고있는 것일까? 이전에 백그라운드 스레드에서 UI를 업데이트 할 때부터 문제가있었습니다. 그런 다음 GCD 파견을 추가하여지도를 그렸습니다. 마지막 문제가 수정되었습니다. 최대한 많은 NSOperation을 제거해야합니까?
나는이 용어에 익숙하지 않다. 개체의 전체 복사본은 무엇입니까? – user3185748
걱정할 필요가 없습니다. 기본적인 설명은 http://stackoverflow.com/a/184745/1445366을 참조하십시오. –