我已经在堆栈溢出周围看到了一些,但没有一个能解决我的问题。我尝试删除派生数据,重新输入功能,然后进行清理。唯一有效的是注释掉代码,但我需要我的应用程序的代码。在我更新到Xcode 8并将我的代码更新为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!")
}
})
}
}"
整个功能如下所示:
@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)
}
答案 0 :(得分:1)
对于teamItem.toDictionary
,请尝试teamItem.toDictionary as Any
。