Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Table View Adapter
@interface TableViewAdapter : NSObject <FRKDataProvider, UITableViewDataSource>
- (instancetype)initWithDataProvider:(id<FRKDataProvider, FRKSectionInfoProvider>)provider
dataPresenter:(id<FRKTableViewDataPresenter>)presenter;
- (void)registerCellsForTableView:(UITableView *)tableView;
@end
@interface FRKTableViewAdapter ()
@property(nonatomic, strong) id<FRKDataProvider, FRKSectionInfoProvider> provider;
@property(nonatomic, strong) id<FRKTableViewDataPresenter> presenter;
@end
@implementation FRKTableViewAdapter
- (instancetype)initWithDataProvider:(id<FRKDataProvider, FRKSectionInfoProvider>)provider
dataPresenter:(id<FRKTableViewDataPresenter>)presenter {
self = [super init];
if (!self) {
return nil;
}
_provider = provider;
_presenter = presenter;
return self;
}
- (void)registerCellsForTableView:(UITableView *)tableView {
[self.presenter registerCellsForTableView:tableView];
}
#pragma mark - FRKDataProvider
- (id)itemAtIndexPath:(NSIndexPath *)indexPath {
return [self.provider itemAtIndexPath:indexPath];
}
- (NSIndexPath *)indexForItem:(id)item {
return [self.provider indexForItem:item];
}
- (void)loadDataWithCompletion:(void(^)(NSError *error))completion {
[self.provider loadDataWithCompletion:completion];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.provider numberOfSections];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.provider numberOfItemsInSection:section];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
id item = [self itemAtIndexPath:indexPath];
return [self.presenter tableView:tableView cellForItem:item atIndexPath:indexPath];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment