From 0001a0915a14e43c2a3952e6541af95a36b7eb52 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Mon, 24 Apr 2023 09:41:00 +0200 Subject: [PATCH] ref: Simplify has_UIKit logic in SentrySwizzleWrapper (#2925) Remove a few #if SENTRY_HAS_UIKIT for SentrySwizzleWrapper. --- SentryTestUtils/ClearTestState.swift | 2 +- Sources/Sentry/SentrySwizzleWrapper.m | 8 +------- Sources/Sentry/include/SentrySwizzleWrapper.h | 3 ++- scripts/no-changes-in-high-risk-files.sh | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/SentryTestUtils/ClearTestState.swift b/SentryTestUtils/ClearTestState.swift index 48a71d3b9fe..317ffbd691e 100644 --- a/SentryTestUtils/ClearTestState.swift +++ b/SentryTestUtils/ClearTestState.swift @@ -32,12 +32,12 @@ class TestCleanup: NSObject { setenv("ActivePrewarm", "0", 1) SentryAppStartTracker.load() SentryUIViewControllerPerformanceTracker.shared.enableWaitForFullDisplay = false + SentrySwizzleWrapper.sharedInstance.removeAllCallbacks() #endif SentryDependencyContainer.reset() Dynamic(SentryGlobalEventProcessor.shared()).removeAllProcessors() SentryPerformanceTracker.shared.clear() - SentrySwizzleWrapper.sharedInstance.removeAllCallbacks() SentryTracer.resetAppStartMeasurementRead() diff --git a/Sources/Sentry/SentrySwizzleWrapper.m b/Sources/Sentry/SentrySwizzleWrapper.m index 049803a2506..2d60a9efe70 100644 --- a/Sources/Sentry/SentrySwizzleWrapper.m +++ b/Sources/Sentry/SentrySwizzleWrapper.m @@ -19,16 +19,14 @@ + (SentrySwizzleWrapper *)sharedInstance return instance; } +#if SENTRY_HAS_UIKIT + (void)initialize { -#if SENTRY_HAS_UIKIT if (self == [SentrySwizzleWrapper class]) { sentrySwizzleSendActionCallbacks = [NSMutableDictionary new]; } -#endif } -#if SENTRY_HAS_UIKIT - (void)swizzleSendAction:(SentrySwizzleSendActionCallback)callback forKey:(NSString *)key { // We need to make a copy of the block to avoid ARC of autoreleasing it. @@ -75,16 +73,12 @@ + (void)sendActionCalled:(SEL)action target:(id)target sender:(id)sender event:( { return sentrySwizzleSendActionCallbacks; } -#endif - (void)removeAllCallbacks { -#if SENTRY_HAS_UIKIT [sentrySwizzleSendActionCallbacks removeAllObjects]; -#endif } -#if SENTRY_HAS_UIKIT // For test purpose + (BOOL)hasCallbacks { diff --git a/Sources/Sentry/include/SentrySwizzleWrapper.h b/Sources/Sentry/include/SentrySwizzleWrapper.h index 5d5f61eea9b..11e3a7aef01 100644 --- a/Sources/Sentry/include/SentrySwizzleWrapper.h +++ b/Sources/Sentry/include/SentrySwizzleWrapper.h @@ -23,13 +23,14 @@ typedef void (^SentrySwizzleSendActionCallback)( - (void)swizzleSendAction:(SentrySwizzleSendActionCallback)callback forKey:(NSString *)key; - (void)removeSwizzleSendActionForKey:(NSString *)key; -#endif /** * For testing purposes. */ - (void)removeAllCallbacks; +#endif + @end NS_ASSUME_NONNULL_END diff --git a/scripts/no-changes-in-high-risk-files.sh b/scripts/no-changes-in-high-risk-files.sh index 78be135528d..8d719d90c69 100755 --- a/scripts/no-changes-in-high-risk-files.sh +++ b/scripts/no-changes-in-high-risk-files.sh @@ -10,7 +10,7 @@ EXPECTED="819d5ca5e3db2ac23c859b14c149b7f0754d3ae88bea1dba92c18f49a81da0e1 ./So e95e62ec7363984f20c78643bb7d992a41a740f97e1befb71525ac34caf88b37 ./Sources/Sentry/SentryNSDataSwizzling.m 9ad05dd8dd29788cba994736fdcd3bbde59a94e32612640d11f4f9c38ad6610e ./Sources/Sentry/SentrySubClassFinder.m 13c3030d8c1fb145760d51837773c35127c777fce1d4dbb9009d53d0fcc5dce8 ./Sources/Sentry/SentryCoreDataSwizzling.m -e41c853a75dcc31a2783ec513acc8c7af8a67033ab8585c80b525f63dd26b506 ./Sources/Sentry/SentrySwizzleWrapper.m +c6fd5fb82863246c697f4913fdd03c09a18d1006d30322d375a66a0046e9c252 ./Sources/Sentry/SentrySwizzleWrapper.m b1c642450170358cab39b4cc6cd546f27c41b12eacb90c3ad93f87733d46e56c ./Sources/Sentry/include/SentrySwizzle.h f97128c823f92d1c2ec37e5e3b2914f7488a94043af6a8344e348f1a14425f47 ./Sources/Sentry/SentrySwizzle.m"