Skip to content

Commit 535ebd9

Browse files
authored
ref: Convert SentrySwizzleWrapper to Swift (#6429)
1 parent fb48c9a commit 535ebd9

17 files changed

+123
-153
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,8 @@
499499
7BC3936825B1AB3E004F03D3 /* SentryLevelMapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC3936725B1AB3E004F03D3 /* SentryLevelMapper.h */; };
500500
7BC3936E25B1AB72004F03D3 /* SentryLevelMapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC3936D25B1AB72004F03D3 /* SentryLevelMapper.m */; };
501501
7BC5B6FA290BCDE500D99477 /* SentryHttpStatusCodeRange+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC5B6F8290BCDE500D99477 /* SentryHttpStatusCodeRange+Private.h */; };
502-
7BC63F0828081242009D9E37 /* SentrySwizzleWrapper.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC63F0728081242009D9E37 /* SentrySwizzleWrapper.h */; };
503-
7BC63F0A28081288009D9E37 /* SentrySwizzleWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC63F0928081288009D9E37 /* SentrySwizzleWrapper.m */; };
502+
7BC63F0828081242009D9E37 /* SentrySwizzleWrapperHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BC63F0728081242009D9E37 /* SentrySwizzleWrapperHelper.h */; };
503+
7BC63F0A28081288009D9E37 /* SentrySwizzleWrapperHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7BC63F0928081288009D9E37 /* SentrySwizzleWrapperHelper.m */; };
504504
7BC6EBF4255C044A0059822A /* SentryEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC6EBF3255C044A0059822A /* SentryEventTests.swift */; };
505505
7BC6EBF8255C05060059822A /* TestData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC6EBF7255C05060059822A /* TestData.swift */; };
506506
7BC6EC04255C235F0059822A /* SentryFrameTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7BC6EC03255C235F0059822A /* SentryFrameTests.swift */; };
@@ -1115,6 +1115,7 @@
11151115
FAAB2F972E4D345800FE8B7E /* SentryUIDeviceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB2F962E4D344F00FE8B7E /* SentryUIDeviceWrapper.swift */; };
11161116
FAAB30F32E4E8F2C00FE8B7E /* SentryInAppLogic.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAAB30F22E4E8F2C00FE8B7E /* SentryInAppLogic.swift */; };
11171117
FAB007362E9EF8D3001C806A /* SentryUIViewControllerPerformanceTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */; };
1118+
FAB007522E9FE2FF001C806A /* SentrySwizzleWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAB0074C2E9FE2FA001C806A /* SentrySwizzleWrapper.swift */; };
11181119
FAB359982E05D7E90083D5E3 /* SentryEventSwiftHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */; };
11191120
FAB3599A2E05D8080083D5E3 /* SentryEventSwiftHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */; };
11201121
FAB7BBA92E2577A6007301E1 /* SentryModels+Serializable.h in Headers */ = {isa = PBXBuildFile; fileRef = FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */; };
@@ -1789,8 +1790,8 @@
17891790
7BC3936725B1AB3E004F03D3 /* SentryLevelMapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryLevelMapper.h; path = include/SentryLevelMapper.h; sourceTree = "<group>"; };
17901791
7BC3936D25B1AB72004F03D3 /* SentryLevelMapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryLevelMapper.m; sourceTree = "<group>"; };
17911792
7BC5B6F8290BCDE500D99477 /* SentryHttpStatusCodeRange+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryHttpStatusCodeRange+Private.h"; path = "include/SentryHttpStatusCodeRange+Private.h"; sourceTree = "<group>"; };
1792-
7BC63F0728081242009D9E37 /* SentrySwizzleWrapper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySwizzleWrapper.h; path = include/SentrySwizzleWrapper.h; sourceTree = "<group>"; };
1793-
7BC63F0928081288009D9E37 /* SentrySwizzleWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySwizzleWrapper.m; sourceTree = "<group>"; };
1793+
7BC63F0728081242009D9E37 /* SentrySwizzleWrapperHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentrySwizzleWrapperHelper.h; path = include/SentrySwizzleWrapperHelper.h; sourceTree = "<group>"; };
1794+
7BC63F0928081288009D9E37 /* SentrySwizzleWrapperHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentrySwizzleWrapperHelper.m; sourceTree = "<group>"; };
17941795
7BC6EBF3255C044A0059822A /* SentryEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryEventTests.swift; sourceTree = "<group>"; };
17951796
7BC6EBF7255C05060059822A /* TestData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestData.swift; sourceTree = "<group>"; };
17961797
7BC6EC03255C235F0059822A /* SentryFrameTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFrameTests.swift; sourceTree = "<group>"; };
@@ -2478,6 +2479,7 @@
24782479
FAAB2F962E4D344F00FE8B7E /* SentryUIDeviceWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIDeviceWrapper.swift; sourceTree = "<group>"; };
24792480
FAAB30F22E4E8F2C00FE8B7E /* SentryInAppLogic.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryInAppLogic.swift; sourceTree = "<group>"; };
24802481
FAB007302E9EF8CB001C806A /* SentryUIViewControllerPerformanceTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryUIViewControllerPerformanceTracker.swift; sourceTree = "<group>"; };
2482+
FAB0074C2E9FE2FA001C806A /* SentrySwizzleWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentrySwizzleWrapper.swift; sourceTree = "<group>"; };
24812483
FAB359972E05D7E90083D5E3 /* SentryEventSwiftHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryEventSwiftHelper.h; path = include/SentryEventSwiftHelper.h; sourceTree = "<group>"; };
24822484
FAB359992E05D8080083D5E3 /* SentryEventSwiftHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryEventSwiftHelper.m; sourceTree = "<group>"; };
24832485
FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryModels+Serializable.h"; path = "include/SentryModels+Serializable.h"; sourceTree = "<group>"; };
@@ -2637,6 +2639,7 @@
26372639
621D9F2D2B9B030E003D94DE /* Helper */ = {
26382640
isa = PBXGroup;
26392641
children = (
2642+
FAB0074C2E9FE2FA001C806A /* SentrySwizzleWrapper.swift */,
26402643
D4F56C3C2E9CEFFB00D57DAB /* InfoPlist */,
26412644
F4E1E9802E8C2B150007B080 /* SentryDateUtil.swift */,
26422645
FAE579872E7D9D4900B710F9 /* SentrySysctl.swift */,
@@ -2950,8 +2953,8 @@
29502953
15E0A8EC240F2CB000F044E3 /* SentrySerialization.m */,
29512954
639889B91EDED18400EA7442 /* SentrySwizzle.h */,
29522955
639889BA1EDED18400EA7442 /* SentrySwizzle.m */,
2953-
7BC63F0728081242009D9E37 /* SentrySwizzleWrapper.h */,
2954-
7BC63F0928081288009D9E37 /* SentrySwizzleWrapper.m */,
2956+
7BC63F0728081242009D9E37 /* SentrySwizzleWrapperHelper.h */,
2957+
7BC63F0928081288009D9E37 /* SentrySwizzleWrapperHelper.m */,
29552958
FAB7BBA82E2577A2007301E1 /* SentryModels+Serializable.h */,
29562959
7B8ECBF926498906005FE2EF /* SentryDefaultAppStateManager.h */,
29572960
7B8ECBFB26498958005FE2EF /* SentryDefaultAppStateManager.m */,
@@ -5229,7 +5232,7 @@
52295232
15360CF02433A16D00112302 /* SentryInstallation.h in Headers */,
52305233
63FE714720DA4C1100CDBAE8 /* SentryCrashMachineContext.h in Headers */,
52315234
7BA61CAB247BA98100C130A8 /* SentryDebugImageProvider.h in Headers */,
5232-
7BC63F0828081242009D9E37 /* SentrySwizzleWrapper.h in Headers */,
5235+
7BC63F0828081242009D9E37 /* SentrySwizzleWrapperHelper.h in Headers */,
52335236
638DC9A01EBC6B6400A66E41 /* SentryRequestOperation.h in Headers */,
52345237
6344DDB01EC308E400D9160D /* SentryCrashInstallationReporter.h in Headers */,
52355238
7B5CAF7527F5A67C00ED0DB6 /* SentryNSURLRequestBuilder.h in Headers */,
@@ -5686,7 +5689,6 @@
56865689
FAF1201A2E70C0EE006E1DA3 /* SentryEnvelopeHeaderHelper.m in Sources */,
56875690
F49D419E2DEA3D0600D9244E /* SentryCrashExceptionApplicationHelper.m in Sources */,
56885691
D4F56C5D2E9CF38900D57DAB /* SentryXcodeVersion.swift in Sources */,
5689-
7BE3C77D2446112C00A38442 /* SentryRateLimitParser.m in Sources */,
56905692
D8ACE3C82762187200F5A213 /* SentryFileIOTrackerHelper.m in Sources */,
56915693
D8B088B729C9E3FF00213258 /* SentryTracerConfiguration.m in Sources */,
56925694
FA7206E12E0B37C80072FDD4 /* SentryProfileCollector.mm in Sources */,
@@ -5825,7 +5827,7 @@
58255827
63FE70D520DA4C1000CDBAE8 /* SentryCrashMonitor_NSException.m in Sources */,
58265828
62F70E952D423BCD00634054 /* SentryMechanismCodable.swift in Sources */,
58275829
6283085F2D50AA8C00EAEF77 /* SentryMessage.swift in Sources */,
5828-
7BC63F0A28081288009D9E37 /* SentrySwizzleWrapper.m in Sources */,
5830+
7BC63F0A28081288009D9E37 /* SentrySwizzleWrapperHelper.m in Sources */,
58295831
6276350C2D59FACC00F7CEF6 /* SentryEventDecoder.swift in Sources */,
58305832
7B6C5EDC264E8DA80010D138 /* SentryFramesTrackingIntegration.m in Sources */,
58315833
F4FE9E082E6248E40014FED5 /* SentryCrashWrapper.swift in Sources */,
@@ -6041,6 +6043,7 @@
60416043
63FE714520DA4C1100CDBAE8 /* SentryCrashObjC.c in Sources */,
60426044
63FE710520DA4C1000CDBAE8 /* SentryAsyncSafeLog.c in Sources */,
60436045
62E59A5A2E8FB85300DB7A7B /* SentryTracePropagation.m in Sources */,
6046+
FAB007522E9FE2FF001C806A /* SentrySwizzleWrapper.swift in Sources */,
60446047
62E300942D5202890037AA3F /* SentryExceptionCodable.swift in Sources */,
60456048
0A2D8D5B289815C0008720F6 /* SentryBaseIntegration.m in Sources */,
60466049
639FCF991EBC7B9700778193 /* SentryEvent.m in Sources */,

SentryTestUtils/SentryTestUtils-ObjC-BridgingHeader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#import "SentrySDK+Private.h"
4444
#import "SentrySDKInternal+Tests.h"
4545
#import "SentryScopeSyncC.h"
46-
#import "SentrySwizzleWrapper.h"
4746
#import "SentrySystemWrapper.h"
4847
#import "SentryTraceContext.h"
4948
#import "SentryTracer+Test.h"

SentryTestUtils/TestNSNotificationCenterWrapper.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import Foundation
22
@_spi(Private) import Sentry
33

44
#if canImport(UIKit)
5+
import UIKit
56
public typealias CrossPlatformApplication = UIApplication
67
#else
8+
import AppKit
79
public typealias CrossPlatformApplication = NSApplication
810
#endif
911

Sources/Sentry/SentryBreadcrumbTracker.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#import "SentryScope.h"
1111
#import "SentrySwift.h"
1212
#import "SentrySwizzle.h"
13-
#import "SentrySwizzleWrapper.h"
1413

1514
#if SENTRY_TARGET_MACOS_HAS_UI
1615
# import <Cocoa/Cocoa.h>

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#import <SentryPerformanceTracker.h>
1919
#import <SentrySDK+Private.h>
2020
#import <SentrySwift.h>
21-
#import <SentrySwizzleWrapper.h>
2221
#import <SentryTracer.h>
2322
#import <SentryWatchdogTerminationScopeObserver.h>
2423

Sources/Sentry/SentrySwizzleWrapper.m

Lines changed: 0 additions & 84 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#import "SentrySwizzleWrapperHelper.h"
2+
#import "SentrySwizzle.h"
3+
4+
#if SENTRY_HAS_UIKIT
5+
# import <UIKit/UIKit.h>
6+
7+
NS_ASSUME_NONNULL_BEGIN
8+
9+
@implementation SentrySwizzleWrapperHelper
10+
11+
+ (void)swizzle:(void (^)(SEL action, id target, id sender, UIEvent *event))callback;
12+
{
13+
# pragma clang diagnostic push
14+
# pragma clang diagnostic ignored "-Wshadow"
15+
static const void *swizzleSendActionKey = &swizzleSendActionKey;
16+
SEL selector = NSSelectorFromString(@"sendAction:to:from:forEvent:");
17+
SentrySwizzleInstanceMethod(UIApplication, selector, SentrySWReturnType(BOOL),
18+
SentrySWArguments(SEL action, id target, id sender, UIEvent * event), SentrySWReplacement({
19+
callback(action, target, sender, event);
20+
return SentrySWCallOriginal(action, target, sender, event);
21+
}),
22+
SentrySwizzleModeOncePerClassAndSuperclasses, swizzleSendActionKey);
23+
# pragma clang diagnostic pop
24+
}
25+
26+
@end
27+
28+
NS_ASSUME_NONNULL_END
29+
30+
#endif // SENTRY_HAS_UIKIT

Sources/Sentry/SentryUIEventTracker.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#if SENTRY_HAS_UIKIT
55

66
# import "SentrySpanOperation.h"
7-
# import "SentrySwizzleWrapper.h"
7+
# import "SentrySwift.h"
88
# import <SentryDependencyContainer.h>
99
# import <SentryLogC.h>
1010
# import <SentryUIEventTrackerMode.h>

Sources/Sentry/include/SentryPrivate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#import "SentrySessionInternal.h"
4949
#import "SentrySpanDataKey.h"
5050
#import "SentrySpanOperation.h"
51+
#import "SentrySwizzleWrapperHelper.h"
5152
#import "SentrySysctlObjC.h"
5253
#import "SentryTraceHeader.h"
5354
#import "SentryTraceOrigin.h"

Sources/Sentry/include/SentrySwizzleWrapper.h

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)