Skip to content

Create an ObjC SDK #6342

@noahsmartin

Description

@noahsmartin

Problem Statement

The current SDK aims to support both Swift and ObjC projects. However, we want to use Swift only APIs, such as enums with associated values, to improve the public interface for Swift users. This however would break objc users. To still support ObjC we should create a new SDK that wraps the Swift one. It would also be written in Swift so that it can access the Swift only APIs, but it would wrap them in an objc interface using @objc.

For example if the Swift SDK had:

public struct Options {
  enum AppHangTrackingType {
    case .disabled
    case .enabled(hangDuration: Int)
    case .v2(hangDuration: Int)
  }

  public let appHangTracking: AppHangTrackingType
}

The ObjC SDK could have:

import Sentry

@objc public final class SentryOptions: NSObject {
  @objc public var enableAppHangTracking: Bool = false
  @objc public var enableAppHangTrackingV2: Bool = false
  @objc public var hangDuration: Int = 0

  func makeOptions() -> Sentry.Options {
    var appHangTracking = Sentry.Options.AppHangTrackingType.disabled
    if enableAppHangTracking {
        appHangTracking = .enabled(hangDuration)
    } else if enableAppHangTrackingV2 {
        appHangTracking = .v2(hangDuration)
    }
    return .init(appHangTracking: appHangTracking)
  }
}

If we further want to support ObjC that doesn't use modules, such as ObjC++ in #4543, then we could make another SDK that wraps the Swift+@objc one that is written entirely in ObjC. This would then be able to be imported without a module import

None of this needs to be tied to any particular version release since it is purely additive, it should probably come after releasing a V9 SDK

Solution Brainstorm

No response

Are you willing to submit a PR?

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions