I can't figure out how I can fix this error.
If I remove @Published, it compiles everything correct but then I can't see the data in a cell in real time. Reading I saw that I need the var with @Published
import SwiftUI
import Combine
class TimeModel: Codable, Identifiable, ObservableObject {
@Published var id: UUID = UUID()
@Published var nome : String
@Published var time : String
func aggiornaUI() {
DispatchQueue.main.async {
self.objectWillChange.send()
}
}
init(nome: String, time: String) {
self.nome = nome
self.time = time
}
}
Update: ok thanks I check now but the error remain
HStack {
Text("\(timeString(from: Int(TimeInterval(remainingSeconds))))")
.onReceive(timer) { _ in
if isCounting && remainingSeconds > 0 {
remainingSeconds -= 1
}
}
error:
Instance method 'onReceive(_:perform:)' requires that 'TimeModel' conform to 'Publisher'