1010
1111@implementation EPAnnotationArray
1212
13+ #pragma mark - Obj Alloc/Dealloc
14+
1315- (id )init
1416{
1517 if (self = [super init ]) {
@@ -26,6 +28,9 @@ - (id)initWithAnnotationArray:(NSArray *)annotations
2628 return self;
2729}
2830
31+ #pragma mark - Collection Mutators
32+
33+
2934- (void )addAnnotations : (NSArray *)annotations
3035{
3136 for (id annotation in annotations)
@@ -69,6 +74,39 @@ - (void)removeAnnotationsConformsToProtocols:(NSArray *)protocols
6974 }
7075}
7176
77+ - (void )removeAnnotationsOfKindOfClass : (Class <MKAnnotation>)cls
78+ {
79+ NSPredicate *predicate = [NSPredicate predicateWithBlock: ^BOOL (id evaluatedObject, NSDictionary *bindings) {
80+ return ![evaluatedObject isKindOfClass: cls];
81+ }];
82+ [_annotationArray filterUsingPredicate: predicate];
83+ }
84+
85+ - (void )removeAnnotationsOfKindOfClasses : (NSArray *)classes
86+ {
87+ for (Class <MKAnnotation> cls in classes) {
88+ [self removeAnnotationsOfKindOfClass: cls];
89+ }
90+ }
91+
92+ - (void )removeAnnotation : (id <MKAnnotation>)annotation
93+ {
94+ if ( ! [annotation conformsToProtocol: @protocol (MKAnnotation)] )
95+ [NSException raise: NSInternalInconsistencyException format: @" annotation should respond to MKAnnotation protocol" ];
96+ [_annotationArray removeObject: annotation];
97+ }
98+
99+ - (void )removeAnnotations : (NSArray *)annotations
100+ {
101+ for (id annotation in annotations)
102+ if (! [annotation conformsToProtocol: @protocol (MKAnnotation)])
103+ [NSException raise: NSInternalInconsistencyException format: @" annotations should contains only objs conforms to MKAnnotation protocol" ];
104+ [_annotationArray removeObjectsInArray: annotations];
105+ }
106+
107+ #pragma mark - Collection Filters/Helpers
108+
109+
72110- (NSArray *)annotationsConformsToProtocol : (Protocol *)protocol
73111{
74112 NSPredicate *predicate = [NSPredicate predicateWithBlock: ^BOOL (id evaluatedObject, NSDictionary *bindings ) {
@@ -103,21 +141,6 @@ - (NSArray *)annotationsOfKindOfClass:(Class<MKAnnotation> )cls
103141 return [_annotationArray filteredArrayUsingPredicate: predicate];
104142}
105143
106- - (void )removeAnnotationsOfKindOfClass : (Class <MKAnnotation>)cls
107- {
108- NSPredicate *predicate = [NSPredicate predicateWithBlock: ^BOOL (id evaluatedObject, NSDictionary *bindings) {
109- return ![evaluatedObject isKindOfClass: cls];
110- }];
111- [_annotationArray filterUsingPredicate: predicate];
112- }
113-
114- - (void )removeAnnotationsOfKindOfClasses : (NSArray *)classes
115- {
116- for (Class <MKAnnotation> cls in classes) {
117- [self removeAnnotationsOfKindOfClass: cls];
118- }
119- }
120-
121144- (NSArray *)annotationsWithinRange : (CLLocationDistance)radius center : (CLLocationCoordinate2D)center
122145{
123146 CLLocation *centerPosition = [[CLLocation alloc ] initWithLatitude: center.latitude longitude: center.longitude];
@@ -129,29 +152,17 @@ - (NSArray *)annotationsWithinRange:(CLLocationDistance)radius center:(CLLocatio
129152 return [_annotationArray filteredArrayUsingPredicate: predicate];
130153}
131154
132- - (void )removeAnnotation : (id <MKAnnotation>)annotation
133- {
134- if ( ! [annotation conformsToProtocol: @protocol (MKAnnotation)] )
135- [NSException raise: NSInternalInconsistencyException format: @" annotation should respond to MKAnnotation protocol" ];
136- [_annotationArray removeObject: annotation];
137- }
138-
139- - (void )removeAnnotations : (NSArray *)annotations
140- {
141- for (id annotation in annotations)
142- if (! [annotation conformsToProtocol: @protocol (MKAnnotation)])
143- [NSException raise: NSInternalInconsistencyException format: @" annotations should contains only objs conforms to MKAnnotation protocol" ];
144- [_annotationArray removeObjectsInArray: annotations];
145- }
146-
147155- (NSUInteger )count
148156{
149157 return [_annotationArray count ];
150158}
151159
160+ #pragma mark - Overridden Methods
161+
162+
152163- (NSUInteger )countByEnumeratingWithState : (NSFastEnumerationState *)state objects : (__unsafe_unretained id [])buffer count : (NSUInteger )len
153164{
154165 return [_annotationArray countByEnumeratingWithState: state objects: buffer count: len];
155166}
156167
157- @end
168+ @end
0 commit comments