Skip to content

Swift UI views are not updated due to capturing viewStore (vs current state) in closures. #1012

Answered by mbrandonw
grigorye asked this question in Q&A
Discussion options

You must be logged in to vote

This isn't a problem with TCA per se, and would be easily reproducible in a vanilla SwiftUI application too. In fact we have some bugs filed with Apple that demonstrate the problem (here and here).

However, there is an easy change that fixes the problem, and it's probably the better way of constructing your views anyway. Although most SwiftUI views involve closures in some way, 99% of the time they are non-escaping closures. That means the closures aren't actually meant to be stored away and lazily evaluated later, but rather they just serve as a convenient syntax and are evaluated immediately.

For example, the Section view takes view builder closures for parent, content and footer views,…

Replies: 3 comments 14 replies

Comment options

You must be logged in to vote
12 replies
@tgrapperon
Comment options

@tgrapperon
Comment options

@iampatbrown
Comment options

@tgrapperon
Comment options

@iampatbrown
Comment options

Comment options

You must be logged in to vote
2 replies
@grigorye
Comment options

@grigorye
Comment options

Answer selected by grigorye
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants
Converted from issue

This discussion was converted from issue #1011 on March 01, 2022 16:47.