Created
April 28, 2023 12:38
-
-
Save drosenstark/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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You cannot solve this without generics