11
11
12
12
static void *IDEEditorAreaEditorModeObservingContext = &IDEEditorAreaEditorModeObservingContext;
13
13
14
+ @interface IDEEditorArea (SCXcodeMinimap_Private)
15
+
16
+ @property (nonatomic , assign ) BOOL observersInstalled;
17
+
18
+ @end
19
+
14
20
@implementation IDEEditorArea (SCXcodeMinimap)
15
21
16
22
+ (void )load
@@ -19,26 +25,22 @@ + (void)load
19
25
sc_swizzleInstanceMethod ([self class ], @selector (viewWillUninstall ), @selector (sc_viewWillUninstall ));
20
26
}
21
27
22
- - (id <IDEEditorAreaMinimapDelegate>)minimapDelegate
23
- {
24
- return objc_getAssociatedObject (self, @selector (minimapDelegate ));
25
- }
26
-
27
- - (void )setMinimapDelegate : (id <IDEEditorAreaMinimapDelegate>)minimapDelegate
28
- {
29
- objc_setAssociatedObject (self, @selector (minimapDelegate ), minimapDelegate, OBJC_ASSOCIATION_ASSIGN );
30
- }
31
-
32
28
- (void )sc_viewDidInstall
33
29
{
34
- [self addObserver: self forKeyPath: @" editorMode" options: NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context: IDEEditorAreaEditorModeObservingContext];
35
-
30
+ if (!self.observersInstalled ) {
31
+ [self addObserver: self forKeyPath: @" editorMode" options: NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context: IDEEditorAreaEditorModeObservingContext];
32
+ [self setObserversInstalled: YES ];
33
+ }
34
+
36
35
[self sc_viewDidInstall ];
37
36
}
38
37
39
38
- (void )sc_viewWillUninstall
40
39
{
41
- [self removeObserver: self forKeyPath: @" editorMode" ];
40
+ if (self.observersInstalled ) {
41
+ [self removeObserver: self forKeyPath: @" editorMode" ];
42
+ [self setObserversInstalled: NO ];
43
+ }
42
44
43
45
[self sc_viewWillUninstall ];
44
46
}
@@ -52,4 +54,24 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
52
54
}
53
55
}
54
56
57
+ - (BOOL )observersInstalled
58
+ {
59
+ return [objc_getAssociatedObject (self , @selector (observersInstalled )) boolValue ];
60
+ }
61
+
62
+ - (void )setObserversInstalled : (BOOL )observersInstalled
63
+ {
64
+ objc_setAssociatedObject (self, @selector (observersInstalled ), @(observersInstalled), OBJC_ASSOCIATION_RETAIN_NONATOMIC );
65
+ }
66
+
67
+ - (id <IDEEditorAreaMinimapDelegate>)minimapDelegate
68
+ {
69
+ return objc_getAssociatedObject (self, @selector (minimapDelegate ));
70
+ }
71
+
72
+ - (void )setMinimapDelegate : (id <IDEEditorAreaMinimapDelegate>)minimapDelegate
73
+ {
74
+ objc_setAssociatedObject (self, @selector (minimapDelegate ), minimapDelegate, OBJC_ASSOCIATION_ASSIGN );
75
+ }
76
+
55
77
@end
0 commit comments