Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit768ed66

Browse files
committed
Added safety checks when removing editorMode KVO observers (#71)
1 parent330edd3 commit768ed66

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

‎SCXcodeMinimap/IDEEditorArea+SCXcodeMinimap.m

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
staticvoid *IDEEditorAreaEditorModeObservingContext = &IDEEditorAreaEditorModeObservingContext;
1313

14+
@interfaceIDEEditorArea (SCXcodeMinimap_Private)
15+
16+
@property (nonatomic,assign)BOOL observersInstalled;
17+
18+
@end
19+
1420
@implementationIDEEditorArea (SCXcodeMinimap)
1521

1622
+ (void)load
@@ -19,26 +25,22 @@ + (void)load
1925
sc_swizzleInstanceMethod([selfclass],@selector(viewWillUninstall),@selector(sc_viewWillUninstall));
2026
}
2127

22-
- (id<IDEEditorAreaMinimapDelegate>)minimapDelegate
23-
{
24-
returnobjc_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-
3228
- (void)sc_viewDidInstall
3329
{
34-
[selfaddObserver:selfforKeyPath:@"editorMode"options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNewcontext:IDEEditorAreaEditorModeObservingContext];
35-
30+
if(!self.observersInstalled) {
31+
[selfaddObserver:selfforKeyPath:@"editorMode"options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNewcontext:IDEEditorAreaEditorModeObservingContext];
32+
[selfsetObserversInstalled:YES];
33+
}
34+
3635
[selfsc_viewDidInstall];
3736
}
3837

3938
- (void)sc_viewWillUninstall
4039
{
41-
[selfremoveObserver:selfforKeyPath:@"editorMode"];
40+
if(self.observersInstalled) {
41+
[selfremoveObserver:selfforKeyPath:@"editorMode"];
42+
[selfsetObserversInstalled:NO];
43+
}
4244

4345
[selfsc_viewWillUninstall];
4446
}
@@ -52,4 +54,24 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
5254
}
5355
}
5456

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+
returnobjc_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+
5577
@end

‎SCXcodeMinimap/IDEIssueAnnotationProvider+SCXcodeMinimap.m

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
@interfaceIDEIssueAnnotationProvider (SCXcodeMinimap_Private)
1515

16-
@property (nonatomic,assign)BOOLisObservingAnnotations;
16+
@property (nonatomic,assign)BOOLobserversInstalled;
1717

1818
@end
1919

@@ -30,9 +30,10 @@ - (void)sc_providerWillUninstall
3030
{
3131
[selfsc_providerWillUninstall];
3232

33-
if(self.isObservingAnnotations) {
34-
[selfremoveObserver:selfforKeyPath:@"annotations"];
35-
}
33+
if(self.observersInstalled) {
34+
[selfremoveObserver:selfforKeyPath:@"annotations"];
35+
[selfsetObserversInstalled:NO];
36+
}
3637
}
3738

3839
- (void)_didDeleteOrReplaceParagraphForAnnotation:(id)annotation
@@ -54,8 +55,8 @@ - (void)setMinimapDelegate:(id<IDEIssueAnnotationProviderDelegate>)minimapDelega
5455
objc_setAssociatedObject(self,@selector(minimapDelegate), minimapDelegate,OBJC_ASSOCIATION_ASSIGN);
5556

5657
if(minimapDelegate) {
57-
self.isObservingAnnotations =YES;
5858
[selfaddObserver:selfforKeyPath:@"annotations"options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNewcontext:IDEIssueAnnotationProviderIssuesObservingContext];
59+
[selfsetObserversInstalled:YES];
5960
}
6061
}
6162

@@ -68,14 +69,14 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
6869
}
6970
}
7071

71-
- (BOOL)isObservingAnnotations
72+
- (BOOL)observersInstalled
7273
{
73-
return [objc_getAssociatedObject(self,@selector(isObservingAnnotations))boolValue];
74+
return [objc_getAssociatedObject(self,@selector(observersInstalled))boolValue];
7475
}
7576

76-
- (void)setIsObservingAnnotations:(BOOL)isObservingAnnotations
77+
- (void)setObserversInstalled:(BOOL)observersInstalled
7778
{
78-
objc_setAssociatedObject(self,@selector(isObservingAnnotations), @(isObservingAnnotations),OBJC_ASSOCIATION_RETAIN_NONATOMIC);
79+
objc_setAssociatedObject(self,@selector(observersInstalled), @(observersInstalled),OBJC_ASSOCIATION_RETAIN_NONATOMIC);
7980
}
8081

8182
@end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp