Skip to content

Commit

Permalink
Fixed crash with removing observer of layer.sublayers.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbukowski committed Mar 27, 2018
1 parent 7fbbc79 commit 3c62509
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 14 deletions.
1 change: 0 additions & 1 deletion DBDebugToolkit/Classes/DBDebugToolkit.m
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ - (void)newKeyWindowNotification:(NSNotification *)notification {
- (void)windowDidResignKeyNotification:(NSNotification *)notification {
UIWindow *windowResigningKey = notification.object;
[self removeTriggersFromWindow:windowResigningKey];
[self.performanceToolkit windowDidResignKey:windowResigningKey];
}

#pragma mark - Performance toolkit
Expand Down
7 changes: 0 additions & 7 deletions DBDebugToolkit/Classes/Performance/DBPerformanceToolkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,6 @@
*/
- (void)updateKeyWindow:(UIWindow *)window;

/**
Removes the widget from the old key window.
@param window The window that resigned key. It should have the widget removed.
*/
- (void)windowDidResignKey:(UIWindow *)window;

/**
Returns time in seconds between the measurements.
*/
Expand Down
8 changes: 2 additions & 6 deletions DBDebugToolkit/Classes/Performance/DBPerformanceToolkit.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ - (void)setIsWidgetShown:(BOOL)isWidgetShown {
}

- (void)addWidgetToWindow:(UIWindow *)window {
[self.widget.superview removeObserver:self forKeyPath:@"layer.sublayers"];
[window addSubview:self.widget];
// We observe the "layer.sublayers" property of the window to keep the widget on top.
[window addObserver:self
Expand All @@ -112,14 +113,9 @@ - (void)updateKeyWindow:(UIWindow *)window {
[self addWidgetToWindow:window];
}

- (void)windowDidResignKey:(UIWindow *)window {
[window removeObserver:self forKeyPath:@"layer.sublayers"];
}

-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
// We want to keep the widget on top of all the views.
UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
[keyWindow bringSubviewToFront:self.widget];
[self.widget.superview bringSubviewToFront:self.widget];
}

#pragma mark - Performance Measurement
Expand Down

0 comments on commit 3c62509

Please sign in to comment.