From b95cb758c830672f6b780ed0563fd7f7599d29a9 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 2 Jun 2020 14:44:54 -0400 Subject: [PATCH] change to hashtable --- .../MVMCoreNavigationHandler.h | 2 +- .../MVMCoreNavigationHandler.m | 15 +++++---------- .../MVMCoreNavigationOperation.m | 4 ++-- .../MVMCorePresentAnimationOperation.m | 4 ++-- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h index c235315..13df1fa 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.h @@ -26,7 +26,7 @@ @property (nullable, weak, nonatomic) UINavigationController *navigationController; /// A list of possible delegates looking for information. -@property (nonnull, strong, nonatomic) NSPointerArray *delegates; +@property (nonnull, strong, nonatomic) NSHashTable *delegates; // Will navigate appropriately based on the load style - (void)navigateWithLoadObject:(nullable MVMCoreLoadObject *)loadObject viewController:(nonnull UIViewController *)viewController delegate:(nullable NSObject*)delegate completionHandler:(nullable void (^)(void))completionBlock; diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m index c6833d9..107f03f 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m @@ -48,7 +48,7 @@ self.presentationQueue = [[NSOperationQueue alloc] init]; self.presentationQueue.maxConcurrentOperationCount = 1; - self.delegates = (NSPointerArray *)[NSPointerArray weakObjectsPointerArray]; + self.delegates = (NSHashTable *)[NSHashTable weakObjectsHashTable]; } return self; } @@ -56,20 +56,15 @@ #pragma mark - Delegate Handling - (void)addDelegate:(nonnull id )delegate { - [self.delegates addPointer:(__bridge void *)(delegate)]; + [self.delegates addObject:delegate]; } - (void)removeDelegate:(nullable id )delegate { - NSUInteger index = NSNotFound; - for (NSUInteger i = 0; i < self.delegates.count; i++) { - if (delegate == [self.delegates pointerAtIndex:i]) { - index = i; - break; + for (id currentDelegate in [self.delegates allObjects]) { + if (currentDelegate == delegate) { + [self.delegates removeObject:delegate]; } } - if (index != NSNotFound) { - [self.delegates removePointerAtIndex:index]; - } } #pragma mark - Navigation Helpers diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m index adc28cf..999e5d2 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m @@ -237,7 +237,7 @@ if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:willDisplayViewController:)]) { [self.delegate navigationController:navigationController willDisplayViewController:viewController]; } - for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates) { + for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) { if (delegate && [delegate respondsToSelector:@selector(navigationController:willDisplayViewController:)]) { [delegate navigationController:navigationController willDisplayViewController:viewController]; } @@ -249,7 +249,7 @@ if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:displayedViewController:)]) { [self.delegate navigationController:navigationController displayedViewController:viewController]; } - for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates) { + for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) { if (delegate && [delegate respondsToSelector:@selector(navigationController:displayedViewController:)]) { [delegate navigationController:navigationController displayedViewController:viewController]; } diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCorePresentAnimationOperation.m b/MVMCore/MVMCore/PresentationHandling/MVMCorePresentAnimationOperation.m index a93ce12..85c533f 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCorePresentAnimationOperation.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCorePresentAnimationOperation.m @@ -40,7 +40,7 @@ if (self.delegate && [self.delegate respondsToSelector:@selector(viewController:willPresentViewController:)]) { [self.delegate viewController:self.presentingViewController willPresentViewController:self.presentedViewController]; } - for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates) { + for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) { if (delegate && [delegate respondsToSelector:@selector(viewController:willPresentViewController:)]) { [delegate viewController:self.presentingViewController willPresentViewController:self.presentedViewController]; } @@ -51,7 +51,7 @@ if (self.delegate && [self.delegate respondsToSelector:@selector(viewController:didPresentViewController:)]) { [self.delegate viewController:self.presentingViewController didPresentViewController:self.presentedViewController]; } - for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates) { + for (NSObject *delegate in [MVMCoreNavigationHandler sharedNavigationHandler].delegates.allObjects) { if (delegate && [delegate respondsToSelector:@selector(viewController:didPresentViewController:)]) { [delegate viewController:self.presentingViewController didPresentViewController:self.presentedViewController]; }