Take a look at my solution: https://stackoverflow.com/a/63937440/6898849
struct ContainerView<Content: View>: View {
		let content: Content
		init(@ViewBuilder content: @escaping () -> Content) {
				self.content = content()
		}
		
		var body: some View {
				// Do something with `content`
		}
}
You don't need AnyView (which you anyways should use as little as possible as it prevents all kinds of optimizations).
My solution also allows you to use if-else and switch-case blocks inside (thanks to @ViewBuilder):
struct SimpleView: View {
		var body: some View {
				ContainerView {
						Text("SimpleView Text")
				}
		}
}
struct IfElseView: View {
		var flag = true
		
		var body: some View {
				ContainerView {
						if flag {
								Text("True text")
						} else {
								Text("False text")
						}
				}
		}
}
struct SwitchCaseView: View {
		var condition = 1
		
		var body: some View {
				ContainerView {
						switch condition {
						case 1:
								Text("One")
						case 2:
								Text("Two")
						default:
								Text("Default")
						}
				}
		}
}
Post
Replies
Boosts
Views
Activity
I found a nasty workaround, posted it here https://github.com/JuniperPhoton/Widget-Intermediate-Animation/issues/1. Long story short – updating a SwiftData object that (might have) changed will force SwiftData to pull the other updates to this object. So what I did was the following:
.onChange(of: scenePhase) { _, newValue in
if case .active = newValue {
items.forEach { $0.title = $0.title }
}
}