Skip to content

Commit 48f53bc

Browse files
authored
ref: Begin moving dependencies to Swift (#6442)
1 parent ed67bc2 commit 48f53bc

File tree

9 files changed

+17
-25
lines changed

9 files changed

+17
-25
lines changed

Sources/Sentry/SentryDependencyContainer.m

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,12 @@ - (instancetype)init
148148
isInitialializingDependencyContainer = YES;
149149

150150
_dispatchQueueWrapper = SentryDependencies.dispatchQueueWrapper;
151-
_random = [[SentryRandom alloc] init];
152-
_threadWrapper = [[SentryThreadWrapper alloc] init];
151+
_random = SentryDependencies.random;
152+
_threadWrapper = SentryDependencies.threadWrapper;
153153
_binaryImageCache = [[SentryBinaryImageCache alloc] init];
154154
_dateProvider = SentryDependencies.dateProvider;
155155

156-
_notificationCenterWrapper = NSNotificationCenter.defaultCenter;
156+
_notificationCenterWrapper = SentryDependencies.notificationCenterWrapper;
157157

158158
_processInfoWrapper = SentryDependencies.processInfoWrapper;
159159
_crashWrapper = [[SentryCrashWrapper alloc] initWithProcessInfoWrapper:_processInfoWrapper];
@@ -172,7 +172,7 @@ - (instancetype)init
172172
#endif // TARGET_OS_IOS && SENTRY_HAS_UIKIT
173173
];
174174

175-
_sysctlWrapper = [[SentrySysctl alloc] init];
175+
_sysctlWrapper = SentryDependencies.sysctlWrapper;
176176

177177
SentryRetryAfterHeaderParser *retryAfterHeaderParser = [[SentryRetryAfterHeaderParser alloc]
178178
initWithHttpDateParser:[[SentryHttpDateParser alloc] init]
@@ -184,9 +184,6 @@ - (instancetype)init
184184
[[SentryDefaultRateLimits alloc] initWithRetryAfterHeaderParser:retryAfterHeaderParser
185185
andRateLimitParser:rateLimitParser
186186
currentDateProvider:_dateProvider];
187-
_infoPlistWrapper = [[SentryInfoPlistWrapper alloc] init];
188-
_sessionReplayEnvironmentChecker = [[SentrySessionReplayEnvironmentChecker alloc]
189-
initWithInfoPlistWrapper:_infoPlistWrapper];
190187

191188
_reachability = [[SentryReachability alloc] init];
192189

Sources/Sentry/SentrySessionReplayIntegration.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ - (void)setupWith:(SentryReplayOptions *)replayOptions
134134

135135
_notificationCenter = SentryDependencyContainer.sharedInstance.notificationCenterWrapper;
136136
_dateProvider = SentryDependencyContainer.sharedInstance.dateProvider;
137-
_environmentChecker = SentryDependencyContainer.sharedInstance.sessionReplayEnvironmentChecker;
137+
_environmentChecker = SentryDependencies.sessionReplayEnvironmentChecker;
138138

139139
// We use the dispatch queue provider as a factory to create the queues, but store the queues
140140
// directly in this instance, so they get deallocated when the integration is deallocated.

Sources/Sentry/include/HybridPublic/SentryDependencyContainer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
@protocol SentryProcessInfoSource;
3535
@protocol SentryNSNotificationCenterWrapper;
3636
@protocol SentryObjCRuntimeWrapper;
37-
@protocol SentryInfoPlistWrapperProvider;
38-
@protocol SentrySessionReplayEnvironmentCheckerProvider;
3937

4038
#if SENTRY_HAS_METRIC_KIT
4139
@class SentryMXManager;
@@ -91,9 +89,6 @@ SENTRY_NO_INIT
9189
@property (nonatomic, strong) SentrySysctl *sysctlWrapper;
9290
@property (nonatomic, strong) id<SentryRateLimits> rateLimits;
9391
@property (nonatomic, strong) SentryThreadsafeApplication *threadsafeApplication;
94-
@property (nonatomic, strong) id<SentryInfoPlistWrapperProvider> infoPlistWrapper;
95-
@property (nonatomic, strong) id<SentrySessionReplayEnvironmentCheckerProvider>
96-
sessionReplayEnvironmentChecker;
9792

9893
@property (nonatomic, strong) SentryReachability *reachability;
9994

Sources/Sentry/include/SentryHub+Private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
@class SentryTransaction;
77
@class SentryDispatchQueueWrapper;
88
@class SentryEnvelope;
9-
@class SentryNSTimerFactory;
109
@class SentrySession;
1110
@class SentryTracer;
1211
@class SentryTracerConfiguration;

Sources/Sentry/include/SentryTracer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ NS_ASSUME_NONNULL_BEGIN
77
@class SentryDispatchQueueWrapper;
88
@class SentryHub;
99
@class SentryMeasurementValue;
10-
@class SentryNSTimerFactory;
1110
@class SentryTraceContext;
1211
@class SentryTraceHeader;
1312
@class SentryTracer;

Sources/Swift/Helper/Dependencies.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
@_implementationOnly import _SentryPrivate
22

33
@objc(SentryDependencies) @_spi(Private) public final class Dependencies: NSObject {
4+
@objc public static let random: SentryRandomProtocol = SentryRandom()
5+
@objc public static let threadWrapper = SentryThreadWrapper()
46
@objc public static let processInfoWrapper: SentryProcessInfoSource = ProcessInfo.processInfo
7+
static let infoPlistWrapper: SentryInfoPlistWrapperProvider = SentryInfoPlistWrapper()
8+
@objc public static let sessionReplayEnvironmentChecker: SentrySessionReplayEnvironmentChecker = {
9+
SentrySessionReplayEnvironmentChecker(infoPlistWrapper: Dependencies.infoPlistWrapper)
10+
}()
511
@objc public static let dispatchQueueWrapper = SentryDispatchQueueWrapper()
12+
@objc public static let notificationCenterWrapper: SentryNSNotificationCenterWrapper = NotificationCenter.default
13+
@objc public static let sysctlWrapper = SentrySysctl()
614
@objc public static let dateProvider = SentryDefaultCurrentDateProvider()
715
public static let objcRuntimeWrapper = SentryDefaultObjCRuntimeWrapper()
816
#if !os(watchOS) && !os(macOS) && !SENTRY_NO_UIKIT

Sources/Swift/Helper/InfoPlist/SentryInfoPlistWrapper.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
@objc @_spi(Private) public class SentryInfoPlistWrapper: NSObject, SentryInfoPlistWrapperProvider {
1+
final class SentryInfoPlistWrapper: SentryInfoPlistWrapperProvider {
22

33
private let bundle: Bundle
44

5-
public override init() {
5+
public init(bundle: Bundle = Bundle.main) {
66
// We can not use defaults in the initializer because this class is used from Objective-C
7-
self.bundle = Bundle.main
8-
super.init()
9-
}
10-
11-
public init(bundle: Bundle) {
127
self.bundle = bundle
13-
super.init()
148
}
159

1610
// MARK: - Bridge to ObjC

Sources/Swift/Helper/InfoPlist/SentryInfoPlistWrapperProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@_spi(Private) @objc public protocol SentryInfoPlistWrapperProvider {
1+
protocol SentryInfoPlistWrapperProvider {
22
/**
33
* Retrieves a value from the app's `Info.plist` file for the given key and trys to cast it to a ``String``.
44
*

Sources/Swift/Integrations/SessionReplay/SentrySessionReplayEnvironmentChecker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
private let infoPlistWrapper: SentryInfoPlistWrapperProvider
1414

15-
@objc public init(infoPlistWrapper: SentryInfoPlistWrapperProvider) {
15+
init(infoPlistWrapper: SentryInfoPlistWrapperProvider) {
1616
self.infoPlistWrapper = infoPlistWrapper
1717
super.init()
1818
}

0 commit comments

Comments
 (0)