【问题标题】:Swift crash on a line that only has a bracketSwift 在只有括号的行上崩溃
【发布时间】:2015-02-28 04:43:50
【问题描述】:

我很难理解一个程序是如何在只有一个括号的行上崩溃的。我的开源应用 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

可以在here 和代码上下文here 中找到完整的崩溃信息,其中突出显示崩溃发生的行。

【问题讨论】:

  • 请编辑您的问题以包含相关代码和符号化的崩溃日志。链接容易失效,因此您需要在问题中包含相关信息。

标签: ios swift crashlytics


【解决方案1】:

显然,与 Objective-c 应用程序不同,快速崩溃报告并未指明应用程序崩溃的确切位置。这意味着方法中的某些行触发了崩溃,而不是最后的括号。

【讨论】:

  • 能否提供您在何处找到此信息的链接?
  • @user2844801 链接正在重定向。你有这个 devforums.apple.com/message/1106933 的其他来源
  • @user2844801 你知道swift中没有显示崩溃线的确切原因吗
猜你喜欢
  • 2018-07-19
  • 1970-01-01
  • 2014-11-28
  • 1970-01-01
  • 2017-06-29
  • 2015-06-15
  • 2018-10-10
  • 2015-11-23
  • 1970-01-01
相关资源
最近更新 更多