How to Use Appcode and Swiftify to Accelerate Your App Conversion to Swift

Swiftify offers various methods of converting your Objective-C code to Swift. If you use AppCode for development rather than Xcode, you can convert a selection of lines of code or an entire file right from the editor using Swiftify’s AppCode plugin.

The Advantages

AppCode’s extensibility makes it a perfect IDE for migrating your Objective-C projects to Swift gradually, on a per-file basis. It enables you to:

  • Convert .h and .m file pairs simultaneously, unlike Swiftify’s Xcode extension, which can only process a single file at a time due to the limitations of Xcode Source Editor extensions.
  • Automatically update the Xcode project file thanks to the built-in AppCode project file parser.
  • Do the entire conversion without leaving AppCode or using external tools.

Installing the Plugin

To install the Swiftify AppCode plugin, go to the AppCode menu then select Preferences. Select Plugins from the side panel, then select the Browse Repositories button at the bottom. Search for “Swiftify” and click the Install button.

Finally, restart AppCode to start using the plugin.

Getting Started

Before you can begin converting the code to Swift, you’ll need to add your API Key. Go to the Swiftify Extensions page and copy your API Key. Back in AppCode, open AppCode > Preferences, select Tools, then Swiftify and paste your API Key.

Open your app in AppCode and select an Objective-C class to start converting it.

Converting Objective-C Classes to Swift

The AppCode plugin lets you convert a selection of lines of code or entire files to Swift.

Select some Objective-C code, right click on it and select Swiftify > Convert Selection to Swift.

You can also access the same options by clicking on the Tools menu, then selecting Swiftify.

To convert an entire class, select both the .h and .m files from the project window, right click on them, then select Swiftify > Convert [FileName] to Swift.

Swiftify will create a new file that contains all the classes and methods from the Objective-C header and implementation files you selected.

Note that Swiftify will not generate the Objective-C bridging header in this case, so if your newly generated Swift code uses Objective-C classes, you’ll need to create a bridging header manually.

To be able to build the project, select the old .h and .m files, right click on them, then select Exclude from Xcode Project. This will delete references to those files from the project file but will keep them inside the project directory in case you need to go back to them again.

After you have verified that everything is working as intended, you can go ahead and delete the old .h and .m files from the project directory.

Select the next Objective-C file to convert and follow the same steps. If you encounter an error that says your project has undefined symbols for a certain architecture for classes you just converted, make sure you do a clean build by selecting Run > Clean Build Folder, then building the app again.

After converting all classes, the last step would be to convert the UIApplicationDelegate class. Select AppDelegate.m and follow the same steps.

The project is now fully converted to Swift. This approach lets you divide your effort to convert your project to Swift into smaller tasks that can easily be tested. Since Swift has great interoperability with Objective-C, you can always ship versions of your app to the App Store before you have completed the whole conversion.

Converting Entire Projects

If you’d like to convert entire projects or multiple files at once, check out Swiftify’s Advanced Project Converter. The Advanced Project Converter will also automatically generate the Objective-C bridging header.

For more guidance, read our post on migrating from Objective-C to Swift, and please share your questions in the comments section below.