在代码/依赖性方面,调试和发布版本之间是否有任何区别?
我最近开始使用测试飞行(这使用发布版本)并且除了崩溃之外什么都没有。当我构建调试时,它完美地工作。
有人有这个问题吗?
目前,当应用程序点击&#34时,我会收到一个exc_breakpoint;返回true" 这看起来很奇怪。当你所要做的就是返回" 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
}
}
更新:
经过大量的反复试验,我发现添加println()来获取某些值可以防止我的错误。出于某种原因,除了在使用值之前调用println()的时候,除了在我之前调用println()时,不为nil的东西变为nil。对我毫无意义......
答案 0 :(得分:2)
作为猜测,我认为优化器正在咬你。 fromLocationLa
,fromLocationLo
,fromLocation
和distance
仅使用一次。这意味着可以进行以下优化。
…
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
}
}