|
Hi there. Today I try to write a program to calculate everyday in week by swiftUI.But I got two error like my pic. Here is my code.Can anyone help? thx a lot
|
|
The problem is that in your function calculatorWeek you change @State variables where the change itself triggers another view update which could lead to an unexpected behaviour. What you could do is to pass them as parameters into the function and don't do changes on the variables itself but on the copies. |
|
The reason is that when you select a month/year you are trying to change it when displayed eg select choosedMonth then try to change the display to something else. However in
Just a couple other pointers to make an array of numbers you can do.
but you use this in the
So a bit of refactoring end with
**PS not sure if you logic is correct as 1.1.1 is coming out as Tuesday! You might be better to use dates formatters etc as dates are very complicated! |
|
Definitely you should look into using All of the manual calculations you are doing in your
* For iOS 15. For earlier versions, you would need to use a |
BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.