I'm working on an XCode project and can't figure out how to get rid of this error. I have imported the SwiftUI library which 'Content' is from but XCode doesn't seem to realize that. Any suggestions?
func body(content: Content) -> some View {
content
.blur(radius: spotify.isAuthorized ? 0 : 3)
.overlay(
ZStack {
if !spotify.isAuthorized || Self.debugAlwaysShowing {
Color.black.opacity(0.25)
.edgesIgnoringSafeArea(.all)
if self.finishedViewLoadDelay || Self.debugAlwaysShowing {
loginView
}
}
}
)
.onAppear {
// After the app first launches, add a short delay before
// showing this view so that the animation can be seen.
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
withAnimation(LoginViewController.animation) {
self.finishedViewLoadDelay = true
}
}
}
}
You are using Content without telling the compiler enough detail about it. In ViewModifier and AnimatableModifier, Content is already defined for you as an associatedType by the SwiftUI library.
If you are inside a View or a custom struct type of your own making, Content won't be defined, but you can let the compiler know it's a View by doing something like this:
struct MyStruct<Content> where Content : View {
func body(content: Content) -> some View {
return content.background(Color.black)
}
}
If it's a ViewModifier, like I described, the compiler already knows the constraint and you'll see no error:
struct ExampleStruct : ViewModifier {
func body(content: Content) -> some View {
return content.background(Color.black)
}
}
struct ExampleStruct2 : AnimatableModifier {
func body(content: Content) -> some View {
return content.background(Color.black)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With