2015-02-06 6 views
0

나는 나에게 다음과 같은 충돌 보고서를 제공 내 응용 프로그램의 충돌을 받고있다 :왜 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을 제거해야합니까?

답변

0

NSOperationQueueNSBlockOperation은 GCD 주변의 편리한 래퍼 일 뿐이므로 제거하는 것이 도움이 될 것이라고 생각하지 않습니다. 다른 그들을 사용하는 동안

  1. 당신의 CLLocation 객체가 하나 개의 스레드에 변경되는 :

    나는 세 가지 가설이있다.

  2. locations이 강제적으로 언 래핑 되었기 때문일 수 있습니다 ("암시 적으로 언 래핑 됨"). 아마도이 배열은 참조 할 때마다 할당이 해제되어 충돌을 일으킬 수 있습니다. (이 은 당신이 그것에 대해 강한 참조를 유지하고 있기 때문에이 발생하지 않아야합니다.)
  3. Obj-C/Swift bridge에 문제가있을 수 있습니다. 로그를 올바르게 읽는다면 충돌이 발생합니다. objc_retain에, Swift 옵션에서 래핑 해제 한 후 오브젝트를 보유합니다.

어느 쪽이든, 나는 그것이 당신의 잘못,하지만 실험으로 당신이 당신의 작업에서 복사 깊은 locations의 복사 및 사용을 만들 수있는 확신 아니에요.

+0

나는이 용어에 익숙하지 않다. 개체의 전체 복사본은 무엇입니까? – user3185748

+0

걱정할 필요가 없습니다. 기본적인 설명은 http://stackoverflow.com/a/184745/1445366을 참조하십시오. –

관련 문제