NilCoalescing / SwiftUI-Code-Examples

In this repository we are collecting our solutions to interesting SwiftUI problems that we encounter when developing our apps.
MIT License
245 stars 40 forks source link

BuildAndStyleAChartWithSwiftChartsFramework: Value of type 'some ChartContent' has no member 'blendMode' #1

Closed Brett-Best closed 2 years ago

Brett-Best commented 2 years ago

I was trying to follow the article that includes the below line of code. Seems that it doesn’t compile with Xcode 14b5 :( https://github.com/NilCoalescing/SwiftUI-Code-Examples/blob/be5ffae4f4e4df4c50f86e20bc79789225817ef4/BuildAndStyleAChartWithSwiftChartsFramework/SimpleBabyChart.swift#L43

I get:

Value of type 'some ChartContent' has no member 'blendMode'

I couldn’t find anything in the Xcode or iOS release notes about a change in this API.

hishnash commented 2 years ago

@Brett-Best thank you for spotting this. Looks like the api changed in the recent beta release, this can be resolved by moving the .bendMode modifier up inside the foregroundStyle so that it is now applied directly to the LinearGradient.

.foregroundStyle(
    LinearGradient(
       gradient: Gradient (
           colors: [
               .indigo.opacity(0.05),
               .purple.opacity(0.5)
            ]
       ),
       startPoint: .top,
       endPoint: .bottom
    ).blendMode(.darken)
)
Brett-Best commented 2 years ago

Ah nice, wasn’t sure if that was producing the same result, thanks! 😊