Skip to content

Commit c7850df

Browse files
committed
Add safeClassNameForObject: and use it
1 parent 6bbcc55 commit c7850df

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

Classes/GlobalStateExplorers/FLEXObjectListViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ + (instancetype)objectsWithReferencesToObject:(id)object {
228228
sectionTitles:sectionTitles
229229
];
230230
viewController.title = [NSString stringWithFormat:@"Referencing %@ %p",
231-
NSStringFromClass(object_getClass(object)), object
231+
[FLEXRuntimeUtility safeClassNameForObject:object], object
232232
];
233233
return viewController;
234234
}

Classes/GlobalStateExplorers/FLEXObjectRef.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ - (id)initWithObject:(id)object ivarName:(NSString *)ivar showSummary:(BOOL)show
4747
_object = object;
4848
_wantsSummary = showSummary;
4949

50-
NSString *class = NSStringFromClass(object_getClass(object));
50+
NSString *class = [FLEXRuntimeUtility safeClassNameForObject:object];
5151
if (ivar) {
5252
_reference = [NSString stringWithFormat:@"%@ %@", class, ivar];
5353
} else if (showSummary) {

Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ - (void)viewDidLoad {
8787

8888
// Use [object class] here rather than object_getClass
8989
// to avoid the KVO prefix for observed objects
90-
self.title = [[self.object class] description];
90+
self.title = [FLEXRuntimeUtility safeClassNameForObject:self.object];
9191

9292
// Search
9393
self.showsSearchBar = YES;

Classes/Utility/Runtime/FLEXRuntimeUtility.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353

5454
/// Used to describe an object in brief within an explorer row
5555
+ (NSString *)summaryForObject:(id)value;
56+
+ (NSString *)safeClassNameForObject:(id)object;
5657
+ (NSString *)safeDescriptionForObject:(id)object;
5758
+ (NSString *)safeDebugDescriptionForObject:(id)object;
5859

Classes/Utility/Runtime/FLEXRuntimeUtility.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,15 @@ + (NSUInteger)fieldNameOffsetForTypeEncoding:(const FLEXTypeEncoding *)typeEncod
9696
return superClasses;
9797
}
9898

99+
+ (NSString *)safeClassNameForObject:(id)object {
100+
// Don't assume that we have an NSObject subclass
101+
if ([self safeObject:object respondsToSelector:@selector(class)]) {
102+
return NSStringFromClass([object class]);
103+
}
104+
105+
return NSStringFromClass(object_getClass(object));
106+
}
107+
99108
/// Could be nil
100109
+ (NSString *)safeDescriptionForObject:(id)object {
101110
// Don't assume that we have an NSObject subclass; not all objects respond to -description

0 commit comments

Comments
 (0)