You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a view model as you can see the below and I want to get selected days in my viewModel
final class DatePickerViewModel: ObservableObject {
@Published var selectedDates = ""
}
This one created for the test. I just want to get with text when user select days on the date picker.
struct SwiftUITestView: View {
@StateObject var viewModel = DatePickerViewModel()
let monthsLayout: MonthsLayout = .vertical(options: VerticalMonthsLayoutOptions())
var body: some View {
VStack{
Text(viewModel.selectedDates)
SwiftUIScreenDemo(calendar: Calendar.current, monthsLayout: monthsLayout, selectedDates: $viewModel.selectedDates)
}
}
}
And I need to pass variable using @binding property wrapper Because I want to get changes from view model. I passed data like the below in the SwiftUIScreenDemo
.dayItemProvider { day in
let isSelected: Bool
if let selectedDayRange {
isSelected = day == selectedDayRange.lowerBound || day == selectedDayRange.upperBound
} else {
isSelected = false
}
let dayView = SwiftUIDayView(dayNumber: day.day, isSelected: isSelected)
self.manageMultipleDaySelection(isSelected: isSelected, selectedDayRange: selectedDayRange)
return dayView
.calendarItemModel
}
So When I run app and select a day on the datepicker, It keeps going generate day at dayItemProvider. And memory usage continue increase and CPU usage %100. Ui did deadlock. When we set selectedDates in the DispatchQueue.main.async this time doesn't deadlock but It continue generate day on the background. But if selectedDates is marked with @State property wrapper in SwiftUIScreenDemo, there is no problem. It works right. Why is it acting like this? If I need to bind this parameter (which I need), what should I do?
The text was updated successfully, but these errors were encountered:
I have a view model as you can see the below and I want to get selected days in my viewModel
This one created for the test. I just want to get with text when user select days on the date picker.
And I need to pass variable using @binding property wrapper Because I want to get changes from view model. I passed data like the below in the SwiftUIScreenDemo
I have a func in SwiftUIScreenDemo that inside of .dayItemProvider function. And this function for just get selected date.
I used it .dayItemProvider.
So When I run app and select a day on the datepicker, It keeps going generate day at dayItemProvider. And memory usage continue increase and CPU usage %100. Ui did deadlock. When we set selectedDates in the DispatchQueue.main.async this time doesn't deadlock but It continue generate day on the background. But if selectedDates is marked with @State property wrapper in SwiftUIScreenDemo, there is no problem. It works right. Why is it acting like this? If I need to bind this parameter (which I need), what should I do?
The text was updated successfully, but these errors were encountered: