我有幾個客戶抱怨我的應用程序崩潰。我從來沒有能夠重現它。 Crashlitics已檢測到崩潰:解包時出現崩潰可選
func addDevice(unconfiguredDevice: UnconfiguredDevice) {
if let macSegment = unconfiguredDevice.macSegmentFromSSID { <<-CRASH
print("unconfigured mac: \(macSegment)")
if let setupDevice = self.unconfiguredDevices.value.first(where: { Device in Device.macEnd == unconfiguredDevice.macSegmentFromSSID! }) {
setupDevice.unconfiguredDevice = unconfiguredDevice
} else {
self.unconfiguredDevices.value.append(SetupDevice(unconfiguredDevice: unconfiguredDevice))
}
}
}
崩潰類型是EXC_BREAKPOINT。我在這裏看到了其他幾個線程,這種類型的崩潰可能與可選的解包有關,並且確實macSegment方法在那裏返回一個可選項。但我不明白這個問題可能是什麼。 (順便提一下,這種方法用於檢測可通過WAC配置的設備)。
任何想法/提示/建議?
'UnconfiguredDevice'是隱式解包的可選項嗎?如果是這樣,你應該用'?'標記它:'if let macSegment = unconfiguredDevice?.macSegmentFromSSID {' – the4kman
'你試圖強制打開nil值。問題在這裏unconfiguredDevice.macSegmentFromSSID! – iMuzahid
UnconfiguredDevice由WAC返回..我不認爲它是可選的.. macSegment是一個擴展方法,它返回一個可選的。 – user426132