Crashlytics一直在记录此崩溃,我似乎无法复制。我已经查看了代码,找不到任何可能导致此崩溃的内容。
奇怪的是,它自iOS13发行以来才出现。所有崩溃都在安装了iOS13的设备上。在iOS13之前,这种崩溃从未发生过。这段特殊的代码已经存在了两年多了。
任何人都可以提出导致此问题的原因吗?
谢谢。
Crashed: com.apple.main-thread
0 Spotted by 0x104eaf2c0 partial apply for closure #1 in CitiesListViewController.tableSections.didset + 35 (CitiesListViewController.swift:35)
1 Spotted by 0x104ee8508 thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>)
2 libdispatch.dylib 0x1b48b1610 _dispatch_call_block_and_release + 24
3 libdispatch.dylib 0x1b48b2184 _dispatch_client_callout + 16
4 libdispatch.dylib 0x1b489535c _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 996
5 CoreFoundation 0x1b4b623c4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
6 CoreFoundation 0x1b4b5d3b8 __CFRunLoopRun + 2004
7 CoreFoundation 0x1b4b5c8bc CFRunLoopRunSpecific + 464
8 GraphicsServices 0x1be9c8328 GSEventRunModal + 104
9 UIKitCore 0x1b8bf26d4 UIApplicationMain + 1936
10 Spotted by 0x104e95c00 main + 21 (SBLAppDelegate.swift:21)
11 libdyld.dylib 0x1b49e7460 start + 4
这是我的代码(第35行是self.tableView.reloadData()):
typealias TableData = [SectionData]
typealias SectionData = [String: [Any]]
private var tableSections = TableData() {
didSet {
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
}
数据源代码:
func setupData() {
let sortPurchasedCitiesByAlpha: (CityID, CityID) -> Bool = { (cityId1, cityId2) -> Bool in
guard
let city1 = CitiesManager.shared.city(withId: cityId1),
let city2 = CitiesManager.shared.city(withId: cityId2)
else { assertionFailure("missing cities?"); return false }
return city1.name.lowercased() <= city2.name.lowercased()
}
var sections = TableData()
// reverse to show most recent purchase first
let allPurchased = Array(CitiesManager.shared.purchasedCityIds())
var purchased: [CityID] = []
let lastUsedCityId = Defaults[.lastUsedCity]
if let lastUsedCityId = lastUsedCityId {
// put last used first
let rest = Array(allPurchased.removing(lastUsedCityId))
let restSorted = rest.sorted(by: sortPurchasedCitiesByAlpha)
if allPurchased.contains(lastUsedCityId) { // may have been deleted
purchased.append(lastUsedCityId)
}
purchased.append(contentsOf: restSorted)
} else {
purchased = allPurchased.sorted(by: sortPurchasedCitiesByAlpha)
}
installedSectionPresent = !purchased.isEmpty
if installedSectionPresent {
sections.append(["Installed": purchased])
}
let continents = CitiesManager.shared.allContinentsOfNotPurchasedCities()
continents.forEach { continent in
let cityIds = CitiesManager.shared.cityIdsNotPurchased(forContinent: continent)
sections.append([continent: cityIds])
}
tableSections = sections
}
答案 0 :(得分:1)
setter可能在创建整个视图层次结构之前被调用。
尝试
private var tableSections = TableData() {
didSet {
DispatchQueue.main.async {
self.tableView?.reloadData()
}
}
}