Swift – Error : Command failed due to signal : Segmentation fault: 11


I am trying to get an array from dictionary, but I am getting an error for below line

self.items = self.dataDictionary["geoNames"] as NSArray

Complete code is as below

var dataDictionary: AnyObject!
var items: NSArray!

override func viewDidLoad() {

    var url = NSURL(string: "http://api.geonames.org/countryInfoJSON?username=temp")
    var urlRequest = NSURLRequest(URL: url!)

    NSURLConnection.sendAsynchronousRequest(urlRequest, queue:NSOperationQueue(), completionHandler:{ (response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in

        if (data.length > 0 && error == nil){
            self.dataDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil)
            self.items = self.dataDictionary["geoNames"] as NSArray

Best Solution

A Hypothesis: If the editor is - for some reason - unable to parse through your code and make conclusions about the correctness of your code, it might allow you to compile even if you have syntax errors, which might lead to the error you describe.

I was getting this error because of syntax errors. Namely, I was changing a 1D array to a 2D array, but had forgotten to update some of the places it is initialized.

It seems that the editor was unable to pinpoint exactly where the errors were and when I tried compiling, I got the error you are describing. I suspected something funky was going on with the editor because it was flashing between all-white and colored syntax, and throwing the "An internal error happened" error message at the top of the editor.

So if you have this error, manually double-checking your code or undoing your changes one by one until you get to a stage where you can compile successfully might give you a hint of what's going wrong.

Posting because it might be helpful to someone facing a similar issue.

Related Question