Просмотр исходного кода

Move live instances view controller creation to a factory method on the class.

It makes more sense for this logic to live within the class, and this way we can create live instances view controllers wherever we need them.
Ryan Olson лет назад: 12
Родитель
Сommit
b63d1fe3c1

+ 2 - 0
Classes/Global State Explorers/FLEXInstancesTableViewController.h

@@ -12,4 +12,6 @@
 
 @property (nonatomic, strong) NSArray *instances;
 
++ (instancetype)instancesTableViewControllerForClassName:(NSString *)className;
+
 @end

+ 19 - 0
Classes/Global State Explorers/FLEXInstancesTableViewController.m

@@ -11,6 +11,7 @@
 #import "FLEXObjectExplorerViewController.h"
 #import "FLEXRuntimeUtility.h"
 #import "FLEXUtility.h"
+#import "FLEXHeapEnumerator.h"
 
 @interface FLEXInstancesTableViewController ()
 
@@ -18,6 +19,24 @@
 
 @implementation FLEXInstancesTableViewController
 
++ (instancetype)instancesTableViewControllerForClassName:(NSString *)className
+{
+    const char *classNameCString = [className UTF8String];
+    NSMutableArray *instances = [NSMutableArray array];
+    [FLEXHeapEnumerator enumerateLiveObjectsUsingBlock:^(__unsafe_unretained id object, __unsafe_unretained Class actualClass) {
+        if (strcmp(classNameCString, class_getName(actualClass)) == 0) {
+            // Note: objects of certain classes crash when retain is called. It is up to the user to avoid tapping into instance lists for these classes.
+            // Ex. OS_dispatch_queue_specific_queue
+            // In the future, we could provide some kind of warning for classes that are known to be problematic.
+            [instances addObject:object];
+        }
+    }];
+    FLEXInstancesTableViewController *instancesViewController = [[self alloc] init];
+    instancesViewController.instances = instances;
+    instancesViewController.title = [NSString stringWithFormat:@"%@ (%lu)", className, (unsigned long)[instances count]];
+    return instancesViewController;
+}
+
 - (BOOL)prefersStatusBarHidden
 {
     return YES;

+ 1 - 13
Classes/Global State Explorers/FLEXLiveObjectsTableViewController.m

@@ -201,19 +201,7 @@ static const NSInteger kFLEXLiveObjectsSortByCountIndex = 1;
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
     NSString *className = [self.filteredClassNames objectAtIndex:indexPath.row];
-    const char *classNameCString = [className UTF8String];
-    NSMutableArray *instances = [NSMutableArray array];
-    [FLEXHeapEnumerator enumerateLiveObjectsUsingBlock:^(__unsafe_unretained id object, __unsafe_unretained Class actualClass) {
-        if (strcmp(classNameCString, class_getName(actualClass)) == 0) {
-            // Note: objects of certain classes crash when retain is called. It is up to the user to avoid tapping into instance lists for these classes.
-            // Ex. OS_dispatch_queue_specific_queue
-            // In the future, we could provide some kind of warning for classes that are known to be problematic.
-            [instances addObject:object];
-        }
-    }];
-    FLEXInstancesTableViewController *instancesViewController = [[FLEXInstancesTableViewController alloc] init];
-    instancesViewController.instances = instances;
-    instancesViewController.title = [NSString stringWithFormat:@"%@ (%lu)", className, (unsigned long)[instances count]];
+    FLEXInstancesTableViewController *instancesViewController = [FLEXInstancesTableViewController instancesTableViewControllerForClassName:className];
     [self.navigationController pushViewController:instancesViewController animated:YES];
 }