diff --git a/Sources/Datadog/Datadog.swift b/Sources/Datadog/Datadog.swift index c02374bec5..872daca099 100644 --- a/Sources/Datadog/Datadog.swift +++ b/Sources/Datadog/Datadog.swift @@ -102,6 +102,11 @@ public class Datadog { } } + /// Returns `true` if the Datadog SDK is already initialized, `false` otherwise. + public static var isInitialized: Bool { + return instance != nil + } + /// Sets current user information. /// Those will be added to logs, traces and RUM events automatically. /// - Parameters: diff --git a/Tests/DatadogTests/Datadog/DatadogTests.swift b/Tests/DatadogTests/Datadog/DatadogTests.swift index 88ea4cf0af..85cb36b22f 100644 --- a/Tests/DatadogTests/Datadog/DatadogTests.swift +++ b/Tests/DatadogTests/Datadog/DatadogTests.swift @@ -18,7 +18,7 @@ class DatadogTests: XCTestCase { override func setUp() { super.setUp() - XCTAssertNil(Datadog.instance) + XCTAssertFalse(Datadog.isInitialized) printFunction = PrintFunctionMock() consolePrint = printFunction.print } @@ -26,7 +26,7 @@ class DatadogTests: XCTestCase { override func tearDown() { consolePrint = { print($0) } printFunction = nil - XCTAssertNil(Datadog.instance) + XCTAssertFalse(Datadog.isInitialized) super.tearDown() } @@ -38,7 +38,7 @@ class DatadogTests: XCTestCase { trackingConsent: .mockRandom(), configuration: defaultBuilder.build() ) - XCTAssertNotNil(Datadog.instance) + XCTAssertTrue(Datadog.isInitialized) Datadog.flushAndDeinitialize() } @@ -48,7 +48,7 @@ class DatadogTests: XCTestCase { trackingConsent: .mockRandom(), configuration: rumBuilder.build() ) - XCTAssertNotNil(Datadog.instance) + XCTAssertTrue(Datadog.isInitialized) Datadog.flushAndDeinitialize() } @@ -67,7 +67,7 @@ class DatadogTests: XCTestCase { printFunction.printedMessage, "🔥 Datadog SDK usage error: `clientToken` cannot be empty." ) - XCTAssertNil(Datadog.instance) + XCTAssertFalse(Datadog.isInitialized) } func testGivenValidConfiguration_whenInitializedMoreThanOnce_itPrintsError() {