我正在尝试从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
?