Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert committed Aug 25, 2023
1 parent c2d326c commit 9dedda5
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,25 @@ @implementation ViewLoadInstrumentationState
classToIsObserved_[[UIViewController class]] = true;
__block auto classToIsObserved = &classToIsObserved_;
__block bool *isEnabled = &isEnabled_;
__block auto appPath = NSBundle.mainBundle.bundlePath.UTF8String;
SEL selector = @selector(initWithCoder:);
IMP initWithCoder __block = nullptr;
initWithCoder = ObjCSwizzle::replaceInstanceMethodOverride([UIViewController class], selector, ^(id self, NSCoder *coder) {
std::lock_guard<std::mutex> guard(vcInitMutex_);
auto viewControllerClass = [self class];
if (*isEnabled && !isClassObserved(viewControllerClass)) {
Trace(@"%@ -[%s %s]", self, class_getName(viewControllerClass), sel_getName(selector));
instrument(viewControllerClass);
(*classToIsObserved)[viewControllerClass] = true;
auto viewControllerBundlePath = [NSBundle bundleForClass: viewControllerClass].bundlePath.UTF8String;
if (strstr(viewControllerBundlePath, appPath)
#if TARGET_OS_SIMULATOR
// and those loaded from BUILT_PRODUCTS_DIR, because Xcode
// doesn't embed them when building for the Simulator.
|| strstr(viewControllerBundlePath, "/DerivedData/")
#endif
) {
if (*isEnabled && !isClassObserved(viewControllerClass)) {
Trace(@"%@ -[%s %s]", self, class_getName(viewControllerClass), sel_getName(selector));
instrument(viewControllerClass);
(*classToIsObserved)[viewControllerClass] = true;
}
}
reinterpret_cast<void (*)(id, SEL, NSCoder *)>(initWithCoder)(self, selector, coder);
});
Expand All @@ -81,7 +91,6 @@ @implementation ViewLoadInstrumentationState
initWithNibNameBundle = ObjCSwizzle::replaceInstanceMethodOverride([UIViewController class], selector, ^(id self, NSString *name, NSBundle *bundle) {
std::lock_guard<std::mutex> guard(vcInitMutex_);
auto viewControllerClass = [self class];
auto appPath = NSBundle.mainBundle.bundlePath.UTF8String;
auto viewControllerBundlePath = [NSBundle bundleForClass: viewControllerClass].bundlePath.UTF8String;
if (strstr(viewControllerBundlePath, appPath)
#if TARGET_OS_SIMULATOR
Expand Down

0 comments on commit 9dedda5

Please sign in to comment.