Swift compiler segmentation fault when building

后端 未结 30 2273
南旧
南旧 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 04:50

    This error happens also if you accidentally declare a variable with a type matching its name:

        var sectionGroup: sectionGroup? { ... }
    
    0 讨论(0)
  • 2020-11-29 04:50

    Xcode 8.2.

    Adding @nonobjc protocol implementation into extension causing segmentation faults. Move @nonobjc protocol implementation into class implementation.

    0 讨论(0)
  • 2020-11-29 04:53

    Seems like the Swift 2 compiler might not have been quite ready for prime-time! In case this helps anyone, I was getting a segmentation fault: 11 due to a mismatch with the variable type in a closure header, specifically in a Parse method, PFQuery.query.findObjectsInBackgroundWithBlock.

    You can see the issue in more detail here: https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/issues/280

    0 讨论(0)
  • 2020-11-29 04:53

    In my case the culprit was accidentally overloading a function expecting an array argument with one with a variadic argument:

    public required init(_ args: Node...) {
    }
    

    When the superclass had it defined as an array:

    public required init(_ args: [Node]) {
    }
    
    0 讨论(0)
  • 2020-11-29 04:56

    This typically happens when the compiler does not have enough information (despite what you think) to guarantee/determine the state of a statement or a variable within a statement.

    For example, imagine you have a dictionary of type [String: String] which you populate with city names as keys and a comma separated list of corresponding zip codes/post codes.

    Imagine that somewhere in your code you want to update the list of corresponding codes:

    myDict[town] += newZipCode + ","
    

    In this case, the compiler will respond with segmentation fault as town might not be in the dictionary and therefore it cannot guarantee that the above statement will have a valid value.

    To resolve this, you should store the current state of myDict[town] in a separate variable allowing you to handle the case of key not in dict and then update the value for the given key:

    myDict[town] = guaranteedValue + "," newZipCode + ","
    

    Unfortunately, it is not always straightforward to determine the root cause so I hope this simple example helps.

    0 讨论(0)
  • 2020-11-29 05:01

    I had this error because I was doing this :

    if(currentMeal?.State == .Deleted){
    
    }
    

    instead of

    if(currentMeal!.State == .Deleted){
    
    }
    

    so I think optional not unwrapped in if condition can cause this error

    0 讨论(0)
提交回复
热议问题