Преглед изворни кода

Push straight to single instances in heap explorer

Take the user straight to the explorer itself if there is only one instance of the selected class
Tanner Bennett пре 6 година
родитељ
комит
f77f5ccdc9

+ 2 - 2
Classes/GlobalStateExplorers/FLEXLiveObjectsTableViewController.m

@@ -224,8 +224,8 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSString *className = self.filteredClassNames[indexPath.row];
-    FLEXObjectListViewController *instancesViewController = [FLEXObjectListViewController instancesOfClassWithName:className];
-    [self.navigationController pushViewController:instancesViewController animated:YES];
+    UIViewController *instances = [FLEXObjectListViewController instancesOfClassWithName:className];
+    [self.navigationController pushViewController:instances animated:YES];
 }
 
 @end

+ 3 - 1
Classes/GlobalStateExplorers/FLEXObjectListViewController.h

@@ -10,7 +10,9 @@
 
 @interface FLEXObjectListViewController : FLEXFilteringTableViewController
 
-+ (instancetype)instancesOfClassWithName:(NSString *)className;
+/// This will either return a list of the instances, or take you straight
+/// to the explorer itself if there is only one instance.
++ (UIViewController *)instancesOfClassWithName:(NSString *)className;
 + (instancetype)subclassesOfClassWithName:(NSString *)className;
 + (instancetype)objectsWithReferencesToObject:(id)object;
 

+ 7 - 1
Classes/GlobalStateExplorers/FLEXObjectListViewController.m

@@ -111,7 +111,7 @@
     return self;
 }
 
-+ (instancetype)instancesOfClassWithName:(NSString *)className {
++ (UIViewController *)instancesOfClassWithName:(NSString *)className {
     const char *classNameCString = className.UTF8String;
     NSMutableArray *instances = [NSMutableArray new];
     [FLEXHeapEnumerator enumerateLiveObjectsUsingBlock:^(__unsafe_unretained id object, __unsafe_unretained Class actualClass) {
@@ -127,6 +127,12 @@
     }];
     
     NSArray<FLEXObjectRef *> *references = [FLEXObjectRef referencingAll:instances];
+    if (references.count == 1) {
+        return [FLEXObjectExplorerFactory
+                explorerViewControllerForObject:references.firstObject.object
+        ];
+    }
+    
     FLEXObjectListViewController *controller = [[self alloc] initWithReferences:references];
     controller.title = [NSString stringWithFormat:@"%@ (%lu)", className, (unsigned long)instances.count];
     return controller;