

One possible objection to the current approach is: It has two targets, which mimic the structure of the products, and it explicitly defines that SwiftObjcBridge depends on SwiftCode Why define two targets? The package files declare a package named SwiftObjcInterop which exports two different libraries: SwiftObjcBridge and SwiftCode. library( name: "SwiftCode", targets: ), ], targets: ). It makes creating different packages to share your code across libraries and apps is extremely easy.Ī simple setup for these modules is reflected in the following Package.swift file: // swift-tools-version: 5.7 import PackageDescription let package = Package( name: "SwiftObjcInterop", products: ). SwiftPM is the dependency management system developed by Apple toward which the whole iOS community is moving. Modularizing the code is an important technique to keep the code cleanly separated, highlight the public interfaces, and reap some optimization benefits when Xcode builds your app incrementally. Now that you have the library and the bridge, you can integrate it into an Objective-C app. Notice that you need to import the SwiftCode module on top of the file. However, not all Swift features can be used directly in Objective-C, and some details may not be covered in the official documentation.Ĭonsider a Swift library that exposes the following entities: import Foundation public enum Operation The Swift and Objective-C InteroperabilityĪpple has enabled its two languages, Swift and Objective-C, to work together.

This tutorial will explore how to create a Swift library that can work within an Objective-C library and integrate it into an Objective-C app using the Swift Package Manager and Cocoapods. In that case, you could rewrite the login flow in Swift and integrate it into the Objective-C application. Instead, you can perform an incremental migration, rewrite specific Swift code and integrate it into the Objective-C code base.įor example, suppose your company’s product manager asks to review the login flow and add a new feature.


In these situations, it may not be necessary to migrate the code to Swift immediately. If you work in a large company, working with legacy code written in Objective-C may be necessary.
