Wolfstar
Wolfstar

Reputation: 111

OS X Swift Compiler Error - Segmentation Fault

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.

Upvotes: 0

Views: 122

Answers (1)

Wolfstar
Wolfstar

Reputation: 111

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.

Upvotes: 0

Related Questions