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

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
Родитель
Сommit
f77f5ccdc9

+ 2 - 2
Classes/GlobalStateExplorers/FLEXLiveObjectsTableViewController.m

@@ -224,8 +224,8 @@ static const NSInteger kFLEXLiveObjectsSortBySizeIndex = 2;
 
 
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
     NSString *className = self.filteredClassNames[indexPath.row];
     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
 @end

+ 3 - 1
Classes/GlobalStateExplorers/FLEXObjectListViewController.h

@@ -10,7 +10,9 @@
 
 
 @interface FLEXObjectListViewController : FLEXFilteringTableViewController
 @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)subclassesOfClassWithName:(NSString *)className;
 + (instancetype)objectsWithReferencesToObject:(id)object;
 + (instancetype)objectsWithReferencesToObject:(id)object;
 
 

+ 7 - 1
Classes/GlobalStateExplorers/FLEXObjectListViewController.m

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