im getting this error after this code, what module should Iimport here? or does it causes any other problem?
// ContentView.swift
// Widget_and_LiveActivities
//
// Created by Makwin Santhosh K on 20/11/22.
//
import SwiftUI
import ClockKit
struct ContentView: View {
var body: some View {
var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ?? 0), to: Date())! // here is where im getting (cannot find 'minutes' in the scope)
future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ?? 0), to: future)! // also where is where im getting (cannot find 'seconds' in the scope)
let date = Date.now...future
let updatedDeliveryStatus = PizzaDeliveryAttributes.PizzaDeliveryStatus(driverName: "Anne Johnson", deliveryTimer: date)
let alertConfiguration = AlertConfiguration(title: "Delivery Update", body: "Your pizza order will arrive in 25 minutes.", sound: .default)
await deliveryActivity?.update(using: updatedDeliveryStatus, alertConfiguration: alertConfiguration)
let initialContentState = PizzaDeliveryAttributes.ContentState(driverName: "Bill James", deliveryTimer:date)
let activityAttributes = PizzaDeliveryAttributes(numberOfPizzas: 3, totalAmount: "$42.00", orderNumber: "12345")
do {
deliveryActivity = try Activity.request(attributes: activityAttributes, contentState: initialContentState)
print("Requested a pizza delivery Live Activity \(String(describing: deliveryActivity?.id)).")
} catch (let error) {
print("Error requesting pizza delivery Live Activity \(error.localizedDescription).")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
// this is the example code from
[https://developer.apple.com/documentation/activitykit/displaying-live-data-with-live-activities)
Sorry, but I still do not catch it.
I tested the following which works:
struct ContentView: View {
let start = Date()
let future = Calendar.current.date(byAdding: .minute, value: 10, to: Date())!
var deliveryTimer: ClosedRange<Date> {
start...future
}
var body: some View {
Text(timerInterval: deliveryTimer, countsDown: true)
}
}
In the following
var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ), to: Date())!
you use minutes. Where is the String minutes
defined ?
if you change to
var future = Calendar.current.date(byAdding: .minute, value: 10, to: Date())!
That does work