Hi, Habr! I present to you the translation of the article
"Swift 5.0: How to migrate your project and frameworks" by Antoine Van Der Lee.
Swift 5.0 was released in March 2019 and is the first stable release of ABI Swift. Although many resources cover new Swift 5.0 features, they do not often tell you what you need to do to upgrade your project to Swift 5.0.
In this post, I will look at the steps you can take to upgrade an existing project to Swift 5.0.
')
Check that your project has already been moved to Swift 4.2.Do not be surprised if this article will help convince your product manager to plan a time to go.
Automatic transfer using the migrant assistant
Xcode suggests using the "Migration Assistant" to automatically update your code to the current Swift syntax. This conversion will use the latest version of Swift, available with the Xcode version installed.
Xcode 10.2 is the first version that includes Swift 5.0, so you need to use this version of the software.
Often this feature does the hard work for you. Therefore, I recommend starting the code transfer by going to
Edit -> Convert -> To Current Swift Syntax ....Tip: make sure you only do this for your project and framework. You can skip the conversion for any external dependencies.

Dependency update
Most likely, you have some Swift dependencies that need to be updated. Many large open source projects, such as Alamofire and Moya, have already begun to work with Swift 5.0.
However, it is likely that not all of your dependencies have been updated. Although I would like to encourage you to do the transfer, and then submit the pull request yourself, you will probably have to wait a bit until the project owners do it themselves.
If you plan to conduct a full intensive test of your application after this transfer, you may also need to directly update your dependencies. Your test will cover these updates directly, which can serve as a “double win”.
CI Environment Update
If you are using Travis, Jenkins or any other CI platform, you also need to update Xcode.

Using the result in Swift
Xcode Converter performs only basic code changes. It does not take into account the new type
“Result” , which is now included in the standard Swift library. Many frameworks have included the
“Result” type in their code. This may mean that you have quite a lot of data with an enum type that is no longer needed. However, do not rush to replace them with data from your dependencies: you depend on code changes in the external structure.
General type of error
It is likely that your current type
“Result” has determined only the type for a suitable case.
“Result” in Swift 5.0 also requires you to determine the type of error expected. Being a good citizen, you should try to make this type of error specific, based on what you expect. However, if you want to speed up the transfer, you can also simply set the type to
Swift.Error .
Tip: if you want to learn more about the new Result type in Swift 5.0, I would recommend you read this article .Consider ABI stability
In fact, ABI stability is a separate topic. You can
read more about this on the official Swift blog.
Keep in mind that the
size of the application you are downloading
will decrease , because applications no longer need to embed the standard Swift library!
This should convince your product to find the time to transfer.If you want to immerse yourself in Swift 5.0, you can go to the Apple blog post “Migrating to Swift 5.0”.