Skip to content

Commit e63ea4b

Browse files
committed
Group FLEX objects together in the object refs list
1 parent 5a760fb commit e63ea4b

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

Classes/GlobalStateExplorers/FLEXObjectListViewController.m

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,28 @@
2020
#import <malloc/malloc.h>
2121

2222

23+
typedef NS_ENUM(NSUInteger, FLEXObjectReferenceSection) {
24+
FLEXObjectReferenceSectionMain,
25+
FLEXObjectReferenceSectionAutoLayout,
26+
FLEXObjectReferenceSectionKVO,
27+
FLEXObjectReferenceSectionFLEX,
28+
29+
FLEXObjectReferenceSectionCount
30+
};
31+
32+
NSArray<NSString *> * FLEXObjectReferenceSectionTitles() {
33+
return @[
34+
@"", @"AutoLayout", @"Key-Value Observing", @"FLEX"
35+
];
36+
}
37+
38+
NSString const * FLEXTitleForObjectReferenceSection(FLEXObjectReferenceSection section) {
39+
switch (section) {
40+
case FLEXObjectReferenceSectionCount: @throw NSInternalInconsistencyException;
41+
default: return FLEXObjectReferenceSectionTitles()[section];
42+
}
43+
}
44+
2345
@interface FLEXObjectListViewController ()
2446
@property (nonatomic, copy) NSArray<FLEXMutableListSection *> *sections;
2547
@property (nonatomic, copy) NSArray<FLEXMutableListSection *> *allSections;
@@ -38,7 +60,7 @@ @implementation FLEXObjectListViewController
3860
+ (NSPredicate *)defaultPredicateForSection:(NSInteger)section {
3961
// These are the types of references that we typically don't care about.
4062
// We want this list of "object-ivar pairs" split into two sections.
41-
BOOL(^isObserver)(FLEXObjectRef *, NSDictionary *) = ^BOOL(FLEXObjectRef *ref, NSDictionary *bindings) {
63+
BOOL(^isKVORelated)(FLEXObjectRef *, NSDictionary *) = ^BOOL(FLEXObjectRef *ref, NSDictionary *bindings) {
4264
NSString *row = ref.reference;
4365
return [row isEqualToString:@"__NSObserver object"] ||
4466
[row isEqualToString:@"_CFXNotificationObjcObserverRegistration _object"];
@@ -65,28 +87,38 @@ + (NSPredicate *)defaultPredicateForSection:(NSInteger)section {
6587
([row hasPrefix:@"_NSAutoresizingMask"] && [row hasSuffix:@" _referenceItem"]) ||
6688
[ignored containsObject:row];
6789
};
90+
91+
/// These are FLEX classes and usually you aren't looking for FLEX references inside FLEX itself
92+
BOOL(^isFLEXClass)(FLEXObjectRef *, NSDictionary *) = ^BOOL(FLEXObjectRef *ref, NSDictionary *bindings) {
93+
return [ref.reference hasPrefix:@"FLEX"];
94+
};
6895

6996
BOOL(^isEssential)(FLEXObjectRef *, NSDictionary *) = ^BOOL(FLEXObjectRef *ref, NSDictionary *bindings) {
70-
return !(isObserver(ref, bindings) || isConstraintRelated(ref, bindings));
97+
return !(
98+
isKVORelated(ref, bindings) ||
99+
isConstraintRelated(ref, bindings) ||
100+
isFLEXClass(ref, bindings)
101+
);
71102
};
72103

73104
switch (section) {
74-
case 0: return [NSPredicate predicateWithBlock:isEssential];
75-
case 1: return [NSPredicate predicateWithBlock:isConstraintRelated];
76-
case 2: return [NSPredicate predicateWithBlock:isObserver];
105+
case FLEXObjectReferenceSectionMain:
106+
return [NSPredicate predicateWithBlock:isEssential];
107+
case FLEXObjectReferenceSectionAutoLayout:
108+
return [NSPredicate predicateWithBlock:isConstraintRelated];
109+
case FLEXObjectReferenceSectionKVO:
110+
return [NSPredicate predicateWithBlock:isKVORelated];
111+
case FLEXObjectReferenceSectionFLEX:
112+
return [NSPredicate predicateWithBlock:isFLEXClass];
77113

78114
default: return nil;
79115
}
80116
}
81117

82118
+ (NSArray<NSPredicate *> *)defaultPredicates {
83-
return @[[self defaultPredicateForSection:0],
84-
[self defaultPredicateForSection:1],
85-
[self defaultPredicateForSection:2]];
86-
}
87-
88-
+ (NSArray<NSString *> *)defaultSectionTitles {
89-
return @[@"", @"AutoLayout", @"Trivial"];
119+
return [NSArray flex_forEachUpTo:FLEXObjectReferenceSectionCount map:^id(NSUInteger i) {
120+
return [self defaultPredicateForSection:i];
121+
}];
90122
}
91123

92124

@@ -189,7 +221,7 @@ + (instancetype)objectsWithReferencesToObject:(id)object {
189221
}];
190222

191223
NSArray<NSPredicate *> *predicates = [self defaultPredicates];
192-
NSArray<NSString *> *sectionTitles = [self defaultSectionTitles];
224+
NSArray<NSString *> *sectionTitles = FLEXObjectReferenceSectionTitles();
193225
FLEXObjectListViewController *viewController = [[self alloc]
194226
initWithReferences:instances
195227
predicates:predicates

0 commit comments

Comments
 (0)