The problem was that the JSON data wasn't loaded before I ran the code to check the current date. I moved that code from the onAppear in the ContentView to the following.
DispatchQueue.main.async {
self?.user = user
self?.user.checkDate()
}
The checkDate() function is what called that newMonth() function.
That's why it was printing two different months. It would print the default value for the User struct, and then once the data was loaded, it would print the month that was stored.
Topic:
Programming Languages
SubTopic:
Swift
Tags: