Swift在只有支架的线上崩溃 [英] Swift crash on a line that only has a bracket

查看:156
本文介绍了Swift在只有支架的线上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm struggling to understand how a program can crash on a line with just a bracket. My open-source app, Steppy 2, is having this problem. I have been unable to replicate this myself, but multiple users have reported this problem and have sent crash reports. The crash occurs on the last bracket:

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

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

The full crash information can be found here and the code context here with the line where the crash occurs highlighted.

推荐答案

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

Apparently, swift crash reports don't indicate the exact line the app crashed on, unlike objective-c apps. This means some line in the method triggered the crash, not the final bracket.

这篇关于Swift在只有支架的线上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆