Xcode swift failed with exit code 254

前端 未结 7 2260
灰色年华
灰色年华 2021-02-07 14:14

I am getting this compiler error in my code and I can\'t figure out why:

:0: error: unable to execute command: Segmentation fault: 11


        
相关标签:
7条回答
  • 2021-02-07 14:23

    I had this error and the bug was solved in Beta 7 available online today.

    0 讨论(0)
  • 2021-02-07 14:30

    I'm getting the same error when adopt NSTextViewDelegate protocol for my class. If I remove that protocol, compilation goes fine. Strange indeed.

    0 讨论(0)
  • 2021-02-07 14:34

    This is a Swift compiler bug, apparently testing for two or more implicitly unwrapped optionals causes the compiler to crash under some/many circumstances. Use Apple's Bugreporter to file this issue, mark it as duplicate of rdar://17212295.

    Example

    Here's a minimal example that crashes with the same error:

    let a: String!
    let b: String!
    
    if a && b {
        println("have both")
    }
    

    Compile on command line as follows and witness the same crash:

    $ xcrun swift -v -g crash.swift
    
    0 讨论(0)
  • 2021-02-07 14:34

    In my case, i was calling an objective-c function from swift through bridge. Signature was like -

        - (SomeReturnType *)getSomething:(SomeOptions *)options
                              success:(void (^)(NSArray *response))success
                              failure:(void (^)(NSError *error))failure;
    

    From swift, i was calling it as follows and getting compile error as "Xcode swift failed with exit code 254" -

        ObjCClass().getSomething(nil, success: {(response : Array!) in
    
    
            }, failure: {(error: NSError!)  in
    
            })
    

    changing it to following worked for me -

         ObjCClass().getSomething(nil, success: {(response : [AnyObject]!) in
    
    
            }, failure: {(error: NSError!)  in
    
            })
    
    0 讨论(0)
  • 2021-02-07 14:45

    I am getting this same error when I try to extend NSArray to have a foreach method:

    extension NSArray {
    
        func foreach(f: (AnyObject -> ())) {
            for elem in self {
                f(elem)
            }
        }
    }
    

    It would appear that extending NSArray with func that takes a function argument will cause the same problems. I worked around the issue by defining a forEachInArray function that takes the NSArray as an argument:

    func forEachInArray<T>(array: NSArray, f: (AnyObject -> ())) {
        for elem in array {
            f(elem)
        }
    }
    
    0 讨论(0)
  • 2021-02-07 14:46

    For the sake of providing other possible causes and how to fix them; I was trying to set the region of a map view within in dispatch block. If I commented out the setting of the region, the error goes away.

        dispatch_once(&centerMapLocation, {
    //                var theSpan: MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
    //                var theRegion: MKCoordinateRegion = MKCoordinateRegionMake(manager.location.coordinate, theSpan)
    //                self.map.setRegion(theRegion, animated: true)
                    })
            }
    
    0 讨论(0)
提交回复
热议问题