gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 06:45:44 25 4
gpt4 key购买 nike

这是我从 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 崩溃报告通常毫无帮助!

关于ios - Swift 崩溃报告对我来说没有意义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36489471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com