2017-09-18 5 views
1

こんにちは、私はちょうど理解することが少し楽に言ったことを作るために私のデータベースの抜粋ですFirebaseクエリに戻るヌル

"events" : { 
    "CCDS" : { 
     "attend:count" : 2, 
     "event:category" : "Seize The Day", 
     "event:city" : "San Francisco", 
     "event:date" : { 
     "end:date" : "08/09/2017", 
     "end:time" : "7:00 PM", 
     "start:date" : "08/09/2017", 
     "start:time" : "5:00 PM" 
     }, 
     "event:description" : "Happy hour is more joyful in the summer thanks to Center City District Sips, which offers discounted drinks and appetizers every Wednesday evening. Catch up with old friends and make a few new ones as Center City’s best bars and restaurants host the summer’s happiest hour every Wednesday from 5-7 p.m. Enjoy $5 cocktails, $4 wine, $3 beers and half-price appetizers at dozens and dozens of bars and restaurants.", 
     "event:imageURL" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_flyers%2FCCDS-compressor.jpg?alt=media&token=bcce3968-1cca-4890-a3d0-d8064bd0d1da", 
     "event:name" : "center city district sips", 
     "event:promo" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_promo_vid%2FMIA%2FBudweiser%20Made%20In%20America%20Festival%202013%20August%2031%20-%20September%201.mp4?alt=media&token=9b4b9d4f-2d6d-4762-a5fd-c72edb943ac4", 
     "event:state" : "PA", 
     "event:street:address" : "660 Chestnut St", 
     "event:zip" : 19130 
    }, 
    "DD" : { 
     "attend:count" : 2, 
     "event:category" : "I Love College", 
     "event:city" : "New York", 
     "event:date" : { 
     "end:date" : "08/26/2017", 
     "end:time" : "5:00 PM", 
     "start:date" : "08/26/2017", 
     "start:time" : "1:00 PM" 
     }, 
     "event:description" : "Help us celebrate the hard work and creativity of the students and demo the iOS apps and games they've built in only 8 weeks! Developers, entrepreneurs, friends, and industry professionals are all welcome to attend", 
     "event:imageURL" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_flyers%2Fmakeschooldemo-compressor.jpg?alt=media&token=1e75d18d-1949-48e8-a208-2ca88cde395b", 
     "event:name" : "demo day", 
     "event:promo" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_promo_vid%2FDD%2FDemo%20Night%202017%20-%20Make%20School%20Product%20College.mp4?alt=media&token=d9adb4b1-5689-4b15-96b2-e18138701526", 
     "event:state" : "PA", 
     "event:street:address" : "394 Broadway", 
     "event:zip" : 10013 
    }, 
    "MIA" : { 
     "attend:count" : 23, 
     "event:category" : "Seize The Night", 
     "event:city" : "San Francisco", 
     "event:date" : { 
     "end:date" : "09/03/2017", 
     "end:time" : "7:00 PM", 
     "start:date" : "09/02/2017", 
     "start:time" : "12:00 PM" 
     }, 
     "event:description" : "Budweiser Made in America Festival is an annual music festival held in Philadelphia and formerly simultaneously held in Los Angeles.Sponsored by Anheuser–Busch and produced by Live Nation, the event features several stages that continuously host live music from a wide range of genres including hip hop, rock, pop, R&B, and EDM.", 
     "event:imageURL" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_flyers%2FMadeInAmerica-compressor.jpg?alt=media&token=1ac6e794-6a1f-4f8a-bdb0-afc91f8ba6ae", 
     "event:name" : "made in america", 
     "event:promo" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_promo_vid%2FMIA%2FBudweiser%20Made%20In%20America%20Festival%202013%20August%2031%20-%20September%201.mp4?alt=media&token=11e5059f-3973-4a74-9c9b-a537b737e0ab", 
     "event:state" : "PA", 
     "event:street:address" : "Ben Franklin Parkway", 
     "event:zip" : 19130 
    }, 
    "MIA2" : { 
     "attend:count" : 2, 
     "event:category" : "Dress To Impress", 
     "event:city" : "Philadelphia", 
     "event:date" : { 
     "end:date" : "09/03/2017", 
     "end:time" : "7:00 PM", 
     "start:date" : "09/02/2017", 
     "start:time" : "12:00 PM" 
     }, 
     "event:description" : "Budweiser Made in America Festival is an annual music festival held in Philadelphia and formerly simultaneously held in Los Angeles. Sponsored by Anheuser–Busch and produced by Live Nation, the event features several stages that continuously host live music from a wide range of genres including hip hop, rock, pop, R&B, and EDM. This is different regardless of the same name in database", 
     "event:imageURL" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_flyers%2Fmadeinamerica2.jpg?alt=media&token=bd5eb5e4-4e22-4412-a34b-2dc6c9ae561e", 
     "event:name" : "made in america", 
     "event:promo" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_promo_vid%2FMIA%2FBudweiser%20Made%20In%20America%20Festival%202013%20August%2031%20-%20September%201.mp4?alt=media&token=11e5059f-3973-4a74-9c9b-a537b737e0ab", 
     "event:state" : "PA", 
     "event:street:address" : "Ben Franklin Parkway", 
     "event:zip" : 19130 
    }, 
    "MIA3" : { 
     "attend:count" : 8, 
     "event:category" : "21 & Up", 
     "event:city" : "Philadelphia", 
     "event:date" : { 
     "end:date" : "09/03/2017", 
     "end:time" : "7:00 PM", 
     "start:date" : "09/02/2017", 
     "start:time" : "12:00 PM" 
     }, 
     "event:description" : "Budweiser Made in America Festival is an annual music festival held in Philadelphia and formerly simultaneously held in Los Angeles. Sponsored by Anheuser–Busch and produced by Live Nation, the event features several stages that continuously host live music from a wide range of genres including hip hop, rock, pop, R&B, and EDM.", 
     "event:imageURL" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_flyers%2Fmadeinamerica3-compressor.jpg?alt=media&token=9166e2fb-ac9d-46d5-b06f-60cffc337b15", 
     "event:name" : "made in america", 
     "event:promo" : "https://firebasestorage.googleapis.com/v0/b/eventful-3d558.appspot.com/o/event_promo_vid%2FMIA%2FBudweiser%20Made%20In%20America%20Festival%202013%20August%2031%20-%20September%201.mp4?alt=media&token=11e5059f-3973-4a74-9c9b-a537b737e0ab", 
     "event:state" : "PA", 
     "event:street:address" : "Ben Franklin Parkway", 
     "event:zip" : 19130 
    } 
    } 
私も、私も、私は、キーのFRを引っ張っています混乱に

eventsbylocation" : { 
    "37%2e7,-122%2e4" : { 
     "event0" : "MIA", 
     "event1" : "CCDS", 
     "event2" : "MIA2", 
     "event3" : "MIA3", 
     "event4" : "DD" 
    }, 
    "40%2e7,-74%2e0" : { 
     "event" : "DD" 
    } 
    } 

をクリアするには、以下が含まれる場所によって、すべてのイベントを保存し、別のノードを持っている

すべてのイベントを選択した場合、すべてのイベントを返すホームカテゴリまたは1つまたは複数のイベントが異なるカテゴリにある場合、そのカテゴリを選択した場合、「日をつかむ」と言うと、CCDSに関するすべての情報。

私のコード設定は、eventsByLocationの各キーに対して、そのキーに基づいてイベントノードのカテゴリフィールドをチェックするというものです。それはしかし、それは何かを返すされていない、関連する情報を返す必要が一致する場合は、以下

この

import Foundation 
import Firebase 
import FirebaseAuth 


struct EventService { 

    static func show(forEventKey eventKey: String, eventCategory: String? = nil, completion: @escaping (Event?) -> Void) { 
     // print(eventKey) 
     let ref = Database.database().reference().child("events").child(eventKey) 
     // print(eventKey) 

      if eventCategory == "Home" || eventCategory == nil || eventCategory == ""{ 
       //pull everything 
       ref.observeSingleEvent(of: .value, andPreviousSiblingKeyWith: { (snapshot,eventKey) in 
        print(snapshot.value ?? "") 
        guard let event = Event(snapshot: snapshot) else { 
         return completion(nil) 
        } 
        completion(event) 
       }) 

      }else{ 
       //pull based off of category 
       print(eventCategory) 
       print("Begin Query By Event Category") 
       var query = ref.queryOrdered(byChild: "event:category").queryEqual(toValue: eventCategory) 
       query.observeSingleEvent(of: .value, with: { (snapshot) in 
        print(snapshot) 

       }, withCancel: { (err) in 
        print("Failed to fetch event data") 
       }) 
      } 


    } 
} 

私が間違って行っているかもしれないもの上の任意の洞察力を扱う私のメソッドのコードですか?この時点では何も返されていないので、それは私のクエリによるものですが、何が間違っているのか分かりません。

答えて

0

私はそのポイントからイベントオブジェクトを引っ張ったときにカテゴリをすでに持っていました。返す前に単純な文字列チェックをしていました。

関連する問題