2016-09-12 12 views
0

私はfirebaseからデータを取得するいくつかの関数を持っています。すべてのデータが取得されるまで、アクティビティインジケータを回転させたい。ディスパッチグループの機能が呼び出されていない - ディスパッチグループの使い方は?

私の問題は、機能が起動していないことです。間違いを検索するために、私はprintステートメントを入力しましたが、これは呼び出されません。

これは私のコードです:

override func viewDidLoad() { 
    super.viewDidLoad() 
    loadingActInd.hidesWhenStopped = true 
    self.loadingActInd.startAnimating()  

    let group = dispatch_group_create() 

    dispatch_group_enter(group) 
    func loadTweetComplete() { 
     dispatch_group_leave(group) 
    } 

    dispatch_group_enter(group) 
    func loadEventsComplete() { 
     dispatch_group_leave(group) 
    } 

    dispatch_group_notify(group, dispatch_get_main_queue()) { 
     self.loadingActInd.stopAnimating() 
     print("deejayTweetsDictionary = \(deejayTweetsDictionary)") 
     print("finished executing") 
    } 

} 

func loadTweetComplete(completionHandler:() ->()) { 

    print("TEST") 

    deejayTweetsDictionary.removeAll() 

    let usersRef = firebase.child("DeejayTweets").child(passedDJ.objectId) 
    usersRef.observeSingleEventOfType(.Value, withBlock: { snapshot in 

     if snapshot.exists() { 

      deejayTweetsDictionary.removeAll() 

      let sorted = (snapshot.value!.allValues as NSArray).sortedArrayUsingDescriptors([NSSortDescriptor(key: "date",ascending: false)]) 

      for element in sorted { 

       deejayTweetsDictionary.append(element as! NSMutableDictionary) 

      } 

     } 

     completionHandler() 
    }) 
} 

func loadEventsComplete(completionHandler:() ->()) { 

    print("TEST") 

    eventDates.removeAll() 

    if passedDJ.objectId != nil { 

     let userRef = firebase.child("djBookings").child(passedDJ.objectId) 

     userRef.observeSingleEventOfType(.Value, withBlock: { (snapshot) in 

      if snapshot.exists() { 

       eventDates.removeAll() 

       let item = (snapshot.value as? NSMutableDictionary)! 

       let allValues = item.allValues 
       for element in allValues { 

        eventDates.append(element as! NSMutableDictionary) 

       } 

      } 

      completionHandler() 
     }) 

    } 
} 

インジケータさえprint("TEST")文が呼び出され、永遠ではなくスピン。私は間違って何をしていますか?ヘルプは非常に感謝しています。

+0

の代わりに* * 'loadTweetComplete'を呼ぶだろう末尾の閉鎖の構文を使用して、あなたがああ...同じ名前の –

+0

を地元のネストされた関数を定義しています。ええと...それは愚かだった...まあ...答えてもらえませんか... –

+0

あなたの助けを大変ありがとうございます。 –

答えて

2
func loadTweetComplete() { 
    dispatch_group_leave(group) 
} 

(ネスト)関数を定義します。あなたが望むのは、 という関数を、与えられた補完ハンドラを引数として呼び出すことです。

loadTweetComplete { 
    dispatch_group_leave(group) 
} 
+1

再度お返事ありがとうございます –

関連する問題