This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 122
/
MGLObserver.h
67 lines (51 loc) · 1.88 KB
/
MGLObserver.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
#import "MGLFoundation.h"
#import "MGLEvent.h"
NS_ASSUME_NONNULL_BEGIN
#pragma mark -
/**
Base class for observers used to receive notifications from a type conforming to
the `MGLObservable` protocol.
Subclasses should only override `-[MGLObserver notifyWithEvent:]`.
*/
MGL_EXPORT
@interface MGLObserver: NSObject
/// A unique identifier that can be used to identify an observer.
@property (nonatomic, readonly) NSUInteger identifier;
/// Primary notification method.
- (void)notifyWithEvent:(MGLEvent*)event;
// TODO: document
- (BOOL)isEqualToObserver:(MGLObserver *)other;
@end
#pragma mark -
/**
The `MGLObservable` protocol declares methods that conforming classes should
implement should they want to observe low-level events of type `MGLEvent`.
Currently only `MGLMapView` implements `MGLObservable`.
*/
MGL_EXPORT
@protocol MGLObservable
/**
Subscribes an `MGLObserver` to a provided set of event types.
`MGLObservable` will hold a strong reference to an `MGLObserver` instance,
therefore, in order to stop receiving notifications (and to avoid memory leaks),
the caller must call unsubscribe with the `MGLObserver` instance used for
the initial subscription.
@param observer an MGLObserver
@param events a set of event types to subscribe to.
*/
- (void)subscribeForObserver:(nonnull MGLObserver *)observer
events:(nonnull NSSet<MGLEventType> *)events;
/**
Unsubscribes an `MGLObserver` from a provided set of event types.
@param observer an MGLObserver
@param events a set of event types to unsubscribe from.
*/
- (void)unsubscribeForObserver:(nonnull MGLObserver *)observer
events:(nonnull NSSet<MGLEventType> *)events;
/**
Unsubscribes an `MGLObserver` from all events (and release the strong reference).
@param observer an MGLObserver
*/
- (void)unsubscribeForObserver:(nonnull MGLObserver *)observer;
@end
NS_ASSUME_NONNULL_END