0

I know this question was asked before, but other questions relate to the older Xcode versions and answers suggest that this bug was resolved.

I get this error on the newest Xcode 8.1 (8B62) which is the most recent one (and Swift3) and still can not find a solution for my case.

Happens when:

  • Swift 3 and Objective-C are bridged together.
  • Swift code calls Objective-C method which may throw an error (not in all but in specific cases only, more details in included code snippets below).

I was struggling with this for almost whole day and dissected the essence into the minimum demonstration project capable of reproducing this mysterious error. It is available for everyone on GitHub, so feel free to try and help with this:

UPDATE - Includes solution and explanation to the issue: (thanks to @CodaFi) https://github.com/lukaszmargielewski/SegmentationFault11

Here is the code causing it:

Swift 3 code:

   class SegmentationFault11 {

        let responseProcessor = NetworkResponseProcessor() // Objective-C class
        let url = URL(string: "https://example.com")!

        func epicFail() {
            URLSession.shared.dataTask(with: url) { (data, response, error) in
                do {
                    _ = try self.responseProcessor.process(response, data: data, networkError: error)
                } catch {}
            }.resume()
        }
    }

Objective-C code:

// NetworkResponseProcessor.h

@interface NetworkResponseProcessor : NSObject

- (nullable id)process:(nullable NSURLResponse *)response
                  data:(nullable NSData *)data
          networkError:(nullable NSError *)networkError
                 error:(NSError * _Nonnull * _Nullable)error;

@end
4

0 に答える 0