I try to write View extension by restrict where clause,code is very simple:
struct FooView : View {
var body: some View {
VStack {
Text("hello world")
}
}
}
// only FooView type can invoke standard()
extension View where Self == FooView {
func standard() -> some View {
self
.frame(width: 200, height: 50)
}
}
I call standard() like this:
struct ContentView: View {
var body: some View {
VStack {
FooView()
.standard()
}
}
}
But run it will crashed in Xcode Preview! (Xcode 12.2 + MacOS 10.15.7) Is there something wrong with what I wrote? Thanks ;)
lang-swift
FooViewinstead ofView?