-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCWCollection.h
96 lines (68 loc) · 3.36 KB
/
CWCollection.h
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// CWCollection.h
//
// Created by Clément Wehrung on 08/04/2014.
// Copyright (c) 2014 Clément Wehrung. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "CWCollectionModelProtocol.h"
@class CWCollection;
/**
* CWCollectionDataSource
*/
@protocol CWCollectionDataSource <NSObject>
typedef void (^CWCollectionPrepareResult)(id <CWCollectionModelProtocol> model, id data);
@required
- (void)collection:(CWCollection *)collection prepareModelWithData:(id)data completion:(CWCollectionPrepareResult)completionBlock;
@optional
- (NSComparisonResult)collection:(CWCollection *)collection sortCompareModel:(id <CWCollectionModelProtocol>)model1 withModel:(id <CWCollectionModelProtocol>)model2;
@end
/**
* CWCollectionDelegate
*/
@protocol CWCollectionDelegate <NSObject>
@optional
- (void)collection:(CWCollection *)collection modelAdded:(id<CWCollectionModelProtocol>)model atIndex:(NSUInteger)index;
- (void)collection:(CWCollection *)collection modelRemoved:(id <CWCollectionModelProtocol>)model atIndex:(NSUInteger)index;
- (void)collection:(CWCollection *)collection modelUpdated:(id <CWCollectionModelProtocol>)model atIndex:(NSUInteger)index;
- (void)collection:(CWCollection *)collection modelMoved:(id <CWCollectionModelProtocol>)model fromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;
- (void)collectionDidStartLoad:(CWCollection *)collection;
- (void)collectionDidEndLoad:(CWCollection *)collection;
- (void)collectionDidChange:(CWCollection *)collection;
@end
/**
* CWCollection
*/
@interface CWCollection : NSObject
@property (nonatomic, strong, readonly) NSMutableArray *models;
@property (nonatomic, strong, readonly) NSArray *filteredModels;
@property (nonatomic, assign) id <CWCollectionDelegate> delegate;
@property (nonatomic, assign) id <CWCollectionDataSource> dataSource;
@property (nonatomic, assign) Class modelClass;
@property (nonatomic, strong) NSPredicate *filter;
@property (nonatomic, assign) BOOL isAscending;
- (id <CWCollectionModelProtocol>)modelWithIdentifier:(NSString *)identifier;
- (id)modelAtIndex:(NSUInteger)index;
- (NSUInteger)indexForInsertingModel:(id <CWCollectionModelProtocol>)model;
- (void)sort;
- (void)refilter;
- (void)addModel:(id <CWCollectionModelProtocol>)model;
- (void)addModel:(id <CWCollectionModelProtocol>)model silent:(BOOL)silent;
- (void)removeModel:(id <CWCollectionModelProtocol>)model;
- (void)removeModel:(id <CWCollectionModelProtocol>)model silent:(BOOL)silent;
- (void)updateModel:(id <CWCollectionModelProtocol>)model;
- (void)updateModel:(id <CWCollectionModelProtocol>)model silent:(BOOL)silent;
- (NSUInteger)count;
- (NSUInteger)indexOf:(id <CWCollectionModelProtocol>)model;
- (BOOL)hasModel:(id <CWCollectionModelProtocol>)model;
- (id)objectForKeyedSubscript:(id)key;
- (id)objectAtIndexedSubscript:(NSUInteger)index;
- (id)objectAtIndex:(NSUInteger)index;
// Internal methods
- (void)removeModelWithIdentifier:(NSString *)identifier;
- (void)removeModelWithIdentifier:(NSString *)identifier silent:(BOOL)silent;
- (void)modelAdded:(id <CWCollectionModelProtocol>)model atIndex:(NSUInteger)index;
- (void)modelRemoved:(id <CWCollectionModelProtocol>)model atIndex:(NSUInteger)index;
- (void)modelUpdated:(id <CWCollectionModelProtocol>)model atIndex:(NSUInteger)index;
- (void)modelMoved:(id <CWCollectionModelProtocol>)model fromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;
@end