Сбой вызван только после iOS13, который я не могу воспроизвести - PullRequest
0 голосов
/ 09 ноября 2019

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
}

1 Ответ

1 голос
/ 09 ноября 2019

сеттер может быть вызван до создания всей иерархии представления.

try

private var tableSections = TableData() {
    didSet {
        DispatchQueue.main.async {
            self.tableView?.reloadData()
        }
    }
}
...