Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
Ios 无法从firebase数据库获取密钥_Ios_Firebase_Swift2_Firebase Realtime Database - Fatal编程技术网

Ios 无法从firebase数据库获取密钥

Ios 无法从firebase数据库获取密钥,ios,firebase,swift2,firebase-realtime-database,Ios,Firebase,Swift2,Firebase Realtime Database,在我的学生程序员生涯中,我思考的时间最长。我想知道 我使用autoChildId添加了密钥。 如何从firebase数据库swift 2获取密钥?我知道如何使用.getKeys()从Android获取 我最好的朋友谷歌教我使用所有的钥匙。然而,我的友谊现在处于绝望的边缘,因为我收到了以下消息,我们的关系将永远失败。海什 我需要它,以便将Firebase数据库中的数据显示到我的tableview中,因为我相信这是空表的问题,就像我对我的项目的关注一样。没有心 以下是我的firebase数据库的外

在我的学生程序员生涯中,我思考的时间最长。我想知道

我使用autoChildId添加了密钥。

  • 如何从firebase数据库swift 2获取密钥?我知道如何使用.getKeys()从Android获取

  • 我最好的朋友谷歌教我使用所有的钥匙。然而,我的友谊现在处于绝望的边缘,因为我收到了以下消息,我们的关系将永远失败。海什

  • 我需要它,以便将Firebase数据库中的数据显示到我的tableview中,因为我相信这是空表的问题,就像我对我的项目的关注一样。没有心
  • 以下是我的firebase数据库的外观:

    这是我的密码:

    func findPlaceToEat(){
        print("inside findPlaceToEat()")
    
        print("Plan price level")
        print(planPriceLevel)
        print("End of price level")
    
        ref = FIRDatabase.database().reference()
    
        ref.child("places_detail").child("price_level").child(planPriceLevel).observeEventType(.ChildAdded, withBlock:{
            (snapshot) in
    
            if let dictionary = snapshot.value?.allKeys! as? [String: AnyObject]{
                let PlaceObj = placeObj(place_name: dictionary["place_name"] as! String, place_type: dictionary["place_type"] as! String, price_range: dictionary["price_range"] as! String, vegan_type:dictionary["vegan_type"] as! String , website: dictionary["website"] as! String)
                print("Whatever")
    
                print(PlaceObj);
                //self.tableView.reloadData()
    
            }
            }, withCancelBlock: nil)
    }
    

    从快照获取密钥的步骤

    snapshot.key
    

    我为我的项目找到了一个解决办法,请大家祈祷我的讲师不要看到这一点

    我所做的是在“保存”按钮内,从数据库中检索值,然后将其保存回Firebase数据库

    ref = FIRDatabase.database().reference()
    
    
        ref.child("hello").child("google! I need a part time job").child(planPriceLevel).observeEventType(FIRDataEventType.ChildAdded, withBlock:{
            (snapshot: FIRDataSnapshot) in
    
            if let dictionary = snapshot.value as? [String: AnyObject]{
                let getPlaceObj = placeObj()
    
                getPlaceObj.setValuesForKeysWithDictionary(dictionary)
                self.PlaceObj.append(getPlaceObj)
    
    
                print("Name " ,getPlaceObj.place_name)
    
    
            }
    
            let place_name = snapshot.value?.objectForKey("place_name") as! String
            let place_type = snapshot.value?.objectForKey("place_type") as! String
            let price_range = snapshot.value?.objectForKey("price_range") as! String
            let vegan_type = snapshot.value?.objectForKey("vegan_type") as! String
            let website = snapshot.value?.objectForKey("website") as! String
    
            print(place_name, place_type, price_range, vegan_type, website)
    
            let savePlan : [String: AnyObject] = ["place_name":place_name, "place_type":place_type, "price_range":price_range, "vegan_type":vegan_type, "website":website]
    
            self.ref.child("can you place hire me as your intern? I am from Singapore!!!").child(self.user!.uid).childByAutoId().setValue(savePlan)
    
    
            }, withCancelBlock: nil)
    

    您需要定义查询orderbykey,如下所示:

      this.afd.list('/yourItems/', {query:{orderByKey :true}}).subscribe((elements) => {
    
                elements.map(element=>{
                  console.log(element.$key);
    
                })
    
            });
    

    对不起,伙计,这对我的案子不起作用。谢谢你的帮助。:)应该能用的,我自己检查过了。您可能根本得不到任何数据。试着检查snapshot.exists()嘿,伙计,你有什么可以分享给我的参考资料吗?非常感谢@rv7284@charlinagnes完成块中的snapshot.key应具有值
    -K..
    (请参阅)。如果不起作用,请显示您尝试过的代码及其作用。@FrankvanPuffelen再次感谢您的帮助,先生。根据我的案例,我得到了swift 2版本的答案。我已经张贴了我的答案。