Skip to content

Commit 021cb5e

Browse files
authored
[CoreInternal] Address Swift 6 warnings (1) (#13454)
1 parent c399917 commit 021cb5e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatController.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,28 @@ import Foundation
1616

1717
/// An object that provides API to log and flush heartbeats from a synchronized storage container.
1818
public final class HeartbeatController {
19+
/// Used for standardizing dates for calendar-day comparison.
20+
private enum DateStandardizer {
21+
private static let calendar: Calendar = {
22+
var calendar = Calendar(identifier: .iso8601)
23+
calendar.locale = Locale(identifier: "en_US_POSIX")
24+
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
25+
return calendar
26+
}()
27+
28+
static func standardize(_ date: Date) -> (Date) {
29+
return calendar.startOfDay(for: date)
30+
}
31+
}
32+
1933
/// The thread-safe storage object to log and flush heartbeats from.
2034
private let storage: HeartbeatStorageProtocol
2135
/// The max capacity of heartbeats to store in storage.
2236
private let heartbeatsStorageCapacity: Int = 30
2337
/// Current date provider. It is used for testability.
2438
private let dateProvider: () -> Date
2539
/// Used for standardizing dates for calendar-day comparison.
26-
static let dateStandardizer: (Date) -> (Date) = {
27-
var calendar = Calendar(identifier: .iso8601)
28-
calendar.locale = Locale(identifier: "en_US_POSIX")
29-
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
30-
return calendar.startOfDay(for:)
31-
}()
40+
private static let dateStandardizer = DateStandardizer.self
3241

3342
/// Public initializer.
3443
/// - Parameter id: The `id` to associate this controller's heartbeat storage with.
@@ -54,7 +63,7 @@ public final class HeartbeatController {
5463
init(storage: HeartbeatStorageProtocol,
5564
dateProvider: @escaping () -> Date = Date.init) {
5665
self.storage = storage
57-
self.dateProvider = { Self.dateStandardizer(dateProvider()) }
66+
self.dateProvider = { Self.dateStandardizer.standardize(dateProvider()) }
5867
}
5968

6069
/// Asynchronously logs a new heartbeat, if needed.

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsPayload.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public protocol HTTPHeaderRepresentable {
4444
/// ]
4545
/// }
4646
///
47-
public struct HeartbeatsPayload: Codable {
47+
public struct HeartbeatsPayload: Codable, Sendable {
4848
/// The version of the payload. See go/firebase-apple-heartbeats for details regarding current
4949
/// version.
5050
static let version: Int = 2

0 commit comments

Comments
 (0)