react-native-navigation的迁移库

RNNStore.m 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // RNNStore.m
  3. // ReactNativeNavigation
  4. //
  5. // Created by Ran Greenberg on 12/02/2017.
  6. // Copyright © 2017 Wix. All rights reserved.
  7. //
  8. #import "RNNStore.h"
  9. @interface RNNStore ()
  10. @property NSMapTable *containerStore;
  11. @end
  12. @implementation RNNStore
  13. -(instancetype)init {
  14. self = [super init];
  15. self.containerStore = [NSMapTable strongToWeakObjectsMapTable];
  16. return self;
  17. }
  18. -(UIViewController *)findContainerForId:(NSString *)containerId {
  19. return [self.containerStore objectForKey:containerId];
  20. }
  21. - (void)setContainer:(UIViewController*)viewController containerId:(NSString*)containerId {
  22. UIViewController *existingVewController = [self findContainerForId:containerId];
  23. if (existingVewController) {
  24. @throw [NSException exceptionWithName:@"MultipleContainerId" reason:[@"Container id already exists " stringByAppendingString:containerId] userInfo:nil];
  25. }
  26. [self.containerStore setObject:viewController forKey:containerId];
  27. }
  28. - (void)removeContainer:(NSString*)containerId {
  29. [self.containerStore removeObjectForKey:containerId];
  30. }
  31. @end