Michael Williams
Michael Williams

Reputation: 1412

Command failed due to signal: Segmentation fault: 11 after upgrade to Xcode 8 and Swift 3

I've seen a few of these around stackoverflow but none of them solve my problem. I've tried deleting the Derived data, retyping the function, and doing a clean. The only thing that works is commenting out the code but I need the code for my app. The error didn't occur until I updated to Xcode 8 and my code to Swift 3.

1.  While emitting IR SIL function @_TFFC13RLA_Volunteer8TeamsTVC18addBarButtonTappedFT6senderCSo15UIBarButtonItem_T_U0_FCSo13UIAlertActionT_ for expression at [/Volumes/.../Developer/RLA/RLA-Volunteer/RLA Volunteer/TeamsTVC.swift:91:89 - line:109:9] RangeText="{ (action) in
            if let team = alertController.textFields?[0].text {
                if team.characters.count == 0 {
                    let errorAlertController = UIAlertController(title: "Add a team", message: nil, preferredStyle: .alert)
                    self.present(errorAlertController, animated: true, completion: nil)
                    return
                }
                let teamItem = Team(teamName: team)
                let teamsRef = self.ref.child("teams")
                teamsRef.child(team.lowercased()).setValue(teamItem.toDictionary, withCompletionBlock: { (error, success) -> Void in
                    if error != nil {
                        print("Error: \(error!.localizedDescription)")
                    }
                    else {
                        print("Data saved!")
                    }
                })
            }
        }"

The entire function looks like this:

  @IBAction func addBarButtonTapped(sender: UIBarButtonItem) {
        // add teams to list
        let alertController = UIAlertController(title: "Add Team", message: nil, preferredStyle: .alert)
        alertController.addTextField { (textField) in
            textField.placeholder = "Team"
        }
        alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        alertController.addAction(UIAlertAction(title: "Add", style: .default, handler: { (action) in
            if let team = alertController.textFields?[0].text {
                if team.characters.count == 0 {
                    let errorAlertController = UIAlertController(title: "Add a team", message: nil, preferredStyle: .alert)
                    self.present(errorAlertController, animated: true, completion: nil)
                    return
                }
                let teamItem = Team(teamName: team)
                let teamsRef = self.ref.child("teams")
                teamsRef.child(team.lowercased()).setValue(teamItem.toDictionary, withCompletionBlock: { (error, success) -> Void in
                    if error != nil {
                        print("Error: \(error!.localizedDescription)")
                    }
                    else {
                        print("Data saved!")
                    }
                })
            }
        }))
        present(alertController, animated: true, completion: nil)
    }

Upvotes: 3

Views: 128

Answers (1)

matt
matt

Reputation: 536026

For teamItem.toDictionary, try putting teamItem.toDictionary as Any.

Upvotes: 1

Related Questions