简体   繁体   中英

Swift 4.2 Syntax change - What happened to Swift type inference?

I'm running Xcode 10 beta with Swift 4.2. Xcode wants to convert my Xcode 9.4.1 with Swift 4.1 code to Swift 4.2 syntax. The changes are all UIView.animate(... options: ...) .

I using options like .curveEaseIn which worked fine before but it wants to change them to UIView.AnimationOptions.curveEaseIn .

What happened to Swift's ENUM type inference?

It was UIViewAnimationOptions.curveEaseIn in Swift 4.1. So, the migrator has detected your .curveEaseIn as UIViewAnimationOptions.curveEaseIn and trying to convert it to UIView.AnimationOptions.curveEaseIn .

Seems current migrator does not like dot-leaded notation.

You can convert all occurrences of UIView.AnimationOptions.curveEaseIn into .curveEaseIn manually, and Swift type inference would work if appropriate.

You may want to write a feature request proposing improvement of the migrator.


(Addition) Seems Xcode 10 beta 3 has fixed this issue, though I have not tested yet.

Xcode 10 beta 3 Release Notes

AnimationOptions is a enum under UIView now in swift 4.2

You can also take a look at this git repo which contains a list of syntax changes. Please feel free to contribute with the changes you've met in your project.

https://github.com/alexliubj/Swift-Migration-4.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM