Charts icon indicating copy to clipboard operation
Charts copied to clipboard

ChartAnimationEasing.swift file getting compiler error error on Xcode14-beta

Open eliakorkmaz opened this issue 3 years ago • 12 comments

What did you do?

I tried to run my application with Xcode 14 Beta and in Charts pod ChartAnimationEasing.swift file there's an error with this function

    internal static let EaseOutBack = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in
        let s: TimeInterval = 1.70158
        var position: TimeInterval = elapsed / duration
        position -= 1.0
        return Double( position * position * ((s + 1.0) * position + s) + 1.0 )
    }

The error says that The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions. Is there anything I can do with it ?

I expect to run my application without any error however the Chart file getting error that relational with type-checking

Charts Environment

My podfile includes Charts like default

pod 'Charts'

Charts version/Branch/Commit Number: **Xcode version: Version 14.0 beta (14A5228q) **Swift version: swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8) Platform(s) running Charts: Xcode 14.0 Beta as I described, tried to run into multiple simulators and real devices macOS version running Xcode: MacOS Monterey 12.4 (21F79) CommandLineTool: Xcode14 14A5228q

eliakorkmaz avatar Jun 07 '22 10:06 eliakorkmaz

The issue here isn't with charts. My guess is that it's this line: return Double( position * position * ((s + 1.0) * position + s) + 1.0 ) Try separating that into components and provide strict types for the 1.0 values and it shield resolve.

richardpineo avatar Jun 07 '22 16:06 richardpineo

Above function is part of ChartAnimationEasing.swift file so it should be fixed on framework side.

Try separating that into components and provide strict types for the 1.0 values and it shield resolve.

Suggestion passes compiler checks.

return Double( position * position * ((s + Double(1.0)) * position + s) + Double(1.0) )

McSims-Ubi avatar Jun 08 '22 07:06 McSims-Ubi

hey people, sorry for late reply, yesterday we tried new Xcode14 beta and there was an error which I described it already.

After that I separate all of the items as a variable, it worked and successfully run my project into Xcode 14.

I achieved it with a so simple way with

let positionSquare = position * position
let sPlusOne = s + Double(1.0)
....

then 
return Double(positionSquare * (sPlusOne * .....))

but with a single line of which @McSims-Ubi described we can handle it. I am opening a pull request asap and link my issue as #4835 and after that it would be resolved, after that I open PR, I will comment in here.

eliakorkmaz avatar Jun 08 '22 07:06 eliakorkmaz

Hello guys, again

I just create a pull request you can see here -> https://github.com/danielgindi/Charts/pull/4836

Thanks for comments @richardpineo @McSims-Ubi

eliakorkmaz avatar Jun 08 '22 07:06 eliakorkmaz

Weirdly, replacing either instance of 1.0 with Double(1.0) in that line lets it compile -- it doesn't even require replacing both.

As noted in #4838, adding Charts as a Swift Package instead of Cocoapod, or changing the closure declaration to a func also let it compile successfully.

erichedstrom avatar Jun 12 '22 20:06 erichedstrom

Same error with Xcode 14 beta 2

lchamp avatar Jun 23 '22 07:06 lchamp

pr has open and needs to approval for the workflow

eliakorkmaz avatar Jun 27 '22 08:06 eliakorkmaz

People, the Charts library seems not to support beta as they say and you can see in the PR, if you need to fix it open the file and edit the line with

return Double( position * position * ((s + Double(1.0)) * position + s) + Double(1.0) ) for now with unlocking the file until Xcode 14 GM release, so this issue will be open for a while

eliakorkmaz avatar Jun 29 '22 14:06 eliakorkmaz

建议把最后return代码分开,swift不建议此操作通过一行解决

cnjsyyb avatar Jul 02 '22 11:07 cnjsyyb

Seems to be fixed in Xcode 14 beta 3.

Brett-Best avatar Jul 07 '22 10:07 Brett-Best

Seems to be fixed in Xcode 14 beta 3.

Still not working on Xcode14b3 for me (I did delete DerivedData + Clean Build Folder) screenshot

lchamp avatar Jul 08 '22 08:07 lchamp

Seems to be fixed in Xcode 14 beta 3. Screen Shot 2022-07-08 at 15 46 06

mvn-thanhnguyen4-dn avatar Jul 08 '22 08:07 mvn-thanhnguyen4-dn

closed by https://github.com/danielgindi/Charts/releases/tag/v4.1.0

pmairoldi avatar Sep 13 '22 02:09 pmairoldi

To break up the expression into distinct sub-expressions, you can try separating out each part of the calculation into its own intermediate variable. Here is one way you could do this:

internal static let EaseOutBack = { (elapsed: TimeInterval, duration: TimeInterval) -> Double in let s: TimeInterval = 1.70158 var position: TimeInterval = elapsed / duration position -= 1.0 let a = position * position let b = (s + 1.0) * position let c = a * (b + s) let result = c + 1.0 return Double(result) } I hope this helps! Let me know if you have any further questions.

Aiming9793 avatar Jan 10 '23 05:01 Aiming9793

The issue here isn't with charts. My guess is that it's this line: return Double( position * position * ((s + 1.0) * position + s) + 1.0 ) Try separating that into components and provide strict types for the 1.0 values and it shield resolve.

Thanks a lot it worked. Here is the code if anyone wants to refer. Thank You.

let multiplication = position * position return Double(multiplication * ((s + 1.0) * position + s) + 1.0)

AagamVora24 avatar May 05 '23 06:05 AagamVora24