1. mikeabdullah
  2. BWToolkit

Commits

Mike Abdullah  committed bdafd86

Added -[BWTabViewController countOfViewControllers] to improve efficiency and ease leak hunting

  • Participants
  • Parent commits 36a6578
  • Branches default

Comments (0)

Files changed (2)

File BWTabViewController.h

View file
  • Ignore whitespace
 #pragma mark Managing the View Controllers
 
 @property(nonatomic, copy, readonly) NSArray *viewControllers;
+- (NSUInteger)countOfViewControllers;  // improves efficiency & eases leak hunting
+
 - (void)insertViewController:(NSViewController *)controller atIndex:(NSUInteger)index;
 - (void)addViewController:(NSViewController *)controller;
 - (void)removeViewController:(NSViewController *)controller;

File BWTabViewController.m

View file
  • Ignore whitespace
     return [[_viewControllers copy] autorelease];
 }
 
+- (NSUInteger)countOfViewControllers;
+{
+    return [_viewControllers count];
+}
+
 - (void)insertViewController:(NSViewController *)controller atIndex:(NSUInteger)index;
 {
     // Store controller
-    NSArray *oldViewControllers = [self viewControllers];
+    NSUInteger oldCount = [self countOfViewControllers];
     [_viewControllers insertObject:controller atIndex:index];
     
      
     
     
     //  If this was the first controller to be inserted, also want to force it to be selected otherwise NSTabView doesn't report a change to selectedIndex
-    if ([oldViewControllers count] == 0) [self setSelectedViewController:controller];
+    if (oldCount == 0) [self setSelectedViewController:controller];
 }
 
 - (void)addViewController:(NSViewController *)controller;
 {
-    [self insertViewController:controller atIndex:[[self viewControllers] count]];
+    [self insertViewController:controller atIndex:[self countOfViewControllers]];
 }
 
 - (void)removeViewController:(NSViewController *)controller;