Skip to content

Commit

Permalink
chore: Move SentryDefine enums to swift (#3963)
Browse files Browse the repository at this point in the history
We can't use Objective-C enums from Swift as a function argument without breaking TestUtil compilation, but we can use Swift int enums from Objective-C.

Session Replay will need SentryLevel, so a move it to swift, alongside with it I also moved SentryTransactionNameSource, both from SentryDefines.h
  • Loading branch information
brustolin authored May 17, 2024
1 parent 0af45a9 commit 699d76f
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 27 deletions.
24 changes: 24 additions & 0 deletions Sentry.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,8 @@
D86B7B5C2B7A529C0017E8D9 /* SentryReplayEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = D86B7B5A2B7A529C0017E8D9 /* SentryReplayEvent.h */; };
D86B7B5D2B7A529C0017E8D9 /* SentryReplayEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = D86B7B5B2B7A529C0017E8D9 /* SentryReplayEvent.m */; };
D86F419827C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = D86F419727C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift */; };
D8739CF32BECF70F007D2F66 /* SentryLevel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8739CF22BECF70F007D2F66 /* SentryLevel.swift */; };
D8739CF92BECFFB5007D2F66 /* SentryTransactionNameSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8739CF82BECFFB5007D2F66 /* SentryTransactionNameSource.swift */; };
D8751FA5274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */; };
D875ED0B276CC84700422FAC /* SentryNSDataTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */; };
D87C89032BC43C9C0086C7DF /* SentryRedactOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D87C89022BC43C9C0086C7DF /* SentryRedactOptions.swift */; };
Expand Down Expand Up @@ -1888,6 +1890,8 @@
D86B7B5A2B7A529C0017E8D9 /* SentryReplayEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SentryReplayEvent.h; path = include/SentryReplayEvent.h; sourceTree = "<group>"; };
D86B7B5B2B7A529C0017E8D9 /* SentryReplayEvent.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SentryReplayEvent.m; sourceTree = "<group>"; };
D86F419727C8FEFA00490520 /* SentryCoreDataTrackerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryCoreDataTrackerExtension.swift; sourceTree = "<group>"; };
D8739CF22BECF70F007D2F66 /* SentryLevel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryLevel.swift; sourceTree = "<group>"; };
D8739CF82BECFFB5007D2F66 /* SentryTransactionNameSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryTransactionNameSource.swift; sourceTree = "<group>"; };
D8751FA4274743710032F4DE /* SentryNSURLSessionTaskSearchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SentryNSURLSessionTaskSearchTests.swift; sourceTree = "<group>"; };
D8757D142A209F7300BFEFCC /* SentrySampleDecision+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "SentrySampleDecision+Private.h"; path = "include/SentrySampleDecision+Private.h"; sourceTree = "<group>"; };
D875ED0A276CC84700422FAC /* SentryNSDataTrackerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SentryNSDataTrackerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2043,6 +2047,7 @@
621D9F2D2B9B030E003D94DE /* Helper */ = {
isa = PBXGroup;
children = (
D8739CF62BECFF86007D2F66 /* Log */,
621D9F2E2B9B0320003D94DE /* SentryCurrentDateProvider.swift */,
621F61F02BEA073A005E654F /* SentryEnabledFeaturesBuilder.swift */,
);
Expand Down Expand Up @@ -3680,6 +3685,22 @@
name = CoreData;
sourceTree = "<group>";
};
D8739CF62BECFF86007D2F66 /* Log */ = {
isa = PBXGroup;
children = (
D8739CF22BECF70F007D2F66 /* SentryLevel.swift */,
);
path = Log;
sourceTree = "<group>";
};
D8739CF72BECFF92007D2F66 /* Performance */ = {
isa = PBXGroup;
children = (
D8739CF82BECFFB5007D2F66 /* SentryTransactionNameSource.swift */,
);
path = Performance;
sourceTree = "<group>";
};
D875ED09276CC83200422FAC /* IO */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3801,6 +3822,7 @@
D8CAC02D2BA0663E00E38F34 /* Integrations */ = {
isa = PBXGroup;
children = (
D8739CF72BECFF92007D2F66 /* Performance */,
D8CAC02C2BA0663E00E38F34 /* SessionReplay */,
);
path = Integrations;
Expand Down Expand Up @@ -4488,6 +4510,7 @@
7B30B67E26527894006B2752 /* SentryDisplayLinkWrapper.m in Sources */,
63FE711D20DA4C1000CDBAE8 /* SentryCrashCPU_arm64.c in Sources */,
844EDC77294144DB00C86F34 /* SentrySystemWrapper.mm in Sources */,
D8739CF92BECFFB5007D2F66 /* SentryTransactionNameSource.swift in Sources */,
630435FF1EBCA9D900C4D3FA /* SentryNSURLRequest.m in Sources */,
62C1AFAB2B7E10EA0038C5F7 /* SentrySpotlightTransport.m in Sources */,
D87C892B2BC67BC20086C7DF /* SentryExperimentalOptions.swift in Sources */,
Expand Down Expand Up @@ -4555,6 +4578,7 @@
638DC9A11EBC6B6400A66E41 /* SentryRequestOperation.m in Sources */,
63AA767A1EB8D20500D153DE /* SentryLog.m in Sources */,
6344DDBA1EC3115C00D9160D /* SentryCrashReportConverter.m in Sources */,
D8739CF32BECF70F007D2F66 /* SentryLevel.swift in Sources */,
63FE70FD20DA4C1000CDBAE8 /* SentryCrashCachedData.c in Sources */,
A8F17B2E2901765900990B25 /* SentryRequest.m in Sources */,
7BE1E33424F7E3CB009D3AD0 /* SentryMigrateSessionInit.m in Sources */,
Expand Down
22 changes: 4 additions & 18 deletions Sources/Sentry/Public/SentryDefines.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,8 @@ typedef NS_ENUM(NSInteger, SentryLogLevel) {
/**
* Sentry level.
*/
typedef NS_ENUM(NSUInteger, SentryLevel) {
// Defaults to None which doesn't get serialized
kSentryLevelNone = 0,
// Goes from Debug to Fatal so possible to: (level > Info) { .. }
kSentryLevelDebug = 1,
kSentryLevelInfo = 2,
kSentryLevelWarning = 3,
kSentryLevelError = 4,
kSentryLevelFatal = 5
};
typedef NS_ENUM(NSUInteger,
SentryLevel); // This is a forward declaration, the actual enum is implemented in Swift.

/**
* Static internal helper to convert enum to string.
Expand All @@ -166,11 +158,5 @@ static NSString *_Nonnull const kSentryFalseString = @"false";
/**
* Transaction name source.
*/
typedef NS_ENUM(NSInteger, SentryTransactionNameSource) {
kSentryTransactionNameSourceCustom = 0,
kSentryTransactionNameSourceUrl,
kSentryTransactionNameSourceRoute,
kSentryTransactionNameSourceView,
kSentryTransactionNameSourceComponent,
kSentryTransactionNameSourceTask
};
typedef NS_ENUM(NSInteger, SentryTransactionNameSource); // This is a forward declaration, the
// actual enum is implemented in Swift.
1 change: 1 addition & 0 deletions Sources/Sentry/SentryBreadcrumb.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "SentryDateUtils.h"
#import "SentryLevelMapper.h"
#import "SentryNSDictionarySanitize.h"
#import "SentrySwift.h"

@interface
SentryBreadcrumb ()
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/SentryLevelMapper.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#import "SentryLevelMapper.h"

#import "SentrySwift.h"
NS_ASSUME_NONNULL_BEGIN

NSString *const kSentryLevelNameNone = @"none";
Expand Down
1 change: 1 addition & 0 deletions Sources/Sentry/SentryTransaction.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#import "SentryEnvelopeItemType.h"
#import "SentryMeasurementValue.h"
#import "SentryNSDictionarySanitize.h"
#import "SentrySwift.h"
#import "SentryTransactionContext.h"

NS_ASSUME_NONNULL_BEGIN
Expand Down
1 change: 1 addition & 0 deletions Sources/Sentry/include/SentryLog.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "SentryDefines.h"
#import "SentrySwift.h"

@class SentryLogOutput;

Expand Down
9 changes: 1 addition & 8 deletions Sources/SentrySwiftUI/SentryInternal/SentryInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@

NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, SentryTransactionNameSource) {
kSentryTransactionNameSourceCustom = 0,
kSentryTransactionNameSourceUrl,
kSentryTransactionNameSourceRoute,
kSentryTransactionNameSourceView,
kSentryTransactionNameSourceComponent,
kSentryTransactionNameSourceTask
};
typedef NS_ENUM(NSInteger, SentryTransactionNameSource);

@class SentrySpanId;
@protocol SentrySpan;
Expand Down
23 changes: 23 additions & 0 deletions Sources/Swift/Helper/Log/SentryLevel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation

@objc
public enum SentryLevel: UInt {
@objc(kSentryLevelNone)
case none = 0

// Goes from Debug to Fatal so possible to: (level > Info) { .. }
@objc(kSentryLevelDebug)
case debug = 1

@objc(kSentryLevelInfo)
case info = 2

@objc(kSentryLevelWarning)
case warning = 3

@objc(kSentryLevelError)
case error = 4

@objc(kSentryLevelFatal)
case fatal = 5
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Foundation

@objc
public enum SentryTransactionNameSource: Int {
@objc(kSentryTransactionNameSourceCustom)
case custom = 0

@objc(kSentryTransactionNameSourceUrl)
case url

@objc(kSentryTransactionNameSourceRoute)
case route

@objc(kSentryTransactionNameSourceView)
case view

@objc(kSentryTransactionNameSourceComponent)
case component

@objc(kSentryTransactionNameSourceTask)
case sourceTask
}
1 change: 1 addition & 0 deletions Tests/SentryTests/SentryKSCrashReportConverterTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import "SentryThread.h"
#import "SentryUser.h"
#import <XCTest/XCTest.h>
@import Sentry;

@interface SentryCrashReportConverterTests : XCTestCase

Expand Down
1 change: 1 addition & 0 deletions Tests/SentryTests/SentryScopeTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#import "SentryScope.h"
#import "SentryUser.h"
#import <XCTest/XCTest.h>
@import Sentry;

@interface SentryScopeTests : XCTestCase

Expand Down
1 change: 1 addition & 0 deletions Tests/SentryTests/SentryTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "SentryOptions+HybridSDKs.h"
#import "SentrySDK+Private.h"
#import <XCTest/XCTest.h>
@import Sentry;

@interface
SentryBreadcrumbTracker ()
Expand Down

0 comments on commit 699d76f

Please sign in to comment.