-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataProviderProtocol.h
More file actions
38 lines (29 loc) · 1.49 KB
/
DataProviderProtocol.h
File metadata and controls
38 lines (29 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// DataProviderProtocol.h
// CodeChallenge
//
// Created by alexey novikov on 31.03.2018.
//
#import <Foundation/Foundation.h>
@protocol DataConsumer;
// for each of two of our UIViewControllers there will be two different objects implementing this protocol.
// UIViewControllers will have strong references to those objects, and provide a callback reference to themselves via
// the `dataConsumer` property.
// Each object that will implement this method will have an NSFetchedResultsController instance inside of it,
// and will be the delegate for that NSFetchedResultsController. These implementation details are never exposed,
// thus providing abstraction for the data layer.
@protocol DataProviderProtocol <NSObject>
@optional
- (id)cellModelAtRow:(NSUInteger)row;
@property (nonatomic, readonly) NSUInteger numberOfRows;
// our UIViewController. will be notified in two different cases:
// 1. when the incorporated NSFetchedResultsController fires controllerDidChangeContent: or
// 2. an image has been downloaded for a row.
@property (weak, nonatomic) id<DataConsumer> dataConsumer;
@end
// UIViewControllers will implement this and decide whether or not to reload the data for the entire table,
// or for just one row, in case of the image download
@protocol DataConsumer <NSObject>
- (void)dataProvider:(id<DataProviderProtocol>)dataProvider didChangeImageForRowAtIndex:(NSUInteger)index;
- (void)dataProviderDidChangeData:(id<DataProviderProtocol>)dataProvider
@end