0

I am experiencing a "Command failed due to signal: Segmentation fault: 11" error when building my app. The code that I supect triggering this error, appears in the viewDidLoad method in a custom class, the entire code for this class follows below.

import UIKit
import Bolts
import Parse
import FBSDKLoginKit
import FBSDKCoreKit
import FBSDKShareKit
import ParseFacebookUtilsV4

class SignUpViewController: UIViewController {

@IBAction func signUp(sender: AnyObject) {
}

@IBOutlet weak var userImage: UIImageView!


@IBOutlet weak var interestedInWomen: UISwitch!


override func viewDidLoad() {
    super.viewDidLoad()


    let graphRequest  = FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, gender"])
    graphRequest.startWithCompletionHandler( {

        (connection, result, error) -> Void in

        if error != nil {
            print(error)

        } else if let result = result {

            PFUser.currentUser()?["gender"] = result["gender"]!
            PFUser.currentUser()?["name"] = result["name"]!
            PFUser.currentUser()?.saveInBackground()


            var userId = result["id"] as String

            var facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "picture?type=large"

            if let fbipicUrl = NSURL(string: facebookProfilePictureUrl) {

                if let data = NSData(contentsOfURL: fbipicUrl) {

                self.userImage = UIImage(data: data)

                }

        }

    }
    })
}

Some output from the error log can be viewed here (there is more output, but this part is what seems relevant to me at the moment):

    1.  While type-checking 'viewDidLoad' at /Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:28:14
    2.  While type-checking expression at [/Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:33:9 - line:62:10] RangeText="graphRequest.startWithCompletionHandler( {

        (connection, result, error) -> Void in

        if error != nil {
            print(error)

        } else if let result = result {

            PFUser.currentUser()?["gender"] = result["gender"]!
            PFUser.currentUser()?["name"] = result["name"]!
            PFUser.currentUser()?.saveInBackground()


            var userId = result["id"] as String

            var facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "picture?type=large"

            if let fbipicUrl = NSURL(string: facebookProfilePictureUrl) {

                if let data = NSData(contentsOfURL: fbipicUrl) {

                self.userImage = UIImage(data: data)

                }

        }

    }
    })"
    3.  While type-checking declaration 0x7ffb2a8175b8 at /Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:47:17
    4.  While type-checking expression at [/Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:47:30 - line:47:46] RangeText="result["id"] as S"
    5.  While type-checking expression at [/Users/oivind/Dropbox/søndagsåpent/ParseServerStarterProject/ParseStarterProject/SignUpViewController.swift:47:30 - line:47:41] RangeText="result["id"]"

I am using the latest release of Xcode 7.3 (but no beta).

What I've found so far is that if I comment out this part of code, the app will build perfectly fine:

    var userId = result["id"] as String
            var facebookProfilePictureUrl = "https://graph.facebook.com/" + userId + "picture?type=large"
            if let fbipicUrl = NSURL(string: facebookProfilePictureUrl) {
                if let data = NSData(contentsOfURL: fbipicUrl) {
                self.userImage = UIImage(data: data)
                }
        }

But I cannot for the life of me figure out what actually is causing this error.

This is my first question here on SO, I have been searching around for a while and I found a similar thread that seems to lead me in the right direction but the answers there did not quite help me resolve my issue, the other thread that appears to have some relevant suggestions can be found here:

Command failed due to signal: Segmentation fault: 11

Strangely, after the build error appeared, an error in Xcode appeared as well where the syntax highlighting that color highlights parts of the code crashes every 60 seconds or so whenever I edit this particular swift file. Now that may be just a random occurence but I might also be relevant in some way (perhaps some parts of this code is so messed up that it not only won't build but it also crashes parts of Xcode :P )

Community
  • 1
  • 1
lundzern
  • 417
  • 3
  • 11
  • Try deleting derived data. I found that it sometimes helps when projects mysteriously won't build. In XCode go to Window -> Project then find your project and delete the derived data. You can also do a Product -> Clean and see if it works. – xlogic Apr 05 '16 at 17:47
  • It did not work, thanks for the tip - though! I'll keep that in mind for other mysterious bugs. – lundzern Apr 05 '16 at 18:32
  • Ok, so I'm zeroing in on the error. I found that if I "hardcode" the userId variable with my own facebook ID instead of trying to obtain the Id from the array, everything works. – lundzern Apr 05 '16 at 19:41

1 Answers1

1

Ok, so after some hours of troubleshooting I was able to isolate the error down to the line that caused it;

var userId = result["id"] as String

The problem was that I had to force unwrap the contents of the results array, so for me the solution was to just barely modify that line to look like this;

let userId = result["id"]! as! String

Now why the compiler crashed like it did, I don't know. I would have hoped for a more descriptive error message (or maybe I just don't have the experience to read Xcode's error logs yet).

Either way, the bug is out of the way and the app compiles just as I want it to so I'm happy.

lundzern
  • 417
  • 3
  • 11