CACountryDetectionViewController

CACountryDetectionViewController

我遇到过很多这样的车祸
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
__37-[CAManager postNotification:object:]_block_invoke (CAManager.m:95)
caccountrydetectionviewcontroller.swift

    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()
      }
    }

视图加载:
addObserver("receivedWhereAmI:", name: CACountryManagerReceivedWhereAmINotification)
单位:NSNotificationCenter.defaultCenter().removeObserver(self)
有人能给我解释一下发生了什么事吗?

最佳答案

我也经常犯这些错误。通常最好检查异常是什么。就你而言,我认为应该是:

"unexpectedly found nil while unwrapping an Optional value"

我认为问题可能出在response.country.defaultCity上
可以安全地假设,由于if unwrapping语句,响应不是零。但是response.country可以是nil,或者response.country.defaultCity,这样就可以抛出一个异常。

关于ios - 函数签名专门化<Arg [0] =保证拥有,Arg [1] =保证拥有>,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32547905/

10-12 04:21