10

私が構築しているクライアントは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 の機能に光を当てていただければ幸いです。

4

2 に答える 2