斯威夫特火力地堡持久

我试图使火力地堡的持久性,但我的代码保持与崩溃:斯威夫特火力地堡持久

类型的未捕获的异常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)

}

}

回答:

从Firebase documentation for persistenceEnabled property:

注意,这个属性必须创建第一个数据库引用前设置,只需要调用一次每个应用。

因此,标准的做法是将其设置一次AppDelegate类。例如:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

FIRApp.configure()

FIRDatabase.database().persistenceEnabled = true

...

return true

}

以上是 斯威夫特火力地堡持久 的全部内容, 来源链接: utcz.com/qa/266370.html

回到顶部