Swift compiler segmentation fault when building

后端 未结 30 2663
南旧
南旧 2020-11-29 03:59

Adding a (convenient) computed height property to UIView in my UIViewExtension.swift file is causing the Swift compiler to segfault...

30条回答
  •  半阙折子戏
    2020-11-29 05:04

    When you run into a compiler segfault in Swift, you don't get a handy line number and error message. Here's how you can track the problem down:

    1. Create a new file called SegFaultDebugger.swift in your project.
    2. In this new file, define an extension to the class that's giving you problems.
    3. Move a group of methods from the main file to SegFaultDebugger.swift.
    4. Compile.

    At this point, one of three things happens:

    • You still get the segfault in the original file: Move the methods from SegFaultDebugger.swift back to the original file and move a different set of methods into SegFaultDebugger.swift. Repeat
    • You get a segfault in SegFaultDebugger.swift: Great! Now use binary search to pin the segfault down to a specific method until you can figure out what construct is causing it.
    • You get meaningful compiler errors: Great! Fix the errors. Once everything compiles, move your methods back into the original file.

提交回复
热议问题