Objective C和Firebase

时间:2016-10-13 23:45:36

标签: ios objective-c firebase firebase-realtime-database

我正在尝试从Firebase获取数据,然后更新表格(reloading data)。

-(void) findEvents{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group = dispatch_group_create();

    // Add a task to the group
    dispatch_group_async(group, queue, ^{
        [self fetchData];
    });

    // Add another task to the group
    dispatch_group_async(group, queue, ^{
        [self reloadTableData];
    });

    // Add a handler function for when the entire group completes
    // It's possible that this will happen immediately if the other methods have already finished
    dispatch_group_notify(group, queue, ^{
        [self enjoyAfterwards];
    });
}
-(void)fetchData{
    [[ref child:@"calendar_event" ] observeSingleEventOfType:FIRDataEventTypeValue withBlock:^(FIRDataSnapshot * _Nonnull snapshot) {

        for(FIRDataSnapshot* snap in snapshot.children){
            [self.allEvents addObject:[[GAEvent alloc] initWithParams: snap]];

        }
    }];
}
-(void)reloadTableData{
    NSLog(@"reloading table data");
}
-(void) enjoyAfterwards{
    NSLog(@"enjoying");
}

这是我的reference。但我得到以下输出:

reloading table data
enjoying
// data is fetched

在Swift中,我可以使用callbacks来实现这一目标。我如何在Objective-C

中执行此操作

0 个答案:

没有答案