Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d84f7c4

Browse files
author
Ignacio Romero Zurbuchen
committed
Simplifies notification registration's implementation
1 parent d7e4eeb commit d84f7c4

1 file changed

Lines changed: 38 additions & 35 deletions

File tree

Source/SLKTextViewController.m

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,61 +2225,64 @@ - (void)slk_registerNotifications
22252225
{
22262226
[self slk_unregisterNotifications];
22272227

2228+
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
2229+
22282230
// Keyboard notifications
2229-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_willShowOrHideKeyboard:) name:UIKeyboardWillShowNotification object:nil];
2230-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_willShowOrHideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
2231-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didShowOrHideKeyboard:) name:UIKeyboardDidShowNotification object:nil];
2232-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didShowOrHideKeyboard:) name:UIKeyboardDidHideNotification object:nil];
2231+
[notificationCenter addObserver:self selector:@selector(slk_willShowOrHideKeyboard:) name:UIKeyboardWillShowNotification object:nil];
2232+
[notificationCenter addObserver:self selector:@selector(slk_willShowOrHideKeyboard:) name:UIKeyboardWillHideNotification object:nil];
2233+
[notificationCenter addObserver:self selector:@selector(slk_didShowOrHideKeyboard:) name:UIKeyboardDidShowNotification object:nil];
2234+
[notificationCenter addObserver:self selector:@selector(slk_didShowOrHideKeyboard:) name:UIKeyboardDidHideNotification object:nil];
22332235

22342236
#if SLK_KEYBOARD_NOTIFICATION_DEBUG
2235-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardWillShowNotification object:nil];
2236-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardDidShowNotification object:nil];
2237-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardWillHideNotification object:nil];
2238-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardDidHideNotification object:nil];
2237+
[notificationCenter addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardWillShowNotification object:nil];
2238+
[notificationCenter addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardDidShowNotification object:nil];
2239+
[notificationCenter addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardWillHideNotification object:nil];
2240+
[notificationCenter addObserver:self selector:@selector(slk_didPostSLKKeyboardNotification:) name:SLKKeyboardDidHideNotification object:nil];
22392241
#endif
22402242

22412243
// TextView notifications
2242-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_willChangeTextViewText:) name:SLKTextViewTextWillChangeNotification object:nil];
2243-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didChangeTextViewText:) name:UITextViewTextDidChangeNotification object:nil];
2244-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didChangeTextViewContentSize:) name:SLKTextViewContentSizeDidChangeNotification object:nil];
2245-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didChangeTextViewSelectedRange:) name:SLKTextViewSelectedRangeDidChangeNotification object:nil];
2246-
2247-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didChangeTextViewPasteboard:) name:SLKTextViewDidPasteItemNotification object:nil];
2248-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_didShakeTextView:) name:SLKTextViewDidShakeNotification object:nil];
2244+
[notificationCenter addObserver:self selector:@selector(slk_willChangeTextViewText:) name:SLKTextViewTextWillChangeNotification object:nil];
2245+
[notificationCenter addObserver:self selector:@selector(slk_didChangeTextViewText:) name:UITextViewTextDidChangeNotification object:nil];
2246+
[notificationCenter addObserver:self selector:@selector(slk_didChangeTextViewContentSize:) name:SLKTextViewContentSizeDidChangeNotification object:nil];
2247+
[notificationCenter addObserver:self selector:@selector(slk_didChangeTextViewSelectedRange:) name:SLKTextViewSelectedRangeDidChangeNotification object:nil];
2248+
[notificationCenter addObserver:self selector:@selector(slk_didChangeTextViewPasteboard:) name:SLKTextViewDidPasteItemNotification object:nil];
2249+
[notificationCenter addObserver:self selector:@selector(slk_didShakeTextView:) name:SLKTextViewDidShakeNotification object:nil];
22492250

22502251
// Application notifications
2251-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_willTerminateApplication:) name:UIApplicationWillTerminateNotification object:nil];
2252-
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(slk_willTerminateApplication:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
2252+
[notificationCenter addObserver:self selector:@selector(slk_willTerminateApplication:) name:UIApplicationWillTerminateNotification object:nil];
2253+
[notificationCenter addObserver:self selector:@selector(slk_willTerminateApplication:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
22532254
}
22542255

22552256
- (void)slk_unregisterNotifications
22562257
{
2258+
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
2259+
22572260
// Keyboard notifications
2258-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
2259-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
2260-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidShowNotification object:nil];
2261-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
2261+
[notificationCenter removeObserver:self name:UIKeyboardWillShowNotification object:nil];
2262+
[notificationCenter removeObserver:self name:UIKeyboardWillHideNotification object:nil];
2263+
[notificationCenter removeObserver:self name:UIKeyboardDidShowNotification object:nil];
2264+
[notificationCenter removeObserver:self name:UIKeyboardDidHideNotification object:nil];
22622265

22632266
#if SLK_KEYBOARD_NOTIFICATION_DEBUG
2264-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKKeyboardWillShowNotification object:nil];
2265-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKKeyboardDidShowNotification object:nil];
2266-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKKeyboardWillHideNotification object:nil];
2267-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKKeyboardDidHideNotification object:nil];
2267+
[notificationCenter removeObserver:self name:SLKKeyboardWillShowNotification object:nil];
2268+
[notificationCenter removeObserver:self name:SLKKeyboardDidShowNotification object:nil];
2269+
[notificationCenter removeObserver:self name:SLKKeyboardWillHideNotification object:nil];
2270+
[notificationCenter removeObserver:self name:SLKKeyboardDidHideNotification object:nil];
22682271
#endif
22692272

22702273
// TextView notifications
2271-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidBeginEditingNotification object:nil];
2272-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidEndEditingNotification object:nil];
2273-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKTextViewTextWillChangeNotification object:nil];
2274-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextViewTextDidChangeNotification object:nil];
2275-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKTextViewContentSizeDidChangeNotification object:nil];
2276-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKTextViewSelectedRangeDidChangeNotification object:nil];
2277-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKTextViewDidPasteItemNotification object:nil];
2278-
[[NSNotificationCenter defaultCenter] removeObserver:self name:SLKTextViewDidShakeNotification object:nil];
2274+
[notificationCenter removeObserver:self name:UITextViewTextDidBeginEditingNotification object:nil];
2275+
[notificationCenter removeObserver:self name:UITextViewTextDidEndEditingNotification object:nil];
2276+
[notificationCenter removeObserver:self name:SLKTextViewTextWillChangeNotification object:nil];
2277+
[notificationCenter removeObserver:self name:UITextViewTextDidChangeNotification object:nil];
2278+
[notificationCenter removeObserver:self name:SLKTextViewContentSizeDidChangeNotification object:nil];
2279+
[notificationCenter removeObserver:self name:SLKTextViewSelectedRangeDidChangeNotification object:nil];
2280+
[notificationCenter removeObserver:self name:SLKTextViewDidPasteItemNotification object:nil];
2281+
[notificationCenter removeObserver:self name:SLKTextViewDidShakeNotification object:nil];
22792282

22802283
// Application notifications
2281-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
2282-
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
2284+
[notificationCenter removeObserver:self name:UIApplicationWillTerminateNotification object:nil];
2285+
[notificationCenter removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
22832286
}
22842287

22852288

0 commit comments

Comments
 (0)