Skip to content

WildDogTeam/lib-ios-objects

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WilddogObjects是一个回调,用几个类配合wilddog实现一个同步的NSDictionary;

用Wilddog保持一个同步的Dictionary;

// 在viewDidLoad中
    //初始化 WDGApp
    WDGOptions *option = [[WDGOptions alloc] initWithSyncURL:@"https://<YOUR-FIREBASE-APPID>wilddogio.com"];
    [WDGApp configureWithOptions:option];
    //获取一个指向根节点的 WDGSyncReference 实例
    WDGSyncReference *rootRef = [[WDGSync sync] reference];

    WDGSyncReference *refStaff = [rootRef child:@"stuff"];
    NSMutableDictionary * dictionary = [NSMutableDictionary dictionary];
    WilddogCollection * collection = [[WilddogCollection alloc] initWithNode:refStaff dictionary:dictionary type:[User class]];

    [collection didAddChild:^(User * user) {
    // created remotely or locally, it is called here
    NSLog(@"New User %@", user);
    [self.tableView reloadData];
    }];

    User * me = [User new];
    me.name = @"me";
    [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

你的类应该实现 Objectable协议,以便WilddogCollection把它转化为字典 -(NSDictionary*)toObject { return [self dictionaryWithValuesForKeys:@[@"name"]]; }

###另外,移除和更新所有处理 当他们改变时使用didAddChild, didRemoveChilddidUpdateChild去修改

当链接改变时被修改

self.connection = [[WilddogConnection alloc] initWithWilddogName:@"mywilddogname" onConnect:^{
    [self connectToLobby];
} onDisconnect:^{
    [self showDiconnectedScreen];
}];

## 支持

如果在使用过程中有任何问题,请提 issue ,我会在 Github 上给予帮助。

相关文档

感谢 Thanks

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published