我正在构建的客户端正在使用带有Octokit的Reactive Cocoa ,到目前为止它进展顺利。但是现在我正处于想要获取存储库集合的地步,并且无法用“RAC方式”来解决这个问题
// fire this when an authenticated client is set
[[RACAbleWithStart([GHDataStore sharedStore], client)
filter:^BOOL (OCTClient *client) {
return client != nil && client.authenticated;
}]
subscribeNext:^(OCTClient *client) {
[[[client fetchUserRepositories] deliverOn:RACScheduler.mainThreadScheduler]
subscribeNext:^(OCTRepository *fetchedRepo) {
NSLog(@" Received new repo: %@",fetchedRepo.name);
}
error:^(NSError *error) {
NSLog(@"Error fetching repos: %@",error.localizedDescription);
}];
} completed:^{
NSLog(@"Completed fetching repos");
}];
我最初假设它-subscribeNext:
会传递一个NSArray
,但现在明白它会发送消息每个返回的“下一个”对象,在这种情况下是一个OCTRepository
.
现在我可以做这样的事情:
NSMutableArray *repos = [NSMutableArray array];
// most of that code above
subscribeNext:^(OCTRepository *fetchedRepo) {
[repos addObject:fetchedRepo];
}
// the rest of the code above
当然,这行得通,但它似乎没有遵循 RAC 启用的功能原则。我真的很想在这里遵守约定。非常感谢 RAC/Octokit 的任何功能!