6

I spent a lot of time trying to solve that issue myself and already double checked available answers on SO with the same error. So here are the list of thing that I already excluded from possible reasons:

  1. No issue with frameworks as indicated here. I have created another project with the same frameworks set and all is fine
  2. No issue with SwiftyJSON, also works fine in test project
  3. No compile issues highlighted in the code
  4. I went through two different project.pbxproj files (from my original project and fresh test project) using comparison tool to find some differences in project settings, all the same
  5. I also compared build command options for two projects and all the same

When I go to the Report Navigator and look for each file which wasn't compiled successfully, I found some weird correlation: any file that use some of the API of NSString fails to compile. To prove that assumption I found some file which was compiled successfully and added there the following line of code

let abc = NSString(string: "abc")

and then this file stops to compile too.

So for some files it says that casting String class object with as NSString is invalid, somewhere NSAttributedString/NSString creation fails, in some other places calling compare or rangeOfString was incorrect etc. But when I copy pasted all that pieces of code that caused Segmentation fault error to my new fresh project, they compiled successfully

And of course, that project was compiling fine using Xcode 6 just one day ago

I don't know where to go from here and how to fix that issues, any help will be very useful

UPD

I uploaded the project that doesn't compile to the GitHub

Community
  • 1
  • 1
Azat
  • 6,745
  • 5
  • 31
  • 48
  • 1
    `let abc = NSString(string: "abc")` alone compiles (if "Foundation" is imported). Can you provide minimal sample code exhibiting the problem? – In any case, a compiler segmentation fault is a bug and should be reported to Apple. – Martin R Sep 19 '15 at 20:34
  • @MartinR as I already mentioned, if I create new project, any listed issues go away, all compiles successfully. That happens only on my project that was initially created in the Xcode 6 – Azat Sep 19 '15 at 20:36
  • @MartinR I cleaned my original project and uploaded to the [GitHub](https://github.com/Azat92/BrokenSwift). Please check it – Azat Sep 19 '15 at 21:14
  • For me it was a lengthy function that contained test data array, – Chris Gunawardena Aug 17 '16 at 12:04

2 Answers2

1

In "MYHelpers.h/.m" of your project (presumably from https://github.com/AlexandrGraschenkov/MYHelpers) a NSString category with some utility methods is defined:

#pragma mark - NSString+Utils

@interface NSString (Utils)
- (NSString *)trim; // trim whitespace characters with new line
- (NSString *):(NSString *)appendString;
- (NSURL *)toURL;
- (NSString *)URLEncodedString;
- (NSString *)URLDecodedString;
- (NSString *)lightURLEncodeString;
+ (BOOL)emailValidate:(NSString *)email;
- (CGSize)sizeForStringWithFont:(UIFont *)font constrainedToSize:(CGSize)size;
- (id)JSON;
@end

The second method

- (NSString *):(NSString *)appendString;

has an empty selector name. This is allowed in Objective-C, and you can call the method with

NSString *foobar = [@"foo" :@"bar"];

(I don't know if the method was intentionally defined with an empty selector name – I wouldn't recommend it.)

But it causes the Swift compiler to crash. This happens only if NSString is referenced somewhere in the Swift code. (The compiler should never crash, no matter how malformed the input is, so I would recommend to file a bug report at Apple).

You can rename the method to

- (NSString *)appendString:(NSString *)appendString;

(or simply remove it if you don't need it in your project), that should solve the problem.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
0

I had also faced same problem in my project. See my screen shot My scenario: Find the scenario below in which I had found this bug at my end. 1. I am using my objective- C code in my swift project. 2. Basically It was a category class of UIImage which I was using in my code.

Reason of this bug: As far as I am able to judge that complier was confused with some bit code and it was not able to show exact reason. So it was throwing this below message:

Command failed due to signal: Segmentation fault:11

My solution: I just imported #import <UIKit/UIKit.h> in my category class header file and my bug has been resolved instantly.

Happy to help you!!

Himanshu Agnihotri
  • 2,360
  • 4
  • 23
  • 30