2015-01-25 3 views
0

코드/종속성 측면에서 디버그와 릴리스 빌드간에 차이가 있습니까?디버그 대 릴리스 빌드 ?? xcode

최근에 테스트 비행을 사용하기 시작했으며 (릴리스 빌드를 사용함) 충돌이 발생했습니다. 디버깅을 위해 완벽하게 작동합니다.

사람은이 문제를했다?

현재 앱이 "true를 반환합니다"라는 메시지가 표시되면 exc_breakpoint가 표시됩니다. 매우 이상하게 보입니다. 당신이해야 할 모든 반환 "true"로 때 잘못 아무것도 없다

import UIKit 
import CoreLocation 


func calculateRelevance (album: AlbumLight , currentLocation: CLLocation, currentCity: String) -> Bool { 

    let fromLocationLa: CLLocationDegrees = CLLocationDegrees(album.la!) 
    let fromLocationLo: CLLocationDegrees = CLLocationDegrees(album.lo!) 

    var fromLocation: CLLocation = CLLocation(latitude: fromLocationLa, longitude: fromLocationLo) 
    let distance = fromLocation.distanceFromLocation(currentLocation) 

    if album.isActive == true { 
     if album.hasRange == true { 
      if distance < Double(album.range!) { 

       return true 

      } 
      else { 

       return false 

      } 
     } 
     else { 
      if currentCity == album.city { 

       return true 

      } 
      else { 

       return false 

      } 
     } 
    } 
    else { 

     return false 

    } 
} 

업데이트 : 시행 착오를 많이 후

, 나는 발견에) (A에 println 추가 특정 값을 얻으면 내 버그를 예방할 수 있습니다. 어떤 이유로 nil이 아닌 것은 println()을 호출 할 때를 제외하고는 nil로 바뀐다. 나에게 이해가되지 않는다 ....

답변

2

나는 옵티마이 저는 당신을 물고 있다고 생각한다. fromLocationLa, fromLocationLo, fromLocationdistance은 한 번만 사용됩니다. 즉, 다음과 같은 최적화를 수행 할 수 있습니다.

… 
let fromLocationLa: CLLocationDegrees = CLLocationDegrees(album.la!) 
let fromLocationLo: CLLocationDegrees = CLLocationDegrees(album.lo!) 

var fromLocation: CLLocation = CLLocation(latitude: fromLocationLa, longitude: fromLocationLo) 
let distance = fromLocation.distanceFromLocation(currentLocation) 

if album.isActive == true { 
    if album.hasRange == true { 
     if distance < Double(album.range!) { 

      return true 

     } 
     else { 

      return false 

     } 
    } 
… 

은 최적화 된 코드에서 홀수 행 번호를 설명 할 수

if album.isActive == true { 
    if album.hasRange == true { 
     return CLLocation(latitude: CLLocationDegrees(album.la!), longitude: CLLocationDegrees(album.lo!)).distanceFromLocation(currentLocation) < Double(album.range!) 
    } 

이 최적화. 또한 한 줄에 많은 암시 적 래핑을 넣습니다.

문제가있는 것 같으면 선택 사항의 래핑을 해제 할 때 약간의주의가 필요할 수 있습니다.

let fromLocationLa: CLLocationDegrees? = album.la != nil ? CLLocationDegrees(album.la!) : nil 
let fromLocationLo: CLLocationDegrees? = album.la != nil ? CLLocationDegrees(album.lo!) : nil 

var fromLocation: CLLocation? = fromLocationLa != nil && fromLocationLo != nil ? CLLocation(latitude: fromLocationLa!, longitude: fromLocationLo!) : nil 
let distance = fromLocation?.distanceFromLocation(currentLocation) 

if album.isActive == true { 
    if album.hasRange == true { 
     if distance != nil && album.range != nil && distance! < Double(album.range!) { 

      return true 

     } 
     else { 

      return false 

     } 
    } 
+0

모두 사실입니다. 그러나 왜 릴리스 빌드가 디버그가 문제가되지 않는 이유는 무엇입니까? 실제 호출이 수정되기 전에 줄에 println()이 나오는 이유는 무엇입니까? 다른 호출과 동일한 방식으로 값을 호출하거나 만지는 않습니까? 어쨌든. 나는 당신이 제안한 것과 똑같이함으로써 그것을 고쳤다. 필자는이를 최적화하고 별도의 기능에서 일부 기능을 주 기능으로 옮겼습니다. 너무 많은 주위에 옵션을 이동하면 분명히 문제가 발생합니다. 내가 옳은 길을 가고 있다는 것을 알았습니다. 어쨌든 –

+0

실제 문제를 이해하는 것은 너무 과장된 것입니다. 동일한 코드로 println()을 모두 삭제했습니다. 다른 버그도 수정하지 않았는지 확인하십시오. 몇 명 더 찾았 어. 정말 이상한 ... –

+1

정확한 문제를 추적하는 것은 매우 어려울 수 있습니다. 실패의 원인이 된 정확한 최적화 (또는 최적화 조합)를 추적하는 것은 매우 어려울 수 있습니다. –

관련 문제