0

I am making some variable declarations in a NSViewController custom class. The declarations are:

var filterSettings: Dictionary<String, String> = ["Location": "All", "Status": "All", "PPRDate": "All", "Project Manager": "All"]
let locationFilterSettings: Set = ["All", "Newcastle", "Sydney", "ACT & Southern NSW", "Western Sydney", "Grafton"]
let statusFilterSettings: Set = ["All", "Active", "Inactive"]
var PPRDateFilterSettings: Set<NSDate> = []  // this value needs to be set programiticaly by loading up the available PPR Dates --- use PPRDateFilterSettings.insert(dateVariable)
var projectManagerFilterSettings: Set<String> = []  // this value needs to be set programatically by loading up the available PMs

When the program compiles I get one error that shows up in the issues navigator: - a compiler error is not shown against any particular line in the code.

When I go to the issue navigator it shows against this class the following error. All other classes compile correctly with no errors:

"Swift Compiler Error Command failed due to signal: Segmentation fault: 11"

I admit to not knowing how to debug this error.

I do know that if I comment out the let locationFilterSettings.. line in the code that the compiler error goes away.

I have just added this code for the variables shown above and do make any other reference to the filterSettings valuable yet. No other changes have been made to the code which was compiling and running as expected.

Any advice on where/how to debug the issue please let me know. I am not sure what to do next.

I should add that I am running the latest version of Xcode and OSX.

I have also tried playing with optional declaration as suggested in one of the answers here:-->Swift compiler segmentation fault when building but to no avail.

EDIT: Some additional information.

  1. I deleted and re-installed Xcode. The error still occurred.
  2. Having declared the variables within the class I wasn't actually referencing them within any functions so I tried println the variables at a few spots in the code. The error still occurred.
  3. I moved the declarations from the global level within the class to within one of the functions. The error disappeared.

So- three above partially solved the issue for me. I wanted the variables to be available through the class so now I may need to pass them around as parameters (which seems to work). However, I still do not understand why the error was occurring and if it was a syntax thing that I was missing.

Community
  • 1
  • 1
Wolfstar
  • 111
  • 10
  • I've dealt and fixed this nasty segmentation fault before. Unfortunately, it's hard to find and it looks like it can be caused by many different things. The best I can tell you is to be sure the crash is happening where you think it is. When I dealt with this crash, I scrolled down in the issues navigator and it showed me a snippet of my code where the crash was happening. They were like 10 lines, and I had to comment them one by one to see if that line was causing the Swift compiler to go nuts. – Andy Ibanez Jul 18 '15 at 02:39
  • I'd love to add my answer, but the code where it happened is very different to what you have. In my case, the segmentation fault was happening because I was appending a touple to an array using the += operator. I can only assume it is a bug with the Swift compiler. – Andy Ibanez Jul 18 '15 at 02:43
  • I have isolated the error to this line in the code ` let locationFilterSettings: Set = ["All", "Newcastle", "Sydney", "ACT & Southern NSW", "Western Sydney", "Grafton"]` but can not see what might be driving the error. Particularly as it compiles without any problems if this statement is contained within a function rather than as a global variable at the top of the class. – Wolfstar Jul 18 '15 at 06:32

1 Answers1

0

Ok - I have now been able to compile the code without an error with the properties declared at the top of the Class.

The issue was the use of the short form declaration relying on the type of item being inferred.

let propertyName: Set = ["item1", "item2"]

when I initialised the property using the following syntax

let propertyName: Set<String> = ["item1", "item2"]

it compiled without an error. The short form declaration worked when the property was declared within a function.

Wolfstar
  • 111
  • 10