Issue #604
I see that the modifier needs to do something on the content, otherwise it is not getting called! This logs on the modifier, when the View is created. A View won’t be recreated unless necessary
struct LogModifier: ViewModifier {
let text: String
func body(content: Content) -> some View {
print(text)
return content
.onAppear {}
}
}
extension View {
func log(_ text: String) -> some View {
self.modifier(LogModifier(text: text))
}
}
VStack {
Text("")
.log("a text")
}
Another simpler way is to make an extension
extension View {
func log(_ any: Any) -> Self {
print("\(any)")
return self
}
}