Post

Replies

Boosts

Views

Activity

Reply to Publishing changes from within view updates is not allowed, this will cause undefined behavior.
also I have doubt I have created this code in separate SwiftUI File (MapView) let say if I call it in ContentView like MapView() the location button is not functioning as it is programmed (in here it is programmed to show the current location but after calling the MapView in ContentView, the button is not working) how should I make this button work after calling the MapView File in Content View
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Nov ’22
Reply to cannot find 'minutes' in the scope
and I have clearly checked the code and here is my doubt I have set deliveryTimer to be ClosedRange data format so to get ClosedRange input so if I give Minutes and Seconds as variable it is showing error in Timer I have added the code below which the data transfers from Content view to this view seeing this might give you a idea import WidgetKit import SwiftUI import Foundation struct dynamicIsland : Widget {          var body: some WidgetConfiguration{         ActivityConfiguration(for: PizzaDeliveryAttributes.self) { context in                          LockScreenLiveActivityView(context: context)         } dynamicIsland: { context in             DynamicIsland{                                  DynamicIslandExpandedRegion(.leading){                     Label("\(context.attributes.numberOfPizzas) Pizzas", systemImage: "bag")                         .foregroundColor(.indigo)                         .font(.title2)                 }                 DynamicIslandExpandedRegion(.trailing) {                     Label {                         Text(timerInterval: context.state.deliveryTimer, countsDown: true)                             .multilineTextAlignment(.trailing)                             .frame(width: 50)                             .monospacedDigit()                     } icon: {                         Image(systemName: "timer")                             .foregroundColor(.indigo)                     }                     .font(.title2)                 }                                  DynamicIslandExpandedRegion(.center) {                     Text("\(context.state.driverName) is on their way!")                         .lineLimit(1)                         .font(.caption)                 }                                  DynamicIslandExpandedRegion(.bottom) {                     Button {                         // Deep link into your app.                     } label: {                         Label("Call driver", systemImage: "phone")                     }                     .foregroundColor(.indigo)                 }             } compactLeading: {                 // Create the compact leading presentation.                 // ...             } compactTrailing: {                 // Create the compact trailing presentation.                 // ...             } minimal: {                 // Create the minimal presentation.                 // ...             }             .contentMargins(.trailing, 8, for: .expanded)             .keylineTint(.yellow)         }     } }                           struct LockScreenLiveActivityView: View {             let context: ActivityViewContext<PizzaDeliveryAttributes>                          var body: some View {                 VStack {                     Spacer()                     Text("\(context.state.driverName) is on their way with your pizza!")                     Spacer()                     HStack {                         Spacer()                         Label {                             Text("\(context.attributes.numberOfPizzas) Pizzas")                         } icon: {                             Image(systemName: "bag")                                 .foregroundColor(.indigo)                         }                         .font(.title2)                         Spacer()                         Label {                             Text(timerInterval: context.state.deliveryTimer, countsDown: true) // im getting error here if I give var minutes = 10 something like this, it gives error (I think for ClosedRange<date> the input that we should give is in different format)                                 .multilineTextAlignment(.center)                                 .frame(width: 50)                                 .monospacedDigit()                         } icon: {                             Image(systemName: "timer")                                 .foregroundColor(.indigo)                         }                         .font(.title2)                         Spacer()                     }                     Spacer()                 }                 .activitySystemActionForegroundColor(.indigo)                 .activityBackgroundTint(.cyan)             }         }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Reply to cannot find 'minutes' in the scope
import WidgetKit import SwiftUI import Foundation struct dynamicIsland : Widget {          var body: some WidgetConfiguration{         ActivityConfiguration(for: PizzaDeliveryAttributes.self) { context in                          LockScreenLiveActivityView(context: context)         } dynamicIsland: { context in             DynamicIsland{                                  DynamicIslandExpandedRegion(.leading){                     Label("\(context.attributes.numberOfPizzas) Pizzas", systemImage: "bag")                         .foregroundColor(.indigo)                         .font(.title2)                 }                 DynamicIslandExpandedRegion(.trailing) {                     Label {                         Text(timerInterval: context.state.deliveryTimer , countsDown: true)                             .multilineTextAlignment(.trailing)                             .frame(width: 50)                             .monospacedDigit()                     } icon: {                         Image(systemName: "timer")                             .foregroundColor(.indigo)                     }                     .font(.title2)                 }                                  DynamicIslandExpandedRegion(.center) {                     Text("\(context.state.driverName) is on their way!")                         .lineLimit(1)                         .font(.caption)                 }                                  DynamicIslandExpandedRegion(.bottom) {                     Button {                         // Deep link into your app.                     } label: {                         Label("Call driver", systemImage: "phone")                     }                     .foregroundColor(.indigo)                 }             } compactLeading: {                 // Create the compact leading presentation.                 // ...             } compactTrailing: {                 // Create the compact trailing presentation.                 // ...             } minimal: {                 // Create the minimal presentation.                 // ...             }             .contentMargins(.trailing, 8, for: .expanded)             .keylineTint(.yellow)         }     } }                           struct LockScreenLiveActivityView: View {             let context: ActivityViewContext<PizzaDeliveryAttributes>                          var body: some View {                 VStack {                     Spacer()                     Text("\(context.state.driverName) is on their way with your pizza!")                     Spacer()                     HStack {                         Spacer()                         Label {                             Text("\(context.attributes.numberOfPizzas) Pizzas")                         } icon: {                             Image(systemName: "bag")                                 .foregroundColor(.indigo)                         }                         .font(.title2)                         Spacer()                         Label {                             Text(timerInterval: context.state.deliveryTimer, countsDown: true)                                 .multilineTextAlignment(.center)                                 .frame(width: 50)                                 .monospacedDigit()                         } icon: {                             Image(systemName: "timer")                                 .foregroundColor(.indigo)                         }                         .font(.title2)                         Spacer()                     }                     Spacer()                 }                 .activitySystemActionForegroundColor(.indigo)                 .activityBackgroundTint(.cyan)             }         }     struct PizzaDeliveryAttributes: ActivityAttributes {     public typealias PizzaDeliveryStatus = ContentState     public struct ContentState: Codable, Hashable {         var driverName: String         var deliveryTimer: ClosedRange<Date>     }     //var id = UUID()     var numberOfPizzas: Int     var totalAmount: String     var orderNumber: String } now check the code above also I have this in my contentview //  ContentView.swift //  Widget_and_LiveActivities // //  Created by Makwin Santhosh K on 20/11/22. // import SwiftUI import WidgetKit import ActivityKit struct ContentView: View {       var body: some View {         ZStack {             VStack{                 Button("Start Activity"){                     AddLiveACtivity()                 }             }         }         .navigationTitle("Live Activities")     } } func AddLiveACtivity() {        var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ), to: Date())!     future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ), to: future)!          let date = Date.now...future     let activityAttributes = PizzaDeliveryAttributes(numberOfPizzas: 10, totalAmount: "$100", orderNumber: "101")     let initialContentState = PizzaDeliveryAttributes.ContentState(driverName: "Makwin", deliveryTimer: date )               do {         let deliveryActivity = try Activity<PizzaDeliveryAttributes>.request(attributes: activityAttributes, contentState: initialContentState,pushType: nil)         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()     } }
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Reply to cannot find 'minutes' in the scope
inhave just added the code which caused the error label     public typealias PizzaDeliveryStatus = ContentState     public struct ContentState: Codable, Hashable {         var driverName: String         var deliveryTimer: ClosedRange<Date>     }     //var id = UUID()     var numberOfPizzas: Int     var totalAmount: String     var orderNumber: String } i think i have a doubt in syntax only i have used Text(timerInterval: context.state.deliveryTimer, countsDown: true) Where deliveryTimer is in ClosedRange Format like var deliveryTimer: ClosedRange<Date> Now if you go through this below code    var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ), to: Date())!     future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ), to: future)!         let date = Date.now...future     let activityAttributes = PizzaDeliveryAttributes(numberOfPizzas: 10, totalAmount: "$100", orderNumber: "101")     let initialContentState = PizzaDeliveryAttributes.ContentState(driverName: "Makwin", deliveryTimer: date )     do {         let deliveryActivity = try Activity<PizzaDeliveryAttributes>.request(attributes: activityAttributes, contentState: initialContentState,pushType: nil)         print("Requested a pizza delivery Live Activity \(String(describing: deliveryActivity.id)).")     } catch (let error) {         print("Error requesting pizza delivery Live Activity \(error.localizedDescription).")     } } now you may get some clearance of my doubt if i give value for minutes and seconds which is not defined in the code as Int or String it will not accept do you know how to give input format for this Minutes and Seconds which is not defined in my code var future = Calendar.current.date(byAdding: .minute, value: (Int(minutes) ), to: Date())! future = Calendar.current.date(byAdding: .second, value: (Int(seconds) ), to: future)!
Topic: Programming Languages SubTopic: Swift Tags:
Nov ’22
Reply to Cannot convert value of type 'Set<HKQuantityType>' to expected argument type 'HKQuantityType
yeah till this there is no problem the problem arises on below code query =  HKStatisticsCollectionQuery(quantityType: Activitysummary, quantitySamplePredicate: predicate,options: .cumulativeSum, anchorDate: anchorDate, intervalComponents: daily) here in quantityType: Activitysummary throws an error saying "Cannot convert value of type 'Set' to expected argument type 'HKQuantityType "
Jan ’23