我遇到了很多这样的崩溃事件
cfx run -p myDevProfile
堆栈跟踪:
function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed> of App.CACountryDetectionViewController.receivedWhereAmI (App.CACountryDetectionViewController)(ObjectiveC.NSNotification) -> ()
in CACountryDetectionViewController.swift, line 62
function signature specialization <Arg[0] = Owned To Guaranteed, Arg[1] = Owned To Guaranteed> of App.CACountryDetectionViewController.receivedWhereAmI (App.CACountryDetectionViewController)(ObjectiveC.NSNotification) -> () (CACountryDetectionViewController.swift:62)
@objc App.CACountryDetectionViewController.receivedWhereAmI (App.CACountryDetectionViewController)(ObjectiveC.NSNotification) -> () (CACountryDetectionViewController.swift:0)
__CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 16
CACountryDetectionViewController.swift
__37-[CAManager postNotification:object:]_block_invoke (CAManager.m:95)
viewDidLoad中:
internal func receivedWhereAmI(notification: NSNotification) {
if let response = notification.object as? CAWhereAmIResponse {
whereAmIState = .Finished
defaultCity = response.cities?.objectForKey(response.country.defaultCity) as? CACity // 62
setCountry(response.country)
} else {
failedToReceiveWhereAmI()
}
}
deinit:addObserver("receivedWhereAmI:", name: CACountryManagerReceivedWhereAmINotification)
有人可以向我解释发生了什么吗?
答案 0 :(得分:0)
我也一直都会遇到这些错误。通常最好检查异常是什么。在你的情况下,我假设它应该是:
"unexpectedly found nil while unwrapping an Optional value"
我认为问题可能在于response.country.defaultCity 由于if unwrapping语句,可以安全地假设响应不是。但是response.country可能是nil,或者是response.country.defaultCity,然后可以抛出异常。