Maintaining a Swift and Objective-C Hybrid Codebase
Article Summary
Adrianna Chang from Shopify reveals how to write new Swift code in legacy Objective-C apps without rewriting everything. The secret? Strategic bridging patterns that let both languages coexist.
Shopify's Mobile Store Builder team faced a common iOS dilemma: a powerful Objective-C codebase that worked well, but a desire to adopt Swift's modern features. This article shares the practical patterns they developed to maintain a hybrid codebase where Swift and Objective-C work together seamlessly.
Key Takeaways
- Swift classes inheriting from NSObject automatically bridge to Objective-C runtime
- @objc attribute controls exact method and class names exposed to Objective-C
- Wrap Swift-only structs in NSObject subclasses with proxy methods for OBJC access
- Swift extensions on NSObject subclasses appear as categories in Objective-C code
- Nullability annotations prevent runtime crashes when bridging OBJC pointers to Swift
You can adopt Swift incrementally in Objective-C apps using bridging wrappers, extensions, and careful nullability annotations without a costly full rewrite.
About This Article
Shopify's Mobile Store Builder was built on Objective-C for dynamic UI inflation from template-based configurations. A complete rewrite to Swift wasn't practical, but developers wanted to use Swift's type safety for new models.
Adrianna Chang created bridging patterns using @objc attributes to control runtime names, NSObject wrapper classes for Swift-only structs, and Swift extensions that work as Objective-C categories. This allowed the team to adopt Swift incrementally without rewriting the core Objective-C logic.
The team built type-safe Swift models alongside the dynamic Objective-C UI inflation system. This showed that hybrid codebases can work together without expensive full migrations or losing the benefits of either language.