It didn't work when I update to xcode 13 beta 4.
show error:
Property definition has inferred type 'some View', involving the 'some' return type of another declaration
struct RatingToStar : View {
var rating: Int
let star = Image(systemName: "star").foregroundColor(.yellow)
let fillStar = Image(systemName: "star.fill").foregroundColor(.yellow)
var body: some View {
HStack {
if rating >= 1 {fillStar}else{star}
if rating >= 2 {fillStar}else{star}
if rating >= 3 {fillStar}else{star}
if rating >= 4 {fillStar}else{star}
if rating >= 5 {fillStar}else{star}
}
}
}
you can also fix it by specifying a type of some View
let star : some View = Image(systemName: "star").foregroundColor(.yellow)
In beta 4, return types for view modifiers have been cleaned up and made some View
. The release notes say so:
View modifier methods return opaque views (some View) rather than complex generic types. (46140669)
This is what's causing the change in behavior. At this time I cannot give you a full explanation on the error message, as I am not entirely confident about it, but I can give you an easy workaround:
struct RatingToSta : View {
var rating: Int
let star = AnyView(Image(systemName: "star").foregroundColor(.yellow))
let fillStar = AnyView(Image(systemName: "star.fill").foregroundColor(.yellow))
var body: some View {
HStack {
if rating >= 1 { fillStar } else{ star }
if rating >= 2 { fillStar } else{ star }
if rating >= 3 { fillStar } else{ star }
if rating >= 4 { fillStar } else{ star }
if rating >= 5 { fillStar } else{ star }
}
}
}
If I find out more, I'll make sure to come back and update my answer.
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