WilddogObjects是一个回调,用几个类配合wilddog实现一个同步的NSDictionary;
// 在viewDidLoad中
self.wilddog = [[Wilddog alloc] initWithUrl:@"https://fake.wilddogio.com/stuff"];
self.dictionary = [NSMutableDictionary dictionary];
self.collection = [[WilddogCollection alloc] initWithNode:wilddog dictionary:dictionary type:[User class]];
[self.collection didAddChild:^(User * user) {
NSLog(@"New User %@", user);
[self.tableView reloadData];
}];
User * me = [User new];
me.name = @"me";
[self.collection addObject:me];
###我们怎么去运行一个tableView呢
就是使用字典的所有数据去加载它。 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [self.dictionary.allValues count]; }
告诉你什么类型的数据在集合中传递,另外,你能够使用'factory'初始化方法去创建WilddogCollection
self.collection = [[WilddogCollection alloc] initWithNode:wilddog dictionary:dictionary factory:^(NSDictionary* value) {
return [User new];
}];
在你的对象中,wilddog内部会调用setValuesForKeysWithDictionary去设置值
你的类应该实现 Objectable协议,以便WilddogCollection把它转化为字典
-(NSDictionary*)toObject {
return [self dictionaryWithValuesForKeys:@[@"name"]];
}
###另外,移除和更新所有处理
当他们改变时使用didAddChild, didRemoveChild 和 didUpdateChild去修改
self.connection = [[WilddogConnection alloc] initWithWilddogName:@"mywilddogname" onConnect:^{
[self connectToLobby];
} onDisconnect:^{
[self showDiconnectedScreen];
}];
如果在使用过程中有任何问题,请提 issue ,我会在 Github 上给予帮助。
MIT http://wilddog.mit-license.org/
We would like to thank the following projects for helping us achieve our goals:
Open Source:
- ios-firebase-objects FirebaseObjects is a repo with a few classes to make common firebase tasks easier