【发布时间】:2017-03-18 06:41:20
【问题描述】:
我有一个函数可以从我的 firebase 数据库中返回一个数组。问题是它总是在返回数据库中的值之前先打印 snap(项目所在的数字,例如 0),例如它会打印 [snap (0) teamname]
我将如何摆脱值开头的这个 snap (num)。也许有某种框架可以从数组中删除某些短语?让我知道谢谢这里是我的代码和数据库。
import UIKit
import Foundation
import Firebase
class CSGOView: UIViewController, UITableViewDelegate, UITableViewDataSource{
var teams: [String] = []
var times: [String] = []
@IBOutlet weak var tableViewTwo: UITableView!
let teamsRef = FIRDatabase.database().reference(fromURL: "can't have this info sorry, basically it goes straight to Teams in the database")
override func viewDidLoad() {
super.viewDidLoad()
getTeamsAndTimes()
}
func getTeamsAndTimes() {
teamsRef.observeSingleEvent(of: .value, with: { (snapshot) in
let d = snapshot.children.allObjects
print(d)
for child in snapshot.children {
print(child)
}
}) { (error) in
print(error.localizedDescription)
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell? = nil
return cell!
}
}
这是显示数据库及其布局的图像。
这是控制台输出
[Snap (0) FaZe Clan, Snap (1) Natus Vincere, Snap (2) Natus Vincere, Snap (3) FaZe Clan, Snap (4) HellRaisers, Snap (5) G2 Esports, Snap (6) G2 Esports, Snap (7) HellRaisers, Snap (8) NRG Esports, Snap (9) Counter Logic Gaming, Snap (10) Counter Logic Gaming, Snap (11) NRG Esports, Snap (12) OpTic Gaming, Snap (13) Rush, Snap (14) Rush, Snap (15) OpTic Gaming]
Snap (0) FaZe Clan
Snap (1) Natus Vincere
Snap (2) Natus Vincere
Snap (3) FaZe Clan
Snap (4) HellRaisers
Snap (5) G2 Esports
Snap (6) G2 Esports
Snap (7) HellRaisers
Snap (8) NRG Esports
Snap (9) Counter Logic Gaming
Snap (10) Counter Logic Gaming
Snap (11) NRG Esports
Snap (12) OpTic Gaming
Snap (13) Rush
Snap (14) Rush
Snap (15) OpTic Gaming
【问题讨论】:
标签: arrays swift database firebase