Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CoreInternal] Address Swift 6 warnings (1) #13454

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,28 @@ import Foundation

/// An object that provides API to log and flush heartbeats from a synchronized storage container.
public final class HeartbeatController {
/// Used for standardizing dates for calendar-day comparison.
private enum DateStandardizer {
private static let calendar: Calendar = {
var calendar = Calendar(identifier: .iso8601)
calendar.locale = Locale(identifier: "en_US_POSIX")
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
return calendar
}()

static func standardize(_ date: Date) -> (Date) {
return calendar.startOfDay(for: date)
}
}

/// The thread-safe storage object to log and flush heartbeats from.
private let storage: HeartbeatStorageProtocol
/// The max capacity of heartbeats to store in storage.
private let heartbeatsStorageCapacity: Int = 30
/// Current date provider. It is used for testability.
private let dateProvider: () -> Date
/// Used for standardizing dates for calendar-day comparison.
static let dateStandardizer: (Date) -> (Date) = {
var calendar = Calendar(identifier: .iso8601)
calendar.locale = Locale(identifier: "en_US_POSIX")
calendar.timeZone = TimeZone(secondsFromGMT: 0)!
return calendar.startOfDay(for:)
}()
private static let dateStandardizer = DateStandardizer.self

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

/// Asynchronously logs a new heartbeat, if needed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public protocol HTTPHeaderRepresentable {
/// ]
/// }
///
public struct HeartbeatsPayload: Codable {
public struct HeartbeatsPayload: Codable, Sendable {
/// The version of the payload. See go/firebase-apple-heartbeats for details regarding current
/// version.
static let version: Int = 2
Expand Down
Loading