繁体   English   中英

Swift 崩溃报告对我来说没有意义

[英]Swift crash reports don't make sense to me

这是我从 Crashlytics 得到的崩溃日志:

Thread : Crashed: com.apple.main-thread
0  Trenìt!                       0x1000b93e4 SearchHistoryProvider.getMostRecentStations(Int) -> [String] (SearchHistoryProvider.swift)
1  Trenìt!                       0x10007985c specialized MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift:265)
2  Trenìt!                       0x100075414 @objc MasterViewController.onTouchedTextField(UITextField) -> () (MasterViewController.swift)
3  UIKit                          0x186fa0ad0 -[UIApplication sendAction:to:from:forEvent:] + 100
4  UIKit                          0x186fa0a4c -[UIControl sendAction:to:forEvent:] + 80
5  UIKit                          0x186f88740 -[UIControl _sendActionsForEvents:withEvent:] + 436
6  UIKit                          0x186fa9248 -[UIControl touchesBegan:withEvent:] + 400
7  UIKit                          0x186f9fdc0 -[UIWindow _sendTouchesForEvent:] + 376
8  UIKit                          0x186f98b08 -[UIWindow sendEvent:] + 784
9  UIKit                          0x186f68f4c -[UIApplication sendEvent:] + 248
10 UIKit                          0x186f67528 _UIApplicationHandleEventQueue + 6568
11 CoreFoundation                 0x181dd5124 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
12 CoreFoundation                 0x181dd4bb8 __CFRunLoopDoSources0 + 540
13 CoreFoundation                 0x181dd28b8 __CFRunLoopRun + 724
14 CoreFoundation                 0x181cfcd10 CFRunLoopRunSpecific + 384
15 GraphicsServices               0x1835e4088 GSEventRunModal + 180
16 UIKit                          0x186fd1f70 UIApplicationMain + 204
17 Trenìt!                       0x10009b2fc main (AppDelegate.swift:14)```
(edited)

这是我的代码:

MasterViewController.swift:

263    func showRecentStations(textField: UITextField) {
264        textField.text = ""
265        suggestionStations = masterContainerManager!.homeController?.searchHistoryProvider?.getMostRecentStations(10)
266        updateStationsTable(textField)
267    }

SearchHistoryProvider.swift

func getMostRecentStations (maxSize : Int) -> [String] {
    let stationsByOldestArray = getRecentStationsByOldest()
    let stations = NSMutableOrderedSet()
    for i in (0...(stationsByOldestArray.count-1)).reverse() {
        stations.addObject(stationsByOldestArray[i].depStation)
        if stations.count==maxSize {
            return stations.array as! [String]
        }
        stations.addObject(stationsByOldestArray[i].arrStation)
        if stations.count==maxSize {
            return stations.array as! [String]
        }
    }
    return stations.array as! [String]
}

谁能理解崩溃是怎么回事?

我发现了错误:

如果stationsByOldestArray.count为0

for 循环本来是

for i in (0...-1).reverse()

我通过将循环重写为

for i in (0..<stationsByOldestArray.count).reverse()

然而,我认为 Swift 崩溃报告通常毫无帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM