I am wondering why I am not required to provide any parameters at the call site of the function on line 19
I have a strong feeling its because of the static
keyword on the function but I still would like more clarity / insight. Thanks
Code in text form below (if it helps)
import SwiftUI
import Combine
final class CurrentTime: ObservableObject {
@Published var seconds: TimeInterval = CurrentTime.currentSecond(date: Date())
private let timer = Timer.publish(every: 0.2, on: .main, in: .default).autoconnect()
private var store = Set<AnyCancellable>()
init() {
timer.map(Self.currentSecond).assign(to: \.seconds, on: self).store(in: &store) // <-- Why am I not asked for a parameter here
}
private static func currentSecond(date: Date) -> TimeInterval {
let components = Calendar.current.dateComponents([.year, .month, .day], from: date)
let referenceDate = Calendar.current.date(from: DateComponents(year: components.year!, month: components.month!, day: components.day!))!
return Date().timeIntervalSince(referenceDate)
}
}