How to migrate Objective-C code to Swift

Prateek C
Mac O’Clock
Published in
3 min readJun 1, 2020

--

It’s been quite sometime since Swift has come in the market. As it provides many advantages over Objective-C, developers are moving their legacy Objective-C code to Swift. When I did it first I thought it was better to re-write the app from scratch again in Swift. But it is possible to migrate the same legacy code to Swift with little or less hassle. You can actually improve the architecture, logic and performance by replacing pieces of Objective-C to Swift. The following steps will make the code better and also you can migrate the code from Objective-C to Swift very swiftly and easily. Let’s begin

Clean Up Your Code

The first thing is to make sure that the Objective-C code and Swift code have best or most favourable compatibility. You can do this by modernizing and cleaning up the existing Objective-C code. For example, if you find out that there are parts of the code which don’t have nullability annotations, now is the time to add them. Your code must follow modern coding practices. This is to make sure that Objective-C interacts with Swift without any problem and the communication is effective.

Migrate The Code

The best way to do this is to migrate to Swift one class at a time. It is best to start with the classes that don’t have any subclasses. The reason behind this is…

--

--