Swift在只有支架的线上崩溃

我很难理解一个程序如何在只有一个括号的行上崩溃。 我的开源应用程序Steppy 2遇到了这个问题。 我自己无法复制此问题,但多个用户报告了此问题并发送了崩溃报告。 崩溃发生在最后一个括号上:

func loadBars() { let graphView = UIView(frame: CGRectZero) graphView.setTranslatesAutoresizingMaskIntoConstraints(false) self.addSubview(graphView) self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[view]|", options: nil, metrics: nil, views: ["view":graphView])) self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[view]-(30)-|", options: nil, metrics: nil, views: ["view":graphView])) let sortedDayKeys = Array(weekData.keys).sorted(<) for var day = 0; day < 7; day++ { let key = sortedDayKeys[day] as String let bar = STPYGraphBar(frame: CGRectZero) bar.dateKey = key bar.steps = weekData[key] bar.divider = divider bar.backgroundColor = UIColor.clearColor() graphView.addSubview(bar) graphView.bringSubviewToFront(bar) bar.createInnerView() addBarContraints(bar) graphView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[bar]|", options: nil, metrics: nil, views: ["bar":bar])) bars.append(bar) } graphView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[bar1][bar2(bar1)][bar3(bar1)][bar4(bar1)][bar5(bar1)][bar6(bar1)][bar7(bar1)]|", options: nil, metrics: nil, views: ["bar1":bars[0],"bar2":bars[1],"bar3":bars[2],"bar4":bars[3],"bar5":bars[4],"bar6":bars[5],"bar7":bars[6]])) } //HERE 

崩溃信息:

  Thread : Crashed: com.apple.main-thread 0 SwiftSteppy 0x0000000100094b2c SwiftSteppy.STPYGraphView.loadBars (SwiftSteppy.STPYGraphView)() -> () (STPYGraphView.swift:108) 1 SwiftSteppy 0x0000000100094100 SwiftSteppy.STPYGraphView.loadBars (SwiftSteppy.STPYGraphView)() -> () (STPYGraphView.swift) 2 SwiftSteppy 0x000000010009100c SwiftSteppy.STPYGraphView.loadWithProgress (SwiftSteppy.STPYGraphView)(CoreGraphics.CGFloat) -> () (STPYGraphView.swift:32) 3 SwiftSteppy 0x0000000100069a34 SwiftSteppy.STPYGraphViewController.loadMainScrollViewContent (SwiftSteppy.STPYGraphViewController)() -> () (STPYGraphViewController.swift:201) 4 SwiftSteppy 0x0000000100067abc SwiftSteppy.STPYGraphViewController.loadDataInterface (SwiftSteppy.STPYGraphViewController)() -> () (STPYGraphViewController.swift:139) 5 SwiftSteppy 0x00000001000713e0 SwiftSteppy.STPYGraphViewController.(loadData (SwiftSteppy.STPYGraphViewController) -> () -> ()).(closure #1).(closure #1) (STPYGraphViewController.swift:76) 6 libdispatch.dylib 0x000000019866d3ac _dispatch_call_block_and_release + 24 7 libdispatch.dylib 0x000000019866d36c _dispatch_client_callout + 16 8 libdispatch.dylib 0x0000000198671980 _dispatch_main_queue_callback_4CF + 932 9 CoreFoundation 0x00000001878e1fa4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 10 CoreFoundation 0x00000001878e004c __CFRunLoopRun + 1492 11 CoreFoundation 0x000000018780d0a4 CFRunLoopRunSpecific + 396 12 GraphicsServices 0x00000001909af5a4 GSEventRunModal + 168 13 UIKit 0x000000018c13eaa4 UIApplicationMain + 1488 14 SwiftSteppy 0x00000001000a5da8 main (STPYAppDelegate.swift:13) 15 libdyld.dylib 0x0000000198696a08 start + 4 

可以在此处找到完整的崩溃信息, 此处的代码上下文以及突发显示崩溃的行。

显然,快速崩溃报告并不表示应用程序崩溃的确切行,与objective-c应用程序不同。 这意味着该方法中的某些行触发了崩溃,而不是最终的括号。