2016-08-27 10 views
0

「Firebase」のアレイから複数の文字列を一度に照会する方法について考えている人はいませんか?基本的には、の条件を使用するようなクエリです。私は何百もの異なる方法でデータを再構築してみましたが、何も私のために働いていません。また、私はすべてのデータをダンプし、クエリが実行された後、私の配列に一致するためにあまりにも多くのデータを持っています。どんな助けや提案も大歓迎です。Firebaseの文字列の照会

var uniqueStoreId = [“1”, “2”, “3”, “4”, “5”, “6”] 
var posts = [Post]() 

ref.queryOrderedByChild("storeId").queryEqualToValue("\(uniqueStoreId)").observeEventType(.Value, withBlock: {snapshot in 
        if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] { 
         for snap in snapshot{ 
          if let postDict = snap.value as? Dictionary<String, AnyObject> { 
           let key = snap.key 
           let post = Post(postKey: key, postData: postDict) 
           self.posts.insert(post, atIndex: 0) 
          } 
         } 
        } 

     }) 
+0

を楽しむFirebaseの照会機能は、単一の条件を可能にします。場合によっては、複数値のクエリを可能にする方法で値を組み合わせることもできますが、必ずしもそうであるとは限りません。 [トピックに関するこの回答](http://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase)を参照してください。 –

答えて

0

//このような何かをし、その後、1列に追加し、要件ごとに使用し、その配列またはdictioaryかどうかをチェックする。..

    var arrMessage = [MessageFirebase]() 

        if let snapshots = snapshot.children.allObjects as? [FIRDataSnapshot] { 

         //If its a Array then use below method 
         for snap in snapshots { 
          if let postDictionary = snap.value as? Dictionary<String, AnyObject> { 
           let key = snap.key 
           let message = MessageFirebase(key: key, dictionary: postDictionary) 
           // Items are returned chronologically, but it's more fun with the newest jokes first. 

           //if needed 
           arrMessage.insert(message, atIndex: 0) 
          } 
         } 

         //If its a dictionary then use below method 
         if !(arrMessage.count > 0) { 
          let key = snapshot.key 
          let message = MessageFirebase(key: key, dictionary: snapshot.value!) 
          // Items are returned chronologically, but it's more fun with the newest jokes first. 

          //if needed 
          arrMessage.insert(message, atIndex: 0) 
         } 
        } 
関連する問題