Skip to content

ref: SentryOptions in Swift #6690

@github-actions

Description

@github-actions

Note

The pull request "ref: SentryOptions in Swift" was created by @noahsmartin but did not reference an issue. Therefore this issue was created for better visibility in external tools like Linear.

This change may look big, but I've done everything that can be done to make it as small as possible. It only looks big because the generated API json file changed, the actual lines of code added are ~800. So many files were touched because I had to remove a bunch of imports of the objc class

This converts SentryOptions.h/.m to SentryOptions.swift and in doing so removes the last blocker for using SPM. It also cleans up a lot of gross bridging we had to do, like with SentryExperimentalOptions and the beforeSendLog callback. This is now replaced with one piece of cross bridging, which I'll get to later...

Almost all the relevant implementation here is in Options.swift. This matches the old ObjC API almost exactly, except that the class is now final. The API json file changed a lot structurally just because it represents Swift and ObjC differently, not because the actual API changed.

The tricky part of this is that we can't call an objc header that uses a swift type from Swift code. (This works in xcodebuild but not cocoapods/SPM) To work around this the value that gets passed toSentrySDKInternal needs to be type-erased. This is the same as what we had to do with types defined in Swift on SentryOptions.h prior to this PR. To make it easy to follow this change I've kept the Swift type almost everywhere, but in a few header files I had to use SentryOptionsObjc which is just an alias for NSObject. There are extensions at the end of Options.swift that explains what is done in more detail.

#skip-changelog

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions