Skip to content

Instantly share code, notes, and snippets.

@dr2050
Created April 28, 2023 12:38
Show Gist options
  • Save dr2050/d90815b9c3ba83a90dbb4bd65a8d70ef to your computer and use it in GitHub Desktop.
Save dr2050/d90815b9c3ba83a90dbb4bd65a8d70ef to your computer and use it in GitHub Desktop.
How to resolve "Use of protocol 'View' as a type must be written 'any View'" in some cases
// MARK: - Bad: "Use of protocol 'View' as a type must be written 'any View'"
struct LeftRightView: View {
let leftView: View
let rightView: View
var body: some View {
HStack {
leftView
rightView
}
}
}
// MARK: - Good
struct LeftRightView2<Content: View>: View {
let leftView: Content
let rightView: Content
var body: some View {
HStack {
leftView
rightView
}
}
}
@dr2050
Copy link
Author

dr2050 commented Apr 28, 2023

Also see this SO question.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment