-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Harmonize code to get the class name, using Swift's built-in demangler
- Loading branch information
Showing
14 changed files
with
236 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// BugsnagSwiftTools.h | ||
// BugsnagPerformance-iOS | ||
// | ||
// Created by Karl Stenerud on 12.11.24. | ||
// Copyright © 2024 Bugsnag. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface BugsnagSwiftTools : NSObject | ||
|
||
/** | ||
* Get the demangled description of an object's class. | ||
* Note: object must not be a class, otherwise demangling won't work! | ||
*/ | ||
+ (NSString * _Nonnull)demangledClassNameFromInstance:(id _Nonnull)object; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// BugsnagSwiftTools.m | ||
// BugsnagPerformance-iOS | ||
// | ||
// Created by Karl Stenerud on 12.11.24. | ||
// Copyright © 2024 Bugsnag. All rights reserved. | ||
// | ||
|
||
#import "BugsnagSwiftTools.h" | ||
#import <BugsnagPerformance/BugsnagPerformanceTrackedViewContainer.h> | ||
|
||
@implementation BugsnagSwiftTools | ||
|
||
// Selector used by BugsnagSwiftToolsImpl | ||
+ (NSString * _Nonnull)demangledClassNameFromInstanceWithObject:(id _Nonnull)object { | ||
return [self demangledClassNameFromInstance:object]; | ||
} | ||
|
||
+ (NSString * _Nonnull)demangledClassNameFromInstance:(id _Nonnull)object { | ||
// BugsnagSwiftToolsImpl is part of the optional BugsnagPerformanceSwift, and may not be linked in | ||
static Class impl = nil; | ||
static bool implExists = false; | ||
static dispatch_once_t once; | ||
dispatch_once(&once, ^{ | ||
impl = NSClassFromString(@"BugsnagPerformanceSwift.BugsnagSwiftToolsImpl"); | ||
implExists = [impl respondsToSelector:@selector(demangledClassNameFromInstanceWithObject:)]; | ||
}); | ||
if (implExists) { | ||
return [impl demangledClassNameFromInstanceWithObject:object]; | ||
} | ||
|
||
// Fallback if BugsnagSwiftToolsImpl is not available | ||
|
||
if ([object respondsToSelector:@selector(bugsnagPerformanceTrackedViewName)]) { | ||
return [(id)object bugsnagPerformanceTrackedViewName]; | ||
} | ||
|
||
return NSStringFromClass([object class]); | ||
} | ||
|
||
@end |
Oops, something went wrong.