From add8416cd7e3d0f3e9234f9d747c185a8b55be55 Mon Sep 17 00:00:00 2001 From: Dhiogo Brustolin Date: Fri, 8 Mar 2024 08:23:39 +0100 Subject: [PATCH] ref: Convert SentryId to Swift (#3708) I can see this being the beginning of a project refactoring to Swift. Also, I want to try converting something to see how much effort it is. --- .../iOS-Swift.xcodeproj/project.pbxproj | 15 --- Sentry.xcodeproj/project.pbxproj | 42 ++++++-- .../Sentry/Profiling/SentryLaunchProfiling.m | 2 +- .../SentryProfiledTracerConcurrency.mm | 2 +- Sources/Sentry/Public/Sentry.h | 1 - Sources/Sentry/Public/SentryId.h | 45 -------- Sources/Sentry/SentryClient.m | 1 - Sources/Sentry/SentryEvent.m | 2 +- Sources/Sentry/SentryHub.m | 2 +- Sources/Sentry/SentryId.m | 102 ------------------ Sources/Sentry/SentryNoOpSpan.m | 2 +- Sources/Sentry/SentryProfiler.mm | 2 +- Sources/Sentry/SentryPropagationContext.m | 2 +- Sources/Sentry/SentrySerialization.m | 2 +- Sources/Sentry/SentrySpan.m | 2 +- Sources/Sentry/SentrySpanContext.m | 2 +- Sources/Sentry/SentryTraceContext.m | 2 +- Sources/Sentry/SentryTraceHeader.m | 2 +- Sources/Sentry/SentryUserFeedback.m | 2 +- .../include/SentryProfiledTracerConcurrency.h | 3 +- Sources/Sentry/include/SentrySwift.h | 6 ++ Sources/Sentry/include/SentryTraceContext.h | 6 +- .../Swift/Extensions/StringExtensions.swift | 40 +++++++ Sources/Swift/Protocol/SentryId.swift | 72 +++++++++++++ .../SentryProfilerTests.mm | 2 +- Tests/SentryTests/SentryInterfacesTests.m | 2 +- .../SentryTests/SentryTests-Bridging-Header.h | 2 +- Tests/SentryTests/StringExtensionTests.swift | 45 ++++++++ 28 files changed, 215 insertions(+), 195 deletions(-) delete mode 100644 Sources/Sentry/Public/SentryId.h delete mode 100644 Sources/Sentry/SentryId.m create mode 100644 Sources/Swift/Extensions/StringExtensions.swift create mode 100644 Sources/Swift/Protocol/SentryId.swift create mode 100644 Tests/SentryTests/StringExtensionTests.swift diff --git a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj index 1a3a3bd3cff..587766e98e2 100644 --- a/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj +++ b/Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj @@ -172,13 +172,6 @@ remoteGlobalIDString = D8199DAA29376E9B0074249E; remoteInfo = SentrySwiftUI; }; - D81A3499291D0B2C005A27A9 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 6308532C2440C44F00DDE4CE /* Sentry.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = D81A3488291D0AC0005A27A9; - remoteInfo = SentryPrivate; - }; D83A30CA279F075800372D0A /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 6308532C2440C44F00DDE4CE /* Sentry.xcodeproj */; @@ -420,7 +413,6 @@ children = ( 630853322440C44F00DDE4CE /* Sentry.framework */, 630853342440C44F00DDE4CE /* SentryTests.xctest */, - D81A349A291D0B2C005A27A9 /* SentryPrivate.framework */, D8105B5C297E792200299F03 /* SentrySwiftUI.framework */, 84B7FA5B29B2A86500AD93B1 /* SentryProfilerTests.xctest */, 84B7FA5D29B2A86500AD93B1 /* libSentryTestUtils.a */, @@ -844,13 +836,6 @@ remoteRef = D8105B5B297E792200299F03 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - D81A349A291D0B2C005A27A9 /* SentryPrivate.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SentryPrivate.framework; - remoteRef = D81A3499291D0B2C005A27A9 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; D84DAD712B177DB2003CF120 /* SentryTestUtilsDynamic.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; diff --git a/Sentry.xcodeproj/project.pbxproj b/Sentry.xcodeproj/project.pbxproj index 2ec70f0da67..75a6514f3f9 100644 --- a/Sentry.xcodeproj/project.pbxproj +++ b/Sentry.xcodeproj/project.pbxproj @@ -409,8 +409,6 @@ 7B7D873624864C9D00D2ECFF /* SentryCrashDefaultMachineContextWrapper.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B7D873524864C9D00D2ECFF /* SentryCrashDefaultMachineContextWrapper.m */; }; 7B82722927A319E900F4BFF4 /* SentryAutoSessionTrackingIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B82722827A319E900F4BFF4 /* SentryAutoSessionTrackingIntegrationTests.swift */; }; 7B82722B27A3220A00F4BFF4 /* SentryFileIoTrackingUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B82722A27A3220A00F4BFF4 /* SentryFileIoTrackingUnitTests.swift */; }; - 7B82D54524E2A05500EE670F /* SentryId.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B82D54424E2A05500EE670F /* SentryId.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 7B82D54724E2A1AB00EE670F /* SentryId.m in Sources */ = {isa = PBXBuildFile; fileRef = 7B82D54624E2A1AB00EE670F /* SentryId.m */; }; 7B82D54924E2A2D400EE670F /* SentryIdTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B82D54824E2A2D400EE670F /* SentryIdTests.swift */; }; 7B85BD8E24C5C3A6000A4225 /* SentryFileManagerTestExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B85BD8D24C5C3A6000A4225 /* SentryFileManagerTestExtension.swift */; }; 7B85DC1E24EFAFCD007D01D2 /* SentryClient+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B85DC1C24EFAFCD007D01D2 /* SentryClient+Private.h */; }; @@ -814,10 +812,12 @@ D8B0542E2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = D8B0542D2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy */; }; D8B088B629C9E3FF00213258 /* SentryTracerConfiguration.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */; }; D8B088B729C9E3FF00213258 /* SentryTracerConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */; }; + D8B425122B9A0FD6000BFDF3 /* StringExtensionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B425112B9A0FD6000BFDF3 /* StringExtensionTests.swift */; }; + D8B665BC2B95F73200BD0E7B /* SentryInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B665BA2B95F54200BD0E7B /* SentryInternal.h */; }; D8B665BC2B95F73200BD0E7B /* SentryPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B665BA2B95F54200BD0E7B /* SentryPrivate.h */; }; D8B76B062808066D000A58C4 /* SentryScreenshotIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */; }; D8B76B0828081461000A58C4 /* TestSentryScreenShot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8B76B0728081461000A58C4 /* TestSentryScreenShot.swift */; }; - D8BBD32728FD9FC00011F850 /* SentrySwift.h in Headers */ = {isa = PBXBuildFile; fileRef = D8BBD32628FD9FBF0011F850 /* SentrySwift.h */; }; + D8BBD32728FD9FC00011F850 /* SentrySwift.h in Headers */ = {isa = PBXBuildFile; fileRef = D8BBD32628FD9FBF0011F850 /* SentrySwift.h */; settings = {ATTRIBUTES = (Private, ); }; }; D8BD2E6829361A0F00D96C6A /* PrivatesHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = D8BD2E67293619F600D96C6A /* PrivatesHeader.h */; settings = {ATTRIBUTES = (Private, ); }; }; D8BFE37229A3782F002E73F3 /* SentryTimeToDisplayTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = D8BFE37029A3782F002E73F3 /* SentryTimeToDisplayTracker.h */; }; D8BFE37329A3782F002E73F3 /* SentryTimeToDisplayTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = D8BFE37129A3782F002E73F3 /* SentryTimeToDisplayTracker.m */; }; @@ -834,6 +834,8 @@ D8CB742E294B294B00A5F964 /* MockUIScene.m in Sources */ = {isa = PBXBuildFile; fileRef = D8CB742D294B294B00A5F964 /* MockUIScene.m */; }; D8CCFC632A1520C900DE232E /* SentryBinaryImageCacheTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D8CCFC622A1520C900DE232E /* SentryBinaryImageCacheTests.m */; }; D8CE69BC277E39C700C6EC5C /* SentryFileIOTrackingIntegrationObjCTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D8CE69BB277E39C700C6EC5C /* SentryFileIOTrackingIntegrationObjCTests.m */; }; + D8F016B32B9622D6007B9AFB /* SentryId.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F016B22B9622D6007B9AFB /* SentryId.swift */; }; + D8F016B62B962548007B9AFB /* StringExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F016B52B962548007B9AFB /* StringExtensions.swift */; }; D8F6A2472885512100320515 /* SentryPredicateDescriptor.m in Sources */ = {isa = PBXBuildFile; fileRef = D8F6A2452885512100320515 /* SentryPredicateDescriptor.m */; }; D8F6A24B2885515C00320515 /* SentryPredicateDescriptor.h in Headers */ = {isa = PBXBuildFile; fileRef = D8F6A24A2885515B00320515 /* SentryPredicateDescriptor.h */; }; D8F6A24E288553A800320515 /* SentryPredicateDescriptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F6A24C2885534E00320515 /* SentryPredicateDescriptorTests.swift */; }; @@ -1325,8 +1327,6 @@ 7B7D873524864C9D00D2ECFF /* SentryCrashDefaultMachineContextWrapper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryCrashDefaultMachineContextWrapper.m; sourceTree = ""; }; 7B82722827A319E900F4BFF4 /* SentryAutoSessionTrackingIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryAutoSessionTrackingIntegrationTests.swift; sourceTree = ""; }; 7B82722A27A3220A00F4BFF4 /* SentryFileIoTrackingUnitTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFileIoTrackingUnitTests.swift; sourceTree = ""; }; - 7B82D54424E2A05500EE670F /* SentryId.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryId.h; path = Public/SentryId.h; sourceTree = ""; }; - 7B82D54624E2A1AB00EE670F /* SentryId.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryId.m; sourceTree = ""; }; 7B82D54824E2A2D400EE670F /* SentryIdTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryIdTests.swift; sourceTree = ""; }; 7B85BD8D24C5C3A6000A4225 /* SentryFileManagerTestExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryFileManagerTestExtension.swift; sourceTree = ""; }; 7B85DC1C24EFAFCD007D01D2 /* SentryClient+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentryClient+Private.h"; path = "include/SentryClient+Private.h"; sourceTree = ""; }; @@ -1780,6 +1780,8 @@ D8B0542D2A7D2C720056BAF6 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = ""; }; D8B088B429C9E3FF00213258 /* SentryTracerConfiguration.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryTracerConfiguration.h; path = include/SentryTracerConfiguration.h; sourceTree = ""; }; D8B088B529C9E3FF00213258 /* SentryTracerConfiguration.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryTracerConfiguration.m; sourceTree = ""; }; + D8B425112B9A0FD6000BFDF3 /* StringExtensionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensionTests.swift; sourceTree = ""; }; + D8B665BA2B95F54200BD0E7B /* SentryInternal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryInternal.h; path = include/SentryInternal.h; sourceTree = ""; }; D8B665BA2B95F54200BD0E7B /* SentryPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryPrivate.h; path = include/SentryPrivate.h; sourceTree = ""; }; D8B665BB2B95F5A100BD0E7B /* module.modulemap */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.module-map"; name = module.modulemap; path = Sources/Sentry/include/module.modulemap; sourceTree = SOURCE_ROOT; }; D8B76B042808060E000A58C4 /* SentryScreenshotIntegrationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryScreenshotIntegrationTests.swift; sourceTree = ""; }; @@ -1804,6 +1806,8 @@ D8CB742D294B294B00A5F964 /* MockUIScene.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockUIScene.m; sourceTree = ""; }; D8CCFC622A1520C900DE232E /* SentryBinaryImageCacheTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryBinaryImageCacheTests.m; sourceTree = ""; }; D8CE69BB277E39C700C6EC5C /* SentryFileIOTrackingIntegrationObjCTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryFileIOTrackingIntegrationObjCTests.m; sourceTree = ""; }; + D8F016B22B9622D6007B9AFB /* SentryId.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryId.swift; sourceTree = ""; }; + D8F016B52B962548007B9AFB /* StringExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringExtensions.swift; sourceTree = ""; }; D8F01DE42A126B62008F4996 /* HybridPod.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = HybridPod.podspec; sourceTree = ""; }; D8F01DE52A126BF5008F4996 /* HybridTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HybridTest.swift; sourceTree = ""; }; D8F6A2452885512100320515 /* SentryPredicateDescriptor.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryPredicateDescriptor.m; sourceTree = ""; }; @@ -1979,8 +1983,6 @@ 7BE1E32624F7AE08009D3AD0 /* SentrySession+Private.h */, 7B88F2FD24BC5A4C00ADF90A /* SentrySdkInfo.h */, 7B88F2FF24BC5A7D00ADF90A /* SentrySdkInfo.m */, - 7B82D54424E2A05500EE670F /* SentryId.h */, - 7B82D54624E2A1AB00EE670F /* SentryId.m */, 7BFC169A2524995700FF6266 /* SentryMessage.h */, 7BFC16A025249A9D00FF6266 /* SentryMessage.m */, 7BB654FA253DC14A00887E87 /* SentryUserFeedback.h */, @@ -3327,8 +3329,10 @@ D800942328F82E8D005D3943 /* Swift */ = { isa = PBXGroup; children = ( - D856272A2A374A6800FB8062 /* Tools */, + D8F016B42B962533007B9AFB /* Extensions */, 7BF65060292B8EFE00BBA5A8 /* MetricKit */, + D8F016B12B9622B7007B9AFB /* Protocol */, + D856272A2A374A6800FB8062 /* Tools */, D800942628F82F3A005D3943 /* SwiftDescriptor.swift */, D8B665BB2B95F5A100BD0E7B /* module.modulemap */, ); @@ -3383,6 +3387,7 @@ D84541172A2DC2CD00E2B11C /* SentryBinaryImageCacheTests.swift */, D84541192A2DC55100E2B11C /* SentryBinaryImageCache+Private.h */, D8292D7C2A39A027009872F7 /* UrlSanitizedTests.swift */, + D8B425112B9A0FD6000BFDF3 /* StringExtensionTests.swift */, ); name = Tools; sourceTree = ""; @@ -3481,6 +3486,22 @@ path = Resources; sourceTree = ""; }; + D8F016B12B9622B7007B9AFB /* Protocol */ = { + isa = PBXGroup; + children = ( + D8F016B22B9622D6007B9AFB /* SentryId.swift */, + ); + path = Protocol; + sourceTree = ""; + }; + D8F016B42B962533007B9AFB /* Extensions */ = { + isa = PBXGroup; + children = ( + D8F016B52B962548007B9AFB /* StringExtensions.swift */, + ); + path = Extensions; + sourceTree = ""; + }; D8F01DE32A125D7B008F4996 /* HybridSDKTest */ = { isa = PBXGroup; children = ( @@ -3540,7 +3561,6 @@ 639FCFAC1EBC811400778193 /* SentryUser.h in Headers */, D8CB74192947285A00A5F964 /* SentryEnvelopeItemHeader.h in Headers */, 7D7F0A5F23DF3D2C00A4629C /* SentryGlobalEventProcessor.h in Headers */, - 7B82D54524E2A05500EE670F /* SentryId.h in Headers */, D867063D27C3BC2400048851 /* SentryCoreDataTrackingIntegration.h in Headers */, 0A2D8D5D289815EB008720F6 /* SentryBaseIntegration.h in Headers */, 84AC61D629F75A98009EEF61 /* SentryDispatchFactory.h in Headers */, @@ -4177,7 +4197,6 @@ 63295AF71EF3C7DB002D4490 /* NSDictionary+SentrySanitize.m in Sources */, 7B8ECBFC26498958005FE2EF /* SentryAppStateManager.m in Sources */, 7B2A70DD27D6083D008B0D15 /* SentryThreadWrapper.m in Sources */, - 7B82D54724E2A1AB00EE670F /* SentryId.m in Sources */, D8ACE3C72762187200F5A213 /* SentryNSDataSwizzling.m in Sources */, 638DC9A11EBC6B6400A66E41 /* SentryRequestOperation.m in Sources */, 63AA767A1EB8D20500D153DE /* SentryLog.m in Sources */, @@ -4238,6 +4257,7 @@ 8EA1ED0B2668F8C400E62B98 /* SentryUIViewControllerSwizzling.m in Sources */, 7B98D7CF25FB650F00C5A389 /* SentryWatchdogTerminationTrackingIntegration.m in Sources */, 8E5D38DD261D4A3E000D363D /* SentryPerformanceTrackingIntegration.m in Sources */, + D8F016B62B962548007B9AFB /* StringExtensions.swift in Sources */, 7B4E23C2251A2C2B00060D68 /* SentrySessionCrashedHandler.m in Sources */, 9286059729A5098900F96038 /* SentryGeo.m in Sources */, 7B42C48227E08F4B009B58C2 /* SentryDependencyContainer.m in Sources */, @@ -4257,6 +4277,7 @@ D88817D826D7149100BF2251 /* SentryTraceContext.m in Sources */, 8EBF870926140D37001A6853 /* SentryPerformanceTracker.m in Sources */, D80CD8D02B75143F002F710B /* UrlSanitized.swift in Sources */, + D8F016B32B9622D6007B9AFB /* SentryId.swift in Sources */, D865893029D6ECA7000BE151 /* SentryCrashBinaryImageCache.c in Sources */, 7BC9A20428F4166D001E7C4C /* SentryMeasurementValue.m in Sources */, D859696B27BECD8F0036A46E /* SentryCoreDataTrackingIntegration.m in Sources */, @@ -4484,6 +4505,7 @@ 8F73BC312B02B87E00C3CEF4 /* SentryInstallationTests.swift in Sources */, 7B569E002590EEF600B653FC /* SentryScope+Equality.m in Sources */, D8BFE37929A76666002E73F3 /* SentryTimeToDisplayTrackerTest.swift in Sources */, + D8B425122B9A0FD6000BFDF3 /* StringExtensionTests.swift in Sources */, D84541182A2DC2CD00E2B11C /* SentryBinaryImageCacheTests.swift in Sources */, 7BF536D424BEF255004FA6A2 /* SentryAssertions.swift in Sources */, 7BC6EC14255C415E0059822A /* SentryExceptionTests.swift in Sources */, diff --git a/Sources/Sentry/Profiling/SentryLaunchProfiling.m b/Sources/Sentry/Profiling/SentryLaunchProfiling.m index b89fc60bd42..2bf4f906afd 100644 --- a/Sources/Sentry/Profiling/SentryLaunchProfiling.m +++ b/Sources/Sentry/Profiling/SentryLaunchProfiling.m @@ -6,7 +6,6 @@ # import "SentryDependencyContainer.h" # import "SentryDispatchQueueWrapper.h" # import "SentryFileManager.h" -# import "SentryId.h" # import "SentryInternalDefines.h" # import "SentryLog.h" # import "SentryOptions.h" @@ -15,6 +14,7 @@ # import "SentrySamplerDecision.h" # import "SentrySampling.h" # import "SentrySamplingContext.h" +# import "SentrySwift.h" # import "SentryTraceOrigins.h" # import "SentryTracer+Private.h" # import "SentryTracerConfiguration.h" diff --git a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm index 05ce1b65ad5..fe2913dfa2f 100644 --- a/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm +++ b/Sources/Sentry/Profiling/SentryProfiledTracerConcurrency.mm @@ -2,10 +2,10 @@ #if SENTRY_TARGET_PROFILING_SUPPORTED -# import "SentryId.h" # import "SentryInternalDefines.h" # import "SentryLog.h" # import "SentryProfiler+Private.h" +# import "SentrySwift.h" # include # if SENTRY_HAS_UIKIT diff --git a/Sources/Sentry/Public/Sentry.h b/Sources/Sentry/Public/Sentry.h index afaa72b0986..86cab96a84f 100644 --- a/Sources/Sentry/Public/Sentry.h +++ b/Sources/Sentry/Public/Sentry.h @@ -22,7 +22,6 @@ FOUNDATION_EXPORT const unsigned char SentryVersionString[]; #import "SentryGeo.h" #import "SentryHttpStatusCodeRange.h" #import "SentryHub.h" -#import "SentryId.h" #import "SentryIntegrationProtocol.h" #import "SentryMeasurementUnit.h" #import "SentryMechanism.h" diff --git a/Sources/Sentry/Public/SentryId.h b/Sources/Sentry/Public/SentryId.h deleted file mode 100644 index 2024a374ffa..00000000000 --- a/Sources/Sentry/Public/SentryId.h +++ /dev/null @@ -1,45 +0,0 @@ -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * A wrapper around UUID. - * UUIDs are declared as either 32 character hexadecimal strings without dashes - * "12c2d058d58442709aa2eca08bf20986", or 36 character strings with dashes - * "12c2d058-d584-4270-9aa2-eca08bf20986". - * @note It is recommended to omit dashes and use UUID v4 in cases. - */ -@interface SentryId : NSObject - -/** - * Creates a @c SentryId with a random UUID. - */ -- (instancetype)init; - -/** - * Creates a SentryId with the given UUID. - */ -- (instancetype)initWithUUID:(NSUUID *)uuid; - -/** - * Creates a @c SentryId from a 32 character hexadecimal string without dashes such as - * "12c2d058d58442709aa2eca08bf20986" or a 36 character hexadecimal string such as such as - * "12c2d058-d584-4270-9aa2-eca08bf20986". - * @return SentryId.empty for invalid strings. - */ -- (instancetype)initWithUUIDString:(NSString *)string; - -/** - * Returns a 32 lowercase character hexadecimal string description of the @c SentryId, such as - * "12c2d058d58442709aa2eca08bf20986". - */ -@property (readonly, copy) NSString *sentryIdString; - -/** - * A @c SentryId with an empty UUID "00000000000000000000000000000000". - */ -@property (class, nonatomic, readonly, strong) SentryId *empty; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryClient.m b/Sources/Sentry/SentryClient.m index d7435185011..3390b4050f2 100644 --- a/Sources/Sentry/SentryClient.m +++ b/Sources/Sentry/SentryClient.m @@ -22,7 +22,6 @@ #import "SentryGlobalEventProcessor.h" #import "SentryHub+Private.h" #import "SentryHub.h" -#import "SentryId.h" #import "SentryInAppLogic.h" #import "SentryInstallation.h" #import "SentryLog.h" diff --git a/Sources/Sentry/SentryEvent.m b/Sources/Sentry/SentryEvent.m index 132617af4ee..4e5b241fe64 100644 --- a/Sources/Sentry/SentryEvent.m +++ b/Sources/Sentry/SentryEvent.m @@ -8,13 +8,13 @@ #import "SentryDependencyContainer.h" #import "SentryEvent+Private.h" #import "SentryException.h" -#import "SentryId.h" #import "SentryInternalDefines.h" #import "SentryLevelMapper.h" #import "SentryMessage.h" #import "SentryMeta.h" #import "SentryRequest.h" #import "SentryStacktrace.h" +#import "SentrySwift.h" #import "SentryThread.h" #import "SentryUser.h" diff --git a/Sources/Sentry/SentryHub.m b/Sources/Sentry/SentryHub.m index 5af2708c927..38994081e8e 100644 --- a/Sources/Sentry/SentryHub.m +++ b/Sources/Sentry/SentryHub.m @@ -8,7 +8,6 @@ #import "SentryEvent+Private.h" #import "SentryFileManager.h" #import "SentryHub+Private.h" -#import "SentryId.h" #import "SentryInstallation.h" #import "SentryLevelMapper.h" #import "SentryLog.h" @@ -22,6 +21,7 @@ #import "SentryScope+Private.h" #import "SentrySerialization.h" #import "SentrySession+Private.h" +#import "SentrySwift.h" #import "SentryTraceOrigins.h" #import "SentryTracer.h" #import "SentryTransaction.h" diff --git a/Sources/Sentry/SentryId.m b/Sources/Sentry/SentryId.m deleted file mode 100644 index 4b09fb20c69..00000000000 --- a/Sources/Sentry/SentryId.m +++ /dev/null @@ -1,102 +0,0 @@ -#import "SentryId.h" -#import - -NS_ASSUME_NONNULL_BEGIN - -static NSString *const emptyUUIDString = @"00000000-0000-0000-0000-000000000000"; - -@interface -SentryId () - -@property (nonatomic, strong) NSUUID *uuid; - -@end - -@implementation SentryId - -static SentryId *_empty = nil; - -+ (void)initialize -{ - if (self == [SentryId class]) { - // Initialize the empty here instead of using a lazy load approach in the getter to avoid - // using a lock to prevent data races. Empty is used at a couple of places in the SDK, so - // potentially minimizing the memory footprint doesn't apply. - _empty = [[SentryId alloc] initWithUUIDString:emptyUUIDString]; - } -} - -- (instancetype)init -{ - return [self initWithUUID:[NSUUID UUID]]; -} - -- (instancetype)initWithUUID:(NSUUID *)uuid -{ - if (self = [super init]) { - self.uuid = uuid; - } - return self; -} - -- (instancetype)initWithUUIDString:(NSString *)string -{ - NSUUID *uuid; - if (string.length == 36) { - uuid = [[NSUUID alloc] initWithUUIDString:string]; - } else if (string.length == 32) { - NSMutableString *mutableString = [[NSMutableString alloc] initWithString:string]; - [mutableString insertString:@"-" atIndex:8]; - [mutableString insertString:@"-" atIndex:13]; - [mutableString insertString:@"-" atIndex:18]; - [mutableString insertString:@"-" atIndex:23]; - - uuid = [[NSUUID alloc] initWithUUIDString:mutableString]; - } - - if (nil != uuid) { - return [self initWithUUID:uuid]; - } else { - return [self initWithUUIDString:emptyUUIDString]; - } -} - -- (NSString *)sentryIdString; -{ - NSString *sentryIdString = [self.uuid.UUIDString stringByReplacingOccurrencesOfString:@"-" - withString:@""]; - return [sentryIdString lowercaseString]; -} - -- (NSString *)description -{ - return [self sentryIdString]; -} - -- (BOOL)isEqual:(id _Nullable)object -{ - if (object == self) { - return YES; - } - if ([self class] != [object class]) { - return NO; - } - - SentryId *otherSentryID = (SentryId *)object; - - return [self.uuid isEqual:otherSentryID.uuid]; -} - -- (NSUInteger)hash -{ - return [self.uuid hash]; -} - -+ (SentryId *)empty -{ - return _empty; -} - -@end - -NS_ASSUME_NONNULL_END diff --git a/Sources/Sentry/SentryNoOpSpan.m b/Sources/Sentry/SentryNoOpSpan.m index 31f4db27068..6b65d59a717 100644 --- a/Sources/Sentry/SentryNoOpSpan.m +++ b/Sources/Sentry/SentryNoOpSpan.m @@ -1,7 +1,7 @@ #import "SentryNoOpSpan.h" -#import "SentryId.h" #import "SentrySpanContext.h" #import "SentrySpanId.h" +#import "SentrySwift.h" #import "SentryTraceHeader.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/SentryProfiler.mm b/Sources/Sentry/SentryProfiler.mm index 5875a7d3cec..6b65e31b869 100644 --- a/Sources/Sentry/SentryProfiler.mm +++ b/Sources/Sentry/SentryProfiler.mm @@ -18,7 +18,6 @@ # import "SentryFormatter.h" # import "SentryFramesTracker.h" # import "SentryHub+Private.h" -# import "SentryId.h" # import "SentryInternalDefines.h" # import "SentryLog.h" # import "SentryMetricProfiler.h" @@ -34,6 +33,7 @@ # import "SentryScope+Private.h" # import "SentrySerialization.h" # import "SentrySpanId.h" +# import "SentrySwift.h" # import "SentrySystemWrapper.h" # import "SentryThread.h" # import "SentryThreadWrapper.h" diff --git a/Sources/Sentry/SentryPropagationContext.m b/Sources/Sentry/SentryPropagationContext.m index 534c89f604a..26b0f427dbc 100644 --- a/Sources/Sentry/SentryPropagationContext.m +++ b/Sources/Sentry/SentryPropagationContext.m @@ -1,11 +1,11 @@ #import "SentryPropagationContext.h" #import "SentryDsn.h" #import "SentryHub+Private.h" -#import "SentryId.h" #import "SentryOptions+Private.h" #import "SentrySDK+Private.h" #import "SentryScope+Private.h" #import "SentrySpanId.h" +#import "SentrySwift.h" #import "SentryTraceContext.h" #import "SentryTraceHeader.h" #import "SentryUser+Private.h" diff --git a/Sources/Sentry/SentrySerialization.m b/Sources/Sentry/SentrySerialization.m index 27fe09500f0..8d87a414ef3 100644 --- a/Sources/Sentry/SentrySerialization.m +++ b/Sources/Sentry/SentrySerialization.m @@ -5,11 +5,11 @@ #import "SentryEnvelopeAttachmentHeader.h" #import "SentryEnvelopeItemType.h" #import "SentryError.h" -#import "SentryId.h" #import "SentryLevelMapper.h" #import "SentryLog.h" #import "SentrySdkInfo.h" #import "SentrySession.h" +#import "SentrySwift.h" #import "SentryTraceContext.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/SentrySpan.m b/Sources/Sentry/SentrySpan.m index 7fd4b4971f5..5148081ff1f 100644 --- a/Sources/Sentry/SentrySpan.m +++ b/Sources/Sentry/SentrySpan.m @@ -5,7 +5,6 @@ #import "SentryCurrentDateProvider.h" #import "SentryDependencyContainer.h" #import "SentryFrame.h" -#import "SentryId.h" #import "SentryInternalDefines.h" #import "SentryLog.h" #import "SentryMeasurementValue.h" @@ -14,6 +13,7 @@ #import "SentrySerializable.h" #import "SentrySpanContext.h" #import "SentrySpanId.h" +#import "SentrySwift.h" #import "SentryThreadInspector.h" #import "SentryTime.h" #import "SentryTraceHeader.h" diff --git a/Sources/Sentry/SentrySpanContext.m b/Sources/Sentry/SentrySpanContext.m index 8f33b3667ae..22add146231 100644 --- a/Sources/Sentry/SentrySpanContext.m +++ b/Sources/Sentry/SentrySpanContext.m @@ -1,8 +1,8 @@ #import "SentrySpanContext.h" -#import "SentryId.h" #import "SentryLog.h" #import "SentrySampleDecision+Private.h" #import "SentrySpanId.h" +#import "SentrySwift.h" #import "SentryTraceOrigins.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/SentryTraceContext.m b/Sources/Sentry/SentryTraceContext.m index 5ec7fd5121b..6675e73ae13 100644 --- a/Sources/Sentry/SentryTraceContext.m +++ b/Sources/Sentry/SentryTraceContext.m @@ -2,12 +2,12 @@ #import "SentryBaggage.h" #import "SentryDefines.h" #import "SentryDsn.h" -#import "SentryId.h" #import "SentryLog.h" #import "SentryOptions+Private.h" #import "SentrySampleDecision.h" #import "SentryScope+Private.h" #import "SentrySerialization.h" +#import "SentrySwift.h" #import "SentryTracer.h" #import "SentryTransactionContext.h" #import "SentryUser.h" diff --git a/Sources/Sentry/SentryTraceHeader.m b/Sources/Sentry/SentryTraceHeader.m index 53ad0847789..7a4d710c1ee 100644 --- a/Sources/Sentry/SentryTraceHeader.m +++ b/Sources/Sentry/SentryTraceHeader.m @@ -1,6 +1,6 @@ #import "SentryTraceHeader.h" -#import "SentryId.h" #import "SentrySpanId.h" +#import "SentrySwift.h" NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Sentry/SentryUserFeedback.m b/Sources/Sentry/SentryUserFeedback.m index aa7a982b327..fc43f4bb2c8 100644 --- a/Sources/Sentry/SentryUserFeedback.m +++ b/Sources/Sentry/SentryUserFeedback.m @@ -1,5 +1,5 @@ #import "SentryUserFeedback.h" -#import "SentryId.h" +#import "SentrySwift.h" #import @implementation SentryUserFeedback diff --git a/Sources/Sentry/include/SentryProfiledTracerConcurrency.h b/Sources/Sentry/include/SentryProfiledTracerConcurrency.h index 438028d67b3..68f1194d4db 100644 --- a/Sources/Sentry/include/SentryProfiledTracerConcurrency.h +++ b/Sources/Sentry/include/SentryProfiledTracerConcurrency.h @@ -1,9 +1,8 @@ #import "SentryCompiler.h" -#import "SentryId.h" #import "SentryProfilingConditionals.h" #import -@class SentryProfiler; +@class SentryProfiler, SentryId; #if SENTRY_TARGET_PROFILING_SUPPORTED diff --git a/Sources/Sentry/include/SentrySwift.h b/Sources/Sentry/include/SentrySwift.h index 7a1392671d6..e8b4a6e2524 100644 --- a/Sources/Sentry/include/SentrySwift.h +++ b/Sources/Sentry/include/SentrySwift.h @@ -1,6 +1,12 @@ #ifndef SentrySwift_h #define SentrySwift_h +#ifdef __cplusplus +# if __has_include() +# import +# endif +#endif + #if __has_include("Sentry-Swift.h") # import "Sentry-Swift.h" #else diff --git a/Sources/Sentry/include/SentryTraceContext.h b/Sources/Sentry/include/SentryTraceContext.h index cef6f4f4c1e..5cbf0c5f94e 100644 --- a/Sources/Sentry/include/SentryTraceContext.h +++ b/Sources/Sentry/include/SentryTraceContext.h @@ -4,10 +4,10 @@ # import "SentrySerializable.h" #endif -#if __has_include() -# import +#if __has_include() +# import #else -# import "SentryId.h" +# import "SentrySwift.h" #endif NS_ASSUME_NONNULL_BEGIN diff --git a/Sources/Swift/Extensions/StringExtensions.swift b/Sources/Swift/Extensions/StringExtensions.swift new file mode 100644 index 00000000000..49b3e0002d2 --- /dev/null +++ b/Sources/Swift/Extensions/StringExtensions.swift @@ -0,0 +1,40 @@ +import Foundation + +extension String { + /// Retrieve a character at a specific index in the string. + subscript (value: Int) -> Character { + return self[index(startIndex, offsetBy: value)] + } + + /// Retrieve a substring within a countable range of indices. + subscript (range: CountableRange) -> Substring { + let start = index(startIndex, offsetBy: range.lowerBound) + let end = index(startIndex, offsetBy: range.upperBound) + return self[start..) -> Substring { + let start = index(startIndex, offsetBy: range.lowerBound) + let end = index(startIndex, offsetBy: range.upperBound) + return self[start...end] + } + + /// Retrieve a substring up to a specified index. + subscript (range: PartialRangeThrough) -> Substring { + let end = index(startIndex, offsetBy: range.upperBound) + return self[startIndex...end] + } + + /// Retrieve a substring from a specified index to the end of the string. + subscript (range: CountablePartialRangeFrom) -> Substring { + let start = index(startIndex, offsetBy: range.lowerBound) + return self[start..) -> Substring { + let end = index(startIndex, offsetBy: range.upperBound) + return self[startIndex.. Bool { + guard let other = object as? SentryId else { return false } + return other.id == self.id + } + + override public var description: String { + sentryIdString + } + + override public var hash: Int { + id.hashValue + } +} diff --git a/Tests/SentryProfilerTests/SentryProfilerTests.mm b/Tests/SentryProfilerTests/SentryProfilerTests.mm index ddeed62c428..840a9220af6 100644 --- a/Tests/SentryProfilerTests/SentryProfilerTests.mm +++ b/Tests/SentryProfilerTests/SentryProfilerTests.mm @@ -1,6 +1,5 @@ #import "SentryEvent+Private.h" #import "SentryHub+Test.h" -#import "SentryId.h" #import "SentryProfileTimeseries.h" #import "SentryProfiler+Private.h" #import "SentryProfiler+Test.h" @@ -8,6 +7,7 @@ #import "SentryProfilerState+ObjCpp.h" #import "SentryProfilingConditionals.h" #import "SentryScreenFrames.h" +#import "SentrySwift.h" #import "SentryThread.h" #import "SentryTransaction.h" #import "SentryTransactionContext+Private.h" diff --git a/Tests/SentryTests/SentryInterfacesTests.m b/Tests/SentryTests/SentryInterfacesTests.m index eaa4902954b..d344bd1d4f4 100644 --- a/Tests/SentryTests/SentryInterfacesTests.m +++ b/Tests/SentryTests/SentryInterfacesTests.m @@ -6,10 +6,10 @@ #import "SentryException.h" #import "SentryFileManager.h" #import "SentryFrame.h" -#import "SentryId.h" #import "SentryMechanism.h" #import "SentryMeta.h" #import "SentryStackTrace.h" +#import "SentrySwift.h" #import "SentryThread.h" #import "SentryUser.h" diff --git a/Tests/SentryTests/SentryTests-Bridging-Header.h b/Tests/SentryTests/SentryTests-Bridging-Header.h index b633f50edf1..6a81b99df9c 100644 --- a/Tests/SentryTests/SentryTests-Bridging-Header.h +++ b/Tests/SentryTests/SentryTests-Bridging-Header.h @@ -119,7 +119,6 @@ #import "SentryHttpTransport.h" #import "SentryHub+Private.h" #import "SentryHub+Test.h" -#import "SentryId.h" #import "SentryInAppLogic.h" #import "SentryInitializeForGettingSubclassesNotCalled.h" #import "SentryInstallation+Test.h" @@ -165,6 +164,7 @@ #import "SentryScreenshot.h" #import "SentryScreenshotIntegration.h" #import "SentrySdkInfo.h" +#import "SentrySwift.h" #import "SentrySwiftAsyncIntegration.h" #import "Sentry/Sentry-Swift.h" diff --git a/Tests/SentryTests/StringExtensionTests.swift b/Tests/SentryTests/StringExtensionTests.swift new file mode 100644 index 00000000000..2d0a8ff390b --- /dev/null +++ b/Tests/SentryTests/StringExtensionTests.swift @@ -0,0 +1,45 @@ +import Foundation +import Nimble +@testable import Sentry +import XCTest + +class StringExtensionTests: XCTestCase { + + func testSingleCharacterSubscript() { + let testString = "Hello, World!" + expect(testString[0]) == "H" + expect(testString[7]) == "W" + expect(testString[12]) == "!" + } + + func testRangeOfCharactersSubscript() { + let testString = "Hello, World!" + expect(testString[1..<5]) == "ello" + expect(testString[7...11]) == "World" + expect(testString[3...3]) == "l" + expect(testString[1...5]) == "ello," + expect(testString[7...11]) == "World" + expect(testString[0...0]) == "H" + } + + func testPartialRangeThroughSubscript() { + let testString = "Hello, World!" + expect(testString[...5]) == "Hello," + expect(testString[...4]) == "Hello" + expect(testString[...0]) == "H" + } + + func testPartialRangeFromSubscript() { + let testString = "Hello, World!" + expect(testString[7...]) == "World!" + expect(testString[0...]) == "Hello, World!" + expect(testString[5...]) == ", World!" + } + + func testPartialRangeUpToSubscript() { + let testString = "Hello, World!" + expect(testString[..<5]) == "Hello" + expect(testString[..<4]) == "Hell" + expect(testString[..<0]) == "" + } +}