Xcode 9& Swift 4 - 呈现视图控制器时出现意外崩溃

时间:2017-06-13 04:46:53

标签: ios swift xcode swift4 xcode9

我在使用Xcode 9 Beta 1和Swift 4时遇到了崩溃。 我试图呈现一个视图控制器,但抛出异常,即使我有几个断点来捕获所有异常,Xcode也不会停在任何地方。

使用lldb我能够打印异常,因为Xcode没有这样做。 这是我得到的:

(lldb) po $arg1

-[UIDeviceRGBColor pointSize]: unrecognized selector sent to instance 0x60000067a6c0
(null)

这是堆栈跟踪:

enter image description here

回溯:

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 3.1 5.1
  * frame #0: 0x00000001090e60f1 libobjc.A.dylib`objc_exception_throw
    frame #1: 0x0000000109806494 CoreFoundation`-[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    frame #2: 0x00000001096ff858 CoreFoundation`___forwarding___ + 1432
    frame #3: 0x00000001096ff238 CoreFoundation`__forwarding_prep_0___ + 120
    frame #4: 0x0000000112e9f350 UIFoundation`__NSStringDrawingEngine + 3564
    frame #5: 0x0000000112ea32b2 UIFoundation`-[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 787
    frame #6: 0x000000010a84e96e UIKit`-[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 1022
    frame #7: 0x000000010a84e33b UIKit`-[UILabel textRectForBounds:limitedToNumberOfLines:] + 68
    frame #8: 0x000000010a8543c9 UIKit`-[UILabel _intrinsicSizeWithinSize:] + 167
    frame #9: 0x000000010b242b24 UIKit`-[UITextField _intrinsicSizeWithinSize:] + 238
    frame #10: 0x000000010b0b61ab UIKit`-[UIView(UIConstraintBasedLayout) intrinsicContentSize] + 37
    frame #11: 0x000000010b0b6a00 UIKit`-[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 35
    frame #12: 0x000000010b0b6643 UIKit`-[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 262
    frame #13: 0x000000010b0c0fef UIKit`-[UIView(AdditionalLayoutSupport) _updateSystemConstraints] + 99
    frame #14: 0x000000010b0bf8b7 UIKit`-[UIView(AdditionalLayoutSupport) _sendUpdateConstraintsIfNecessaryForSecondPass:] + 161
    frame #15: 0x000000010b0bfebf UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 1286
    frame #16: 0x000000010b0bfd3e UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 901
    frame #17: 0x000000010b0bfd3e UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 901
    frame #18: 0x000000010b0bfd3e UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 901
    frame #19: 0x000000010b0bfd3e UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededCollectingViews:forSecondPass:] + 901
    frame #20: 0x0000000107d1d1a1 Foundation`-[NSISEngine withBehaviors:performModifications:] + 131
    frame #21: 0x000000010b0c06f0 UIKit`__100-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:]_block_invoke + 90
    frame #22: 0x000000010b0bef7e UIKit`-[UIView(AdditionalLayoutSupport) _withUnsatisfiableConstraintsLoggingSuspendedIfEngineDelegateExists:] + 104
    frame #23: 0x000000010b0c025f UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededWithViewForVariableChangeNotifications:] + 160
    frame #24: 0x000000010b0c134f UIKit`-[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeededWithViewForVariableChangeNotifications:] + 344
    frame #25: 0x000000010a66f414 UIKit`-[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 159
    frame #26: 0x000000010a599e09 UIKit`-[UIPickerView layoutSubviews] + 189
    frame #27: 0x000000010a59d697 UIKit`-[UIPickerView selectedRowInComponent:] + 45
    frame #28: 0x000000010a5982fc UIKit`-[UIPickerView _updateSelectedRows] + 143
    frame #29: 0x000000010a598396 UIKit`-[UIPickerView didMoveToWindow] + 101
    frame #30: 0x000000010a67a8e1 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 1701
    frame #31: 0x000000010a67a530 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 756
    frame #32: 0x000000010a67a530 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 756
    frame #33: 0x000000010a692e45 UIKit`-[UIScrollView _didMoveFromWindow:toWindow:] + 84
    frame #34: 0x000000010a67a530 UIKit`-[UIView(Internal) _didMoveFromWindow:toWindow:] + 756
    frame #35: 0x000000010a66d259 UIKit`__45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
    frame #36: 0x000000010a66d140 UIKit`-[UIView(Hierarchy) _postMovedFromSuperview:] + 828
    frame #37: 0x000000010a67d4ad UIKit`-[UIView(Internal) _addSubview:positioned:relativeTo:] + 1917
    frame #38: 0x000000010a71a82b UIKit`-[UITransitionView transition:fromView:toView:removeFromView:] + 1541
    frame #39: 0x000000010b2c9f29 UIKit`-[UIViewControllerBuiltinTransitionViewAnimator animateTransition:] + 1712
    frame #40: 0x000000010a720845 UIKit`__56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 3003
    frame #41: 0x000000010a5c46cc UIKit`_runAfterCACommitDeferredBlocks + 318
    frame #42: 0x000000010a5b2cef UIKit`_cleanUpAfterCAFlushAndRunDeferredBlocks + 280
    frame #43: 0x000000010a5e3091 UIKit`_afterCACommitHandler + 137
    frame #44: 0x000000010971f507 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
    frame #45: 0x000000010971f45e CoreFoundation`__CFRunLoopDoObservers + 430
    frame #46: 0x00000001097038f4 CoreFoundation`__CFRunLoopRun + 1332
    frame #47: 0x0000000109703149 CoreFoundation`CFRunLoopRunSpecific + 409
    frame #48: 0x000000011182c9d7 GraphicsServices`GSEventRunModal + 62
    frame #49: 0x000000010a5b891d UIKit`UIApplicationMain + 159
    frame #50: 0x00000001076a1cc7 GradePoint`main at AppDelegate.swift:13
    frame #51: 0x000000010d224b65 libdyld.dylib`start + 1

我知道它与无法识别的选择器有关,但我没有对UIDeviceRGBColorPointSize做任何事情。

不太确定会发生什么,当我切换到Xcode 8时,这一切都很好。

如果您想复制,请随意克隆项目here并切换到features/ios11分支。您所要做的就是完成介绍屏幕,然后单击+按钮。事故发生后会立即发生。使用 Xcode 9 Beta 1

运行

我理解这可能是一个测试版错误,但是如果有人有更多的经验,我会很感激一些帮助,如果没有,至少有助于如何提交Xcode错误报告,因为我从来没有做过。< / p>

谢谢!

2 个答案:

答案 0 :(得分:3)

UIDeviceRGBColor技术上是UIColorpointSizeUIFont上的一种方法。执行UILabel的布局时会发生错误。

最可能的原因是您要为UIColor分配UILabel.font个实例。

如果您有一个属性字符串,则会导致例如按属性:

let attributes: [String: Any] = [NSFontAttributeName: UIColor.black]

请注意,由于属性采用Any值,因此没有类型检查,这可能发生在Swift中。

答案 1 :(得分:2)

我尝试下载您的代码并重现崩溃,但我无法看到崩溃。我试过在iPhone 7 Plus模拟器和我的iPhone 6S上运行你的代码,它在两个地方都运行良好。 (我在Xcode 9 Beta 1上运行你的项目)

您是否可以分享有关您正在运行代码的环境的更多详细信息?也许您正在使用的Swift版本设置(选择目标&gt; Build Settings&gt; Swift语言版本)或者您是否已执行Swift 4迁移?我很乐意进一步研究它。

同时,here's how to file a bug report with Apple

[我知道这些内容应该作为评论发布而不是答案,但在撰写本文时我没有足够的声誉点来做到这一点<。>