nalexn / clean-architecture-swiftui

SwiftUI sample app using Clean Architecture. Examples of working with CoreData persistence, networking, dependency injection, unit testing, and more.
MIT License
5.73k stars 697 forks source link

Why does the '.onReceive(routingUpdate)' perform twice? #74

Closed GeoffreyChen777 closed 2 years ago

GeoffreyChen777 commented 2 years ago

Hi, thanks for your work!

I'm learning your architecture and I found that:

.onReceive(routingUpdate) {
            print("update")  \\ added by me.
            self.routingState = $0 }

the print will be performed twice. Can you explain the reason?

Please forgive me for this simple question, because I am a newbie of swift :)

nalexn commented 2 years ago

Hey @GeoffreyChen777

This phenomenon is explained in the section Phantom state updates of this article. Let me know if you have follow up questions!