Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何删除“;snap";在firebase中数组中的项之前_Arrays_Swift_Database_Firebase - Fatal编程技术网

Arrays 如何删除“;snap";在firebase中数组中的项之前

Arrays 如何删除“;snap";在firebase中数组中的项之前,arrays,swift,database,firebase,Arrays,Swift,Database,Firebase,我有一个从firebase数据库返回数组的函数。问题在于,在返回数据库中的值之前,它总是先打印快照(项目所在的编号,例如0),以便打印[snap(0)teamname] 如何去掉值开头的这个快照(num)。也许有某种框架可以从数组中删除某些短语?让我知道谢谢这里是我的代码和数据库 import UIKit import Foundation import Firebase class CSGOView: UIViewController, UITableViewDelegate, UITab

我有一个从firebase数据库返回数组的函数。问题在于,在返回数据库中的值之前,它总是先打印快照(项目所在的编号,例如0),以便打印[snap(0)teamname]

如何去掉值开头的这个快照(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

您需要访问
snapshot.value
以获取您的团队名称

func getTeamsAndTimes() {
    teamsRef.observeSingleEvent(of: .value, with: { (snapshot) in
        self.teams = []
        for child in snapshot.children {
            if let team = (child as! FIRDataSnapshot).value as? String {
                 self.teams.append(team)
            }               
        }
        //Reload the tabelView after that
        self.tableViewTwo.reloadData()
    }) { (error) in
        print(error.localizedDescription)
    }
}
现在在
numberofrowsin部分
返回
teams
array
count
而不是
3

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.teams.count
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "YourIdentifer", for: indexPath)
    cell.textLabel?.text = teams[indexPath.row]
    return cell
}

您需要访问
snapshot.value
以获取您的团队名称

func getTeamsAndTimes() {
    teamsRef.observeSingleEvent(of: .value, with: { (snapshot) in
        self.teams = []
        for child in snapshot.children {
            if let team = (child as! FIRDataSnapshot).value as? String {
                 self.teams.append(team)
            }               
        }
        //Reload the tabelView after that
        self.tableViewTwo.reloadData()
    }) { (error) in
        print(error.localizedDescription)
    }
}
现在在
numberofrowsin部分
返回
teams
array
count
而不是
3

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.teams.count
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = tableView.dequeueReusableCell(withIdentifier: "YourIdentifer", for: indexPath)
    cell.textLabel?.text = teams[indexPath.row]
    return cell
}

我的天啊。你是最好的伙计,整晚都在做这个。谢谢你教我如何更新手机,我真的很感激。请允许我问一下,您是如何在swift中如此擅长编程的?你是否只是在一家swift应用程序制作公司工作?你是否阅读并制作了很多应用程序?对我有什么建议吗?谢谢你的回答,它在Nirav上运行得非常好D@DevinTripp欢迎mate:)mate如果你阅读了apple swift文档,那么你将获得足够的知识来使用swift lang开发应用程序,这不是什么大任务:)你告诉我你阅读了apple的所有文档,这是你使用的唯一资源。我希望它是那么容易。我不太懂语法,所以对我来说有点难。我接受了答案,我真的很感激@我并不是说要阅读整个文档,当您遇到某些特定类型的问题时,您可以阅读本编程指南type@DevinTripp另外,如果你说我会把答案贴在那里,我会检查你的这个问题,这样也会有助于其他人看同样的问题。哦,我的天哪。你是最好的伙计,整晚都在做这个。谢谢你教我如何更新手机,我真的很感激。请允许我问一下,您是如何在swift中如此擅长编程的?你是否只是在一家swift应用程序制作公司工作?你是否阅读并制作了很多应用程序?对我有什么建议吗?谢谢你的回答,它在Nirav上运行得非常好D@DevinTripp欢迎mate:)mate如果你阅读了apple swift文档,那么你将获得足够的知识来使用swift lang开发应用程序,这不是什么大任务:)你告诉我你阅读了apple的所有文档,这是你使用的唯一资源。我希望它是那么容易。我不太懂语法,所以对我来说有点难。我接受了答案,我真的很感激@我并不是说要阅读整个文档,当您遇到某些特定类型的问题时,您可以阅读本编程指南type@DevinTripp此外,我已经检查了你的这个问题,如果你说,我会张贴答案,也因此,这将有助于其他寻找与同一问题。