1
我試圖使火力地堡的持久性,但我的代碼保持與崩潰:斯威夫特火力地堡持久
類型的未捕獲的異常
NSException
我已經試過我的viewDidLoad下的代碼行終止以及在DataService下,但我仍然遇到同樣的崩潰。什麼做我需要做來解決這個問題,我面對
import UIKit
import Firebase
class HomeTeamSelectionVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
var club: Clubs!
var player = [Players]()
var playerFirstName = String()
var playerLastName = String()
var playerSelected: Bool = false
override func viewDidLoad() {
super.viewDidLoad()
FIRDatabase.database().persistenceEnabled = true //Correct use of????
CLUB_KEY = ""
CLUB_KEY = club.clubKey
tableView.dataSource = self
tableView.delegate = self
DataService.ds.REF_PLAYERS.queryOrdered(byChild: "clubKey").queryEqual(toValue: club.clubKey).observe(.value, with: { (snapshot) in
print("PLAYERS_COUNT: \(snapshot.childrenCount)")
print("PLAYERS_SNAPSHOT: \(snapshot)")
self.player = []
if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] {
for snap in snapshots {
if let playerDict = snap.value as? Dictionary<String, AnyObject> {
let key = snap.key
let players = Players(playerKey: key, dictionary: playerDict)
self.player.append(players)
}
}
}
// self.tableView.reloadData()
}) { (error) in
print(error.localizedDescription)
print("CHET: local error")
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return player.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let players = player[indexPath.row]
if let cell = tableView.dequeueReusableCell(withIdentifier: "HomeTeamPlayersCell") as? HomeTeamPlayersCell {
cell.configureCell(players)
return cell
} else {
return HomeTeamPlayersCell()
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let players: Players!
players = player[indexPath.row]
print (players.playerKey)
print (players.playerFirstName)
print (players.playerLastName)
dismiss(animated: true, completion: nil)
}
}
我把它添加到我的AppDelegate這修正了該問題 – Chet