Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command failed due to signal: Segmentation fault: 11 compile error

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

like image 315
Azat Avatar asked Sep 19 '15 20:09

Azat


People also ask

What causes segmentation fault 11?

1) Segmentation Fault (also known as SIGSEGV and is usually signal 11) occur when the program tries to write/read outside the memory allocated for it or when writing memory which can only be read.In other words when the program tries to access the memory to which it doesn't have access to.

What is Signal 11 segmentation fault?

ANSWER. Signal 11, or officially know as "segmentation fault", means that the program accessed a memory location that was not assigned. That's usually a bug in the program. So if you're writing your own program, that's the most likely cause.

What is segmentation fault 11 python?

Segmentation fault 11 Python Segmentation fault 11 is usually caused by memory allocation issues, and if you're having this problem, be sure to try some of the solutions mentioned above. Related articles. PS Store browser not supported error [Quick fix] The code execution cannot proceed because DLL was not found.


1 Answers

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.

like image 161
Martin R Avatar answered Nov 10 '22 09:11

Martin R