Skip to content

Commit

Permalink
ref: Simplify has_UIKit logic in SentrySwizzleWrapper (#2925)
Browse files Browse the repository at this point in the history
Remove a few #if SENTRY_HAS_UIKIT for SentrySwizzleWrapper.
  • Loading branch information
philipphofmann committed Apr 24, 2023
1 parent 32e64d1 commit 0001a09
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 10 deletions.
2 changes: 1 addition & 1 deletion SentryTestUtils/ClearTestState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 1 addition & 7 deletions Sources/Sentry/SentrySwizzleWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
{
Expand Down
3 changes: 2 additions & 1 deletion Sources/Sentry/include/SentrySwizzleWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion scripts/no-changes-in-high-risk-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 0001a09

Please sign in to comment.