OctoKit 是用于和 Github API 交互的 Cocoa 和 Cocoa Touch 框架,它由 AFNetworking、Mantle、和ReactiveCocoa 建立。
示例代码:
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; RACDisposable *disposable = [[[[self.client fetchUserRepositories] collect] deliverOn:RACScheduler.mainThreadScheduler] subscribeNext:^(NSArray *repositories) { [self addTableViewRowsForRepositories:repositories]; } error:^(NSError *error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops!" message:@"Something went wrong." delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; [alert show]; }]; // Save the disposable into a `strong` property, so we can access it later. self.repositoriesDisposable = disposable; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; // Cancels the request for repositories if it's still in progress. If the // request already terminated, nothing happens. [self.repositoriesDisposable dispose]; }