Skip to content

Commit

Permalink
Get rid of try/catches around removing observers
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Mar 9, 2020
1 parent 670dfec commit 7ec3193
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
12 changes: 5 additions & 7 deletions app/AboutAppearanceViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ @interface AboutAppearanceViewController ()

@implementation AboutAppearanceViewController

- (void)viewDidLoad {
[super viewDidLoad];
- (void)awakeFromNib {
[super awakeFromNib];
[[UserPreferences shared] addObserver:self forKeyPath:@"theme" options:NSKeyValueObservingOptionNew context:nil];
[[UserPreferences shared] addObserver:self forKeyPath:@"fontSize" options:NSKeyValueObservingOptionNew context:nil];
[[UserPreferences shared] addObserver:self forKeyPath:@"fontFamily" options:NSKeyValueObservingOptionNew context:nil];
}

- (void)dealloc {
@try {
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
[[UserPreferences shared] removeObserver:self forKeyPath:@"fontSize"];
[[UserPreferences shared] removeObserver:self forKeyPath:@"fontFamily"];
} @catch (NSException * __unused exception) {}
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
[[UserPreferences shared] removeObserver:self forKeyPath:@"fontSize"];
[[UserPreferences shared] removeObserver:self forKeyPath:@"fontFamily"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
Expand Down
8 changes: 3 additions & 5 deletions app/AboutNavigationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ @interface AboutNavigationController ()

@implementation AboutNavigationController

- (void)viewDidLoad {
[super viewDidLoad];
- (void)awakeFromNib {
[super awakeFromNib];
[[UserPreferences shared] addObserver:self forKeyPath:@"theme" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionInitial context:nil];
}

- (void)dealloc {
@try {
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
} @catch (NSException * __unused exception) {}
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
Expand Down
18 changes: 10 additions & 8 deletions app/AboutViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ @interface AboutViewController ()

@implementation AboutViewController

- (void)awakeFromNib {
[super awakeFromNib];
[self _addObservers];
}

- (void)viewDidLoad {
[super viewDidLoad];
[self _addObservers];
[self _updatePreferenceUI];
}

Expand All @@ -49,13 +53,11 @@ - (void)_addObservers {
}

- (void)_removeObservers {
@try {
UserPreferences *prefs = [UserPreferences shared];
[prefs removeObserver:self forKeyPath:@"capsLockMapping"];
[prefs removeObserver:self forKeyPath:@"fontSize"];
[prefs removeObserver:self forKeyPath:@"launchCommand"];
[prefs removeObserver:self forKeyPath:@"bootCommand"];
} @catch (NSException * __unused exception) {}
UserPreferences *prefs = [UserPreferences shared];
[prefs removeObserver:self forKeyPath:@"capsLockMapping"];
[prefs removeObserver:self forKeyPath:@"fontSize"];
[prefs removeObserver:self forKeyPath:@"launchCommand"];
[prefs removeObserver:self forKeyPath:@"bootCommand"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
Expand Down
6 changes: 2 additions & 4 deletions app/TerminalViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ - (void)viewDidLoad {
object:nil];

[self _updateStyleFromPreferences:NO];
[[UserPreferences shared] addObserver:self forKeyPath:@"theme" options:NSKeyValueObservingOptionNew context:nil];

if (UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad) {
[self.bar removeArrangedSubview:self.hideKeyboardButton];
Expand Down Expand Up @@ -105,6 +104,7 @@ - (void)awakeFromNib {
selector:@selector(processExited:)
name:ProcessExitedNotification
object:nil];
[[UserPreferences shared] addObserver:self forKeyPath:@"theme" options:NSKeyValueObservingOptionNew context:nil];
}

- (void)startNewSession {
Expand Down Expand Up @@ -189,9 +189,7 @@ - (void)showMessage:(NSString *)message subtitle:(NSString *)subtitle {
}

- (void)dealloc {
@try {
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
} @catch (NSException * __unused exception) {}
[[UserPreferences shared] removeObserver:self forKeyPath:@"theme"];
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
Expand Down

0 comments on commit 7ec3193

Please sign in to comment.