@@ -28,6 +28,9 @@ public protocol NUXViewControllerBase {
2828 ///
2929 func shouldShowCancelButton( ) -> Bool
3030 func setupCancelButtonIfNeeded( )
31+
32+ /// Notification observers that can be tied to the lifecycle of the entities implementing the protocol
33+ func addNotificationObserver( _ observer: NSObjectProtocol )
3134}
3235
3336/// extension for NUXViewControllerBase where the base class is UIViewController (and thus also NUXTableViewController)
@@ -286,44 +289,17 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
286289 private func setupNotificationsIndicator( ) {
287290 helpNotificationIndicator. isHidden = true
288291
289- wordpressSupportNotificationReceivedObserver = NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationReceived, object: nil , queue: nil ) { [ weak self] _ in
290- self ? . refreshSupportNotificationIndicator ( )
291- }
292- wordpressSupportNotificationClearedObserver = NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationCleared, object: nil , queue: nil ) { [ weak self] _ in
293- self ? . refreshSupportNotificationIndicator ( )
294- }
295- }
296-
297- private var wordpressSupportNotificationReceivedObserver : NSObjectProtocol ? {
298- get {
299-
300- objc_getAssociatedObject ( self , & wordpressSupportNotificationReceivedKey) as? NSObjectProtocol
301- }
302- set {
303- objc_setAssociatedObject ( self , & wordpressSupportNotificationReceivedKey, newValue, . OBJC_ASSOCIATION_RETAIN)
304- }
305- }
306-
307- private var wordpressSupportNotificationClearedObserver : NSObjectProtocol ? {
308- get {
309- objc_getAssociatedObject ( self , & wordpressSupportNotificationClearedKey) as? NSObjectProtocol
310- }
311- set {
312- objc_setAssociatedObject ( self , & wordpressSupportNotificationClearedKey, newValue, . OBJC_ASSOCIATION_RETAIN)
313- }
314- }
315-
316- func removeNotificationObservers( ) {
317- if let wordpressSupportNotificationReceivedObserver {
318- NotificationCenter . default. removeObserver ( wordpressSupportNotificationReceivedObserver)
319- }
320-
321- if let wordpressSupportNotificationClearedObserver {
322- NotificationCenter . default. removeObserver ( wordpressSupportNotificationClearedObserver)
323- }
292+ addNotificationObserver (
293+ NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationReceived, object: nil , queue: nil ) { [ weak self] _ in
294+ self ? . refreshSupportNotificationIndicator ( )
295+ }
296+ )
324297
325- wordpressSupportNotificationReceivedObserver = nil
326- wordpressSupportNotificationClearedObserver = nil
298+ addNotificationObserver (
299+ NotificationCenter . default. addObserver ( forName: . wordpressSupportNotificationCleared, object: nil , queue: nil ) { [ weak self] _ in
300+ self ? . refreshSupportNotificationIndicator ( )
301+ }
302+ )
327303 }
328304
329305 private func layoutNotificationIndicatorView( _ view: UIView , to superView: UIView ) {
@@ -355,6 +331,3 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
355331 WordPressAuthenticator . shared. delegate? . presentSupport ( from: navigationController, sourceTag: source, lastStep: state. lastStep, lastFlow: state. lastFlow)
356332 }
357333}
358-
359- private var wordpressSupportNotificationReceivedKey = 0
360- private var wordpressSupportNotificationClearedKey = 0
0 commit comments