Upgrade to Pro — share decks privately, control downloads, hide ads and more …

NSSpain 2023: Moving from Cocoapods to SwiftPM

Oswaldo Rubio
September 18, 2023

NSSpain 2023: Moving from Cocoapods to SwiftPM

Discover the realities and challenges of adopting Swift Package Manager in the XING iOS app, to be able to organize and design the modularization of more than 100 internal libraries.

Oswaldo Rubio

September 18, 2023
Tweet

Other Decks in Programming

Transcript

  1. The problems and solutions we found while adopting gradually Swift

    Package Manager in a large codebase What’s the point?
  2. A bit of context 🎒 👨💻 👩💻 + 30 iOS

    Developers +120 Development Pods ~30% ⏳ + 13 years old codebase (monorepo) 📈 + 300K daily unique visitors 📚 + 300K LOC 📐 50% UIKit + 50% SwiftUI
  3. The reasons behind 1. Reduce our technical debt 2. Having

    a more f lexible and capable Package manager 3. Having better build times & developer experience moving to SPM
  4. The problem 🤯 1. More than 20 dependencies per module

    (average) 2. High transitive dependency usage 3. 30% of mixed Objective-C code across the project
  5. 🧪 The experiment … and what we learned during a

    Hackweek 1. Dependencies from our features modules needs to be removed 2. Inter-dependency between modules needs to be reduced 3. A roadmap needs to be de f ined 4. Our managers and community needs to be convinced
  6. Thomas J. McCabe, Sr in 1976 - Wikipedia "It´s a

    quantitative measure of the number of linearly independent paths through a program’s source code.”
  7. Predicting Subsystem failures using dependency graphs, 2016 - Microsoft “The

    complexity of the dependency structure predicts the number of defects.”
  8. Tooling - jungle https://github.com/xing/jungle Complexity = E - V +

    P E - Edges V - Nodes P - Weakly connected components Complexity: 4 - 5 + 1 = 0 Complexity: 6 - 5 + 1 = 2
  9. 🛣 We need a roadmap • De f ine a

    migration plan • Document our migration process • Get a time estimation of the overall process • Get our managers and community approval
  10. 🛠 The Migration Gradual and using both package managers Non

    invasive for other teams Integrate as fast as possible
  11. • Module migration status • Product containers • SPM Schemes

    management • One or Multiple Swift Packages • Using SPM products in Cocoapods • Cyclic dependencies between languages Migration challenges
  12. • Module migration status • Product containers • SPM Schemes

    management • One or Multiple Swift Packages • Using SPM products in Cocoapods • Cyclic dependencies between languages Migration challenges
  13. Module migration status Migrated Integrated Module Availability Cocoapods and SPM

    Only SPM Module usage for running With CocoaPods With SPM Module usage for Testing With SPM With SPM
  14. Migrated status 📦 features Package 📲 XING App 🟦 Pod.xcodeProj

    JobsCoreTests JobsCore 📂 JobsCore/Sources JobsCoreModule 📂 JobsCore/Tests
  15. • Module migration status • Product containers • SPM Schemes

    management • One or Multiple Swift Packages • Using SPM products in Cocoapods • Cyclic dependencies between languages Migration challenges
  16. • Module migration status • Product containers • SPM Schemes

    management • One or Multiple Swift Packages • Using SPM products in Cocoapods • Cyclic dependencies between languages Migration challenges
  17. • Module migration status • Product containers • SPM Schemes

    management • One or Multiple Swift Packages • Using SPM products in Cocoapods • Cyclic dependencies between languages Migration challenges
  18. New Swift 5.9 Package Access modi f ier Private Open

    Public Internal Fileprivate Package 🆕
  19. One package or multiple ones? Cocoapods App Pod1 Pod2 Pod3

    Pod4 Pod5 Pod6 SPM App Prod1 Package1 Package2 Prod2 Prod10 Prod11 Target1 Target2 Target10 Target11 Target3 Pod f ile All dependencies allowed Only Products are accessible to other packages
  20. • Module migration status • Product containers • SPM Schemes

    management • One or Multiple Swift Packages • Using SPM products in Cocoapods • Cyclic dependencies between languages Migration challenges
  21. Using SPM modules inside Cocoapods Can we do this? 📦

    features Package 📲 XING App 🟦 Pod.xcodeProj MyCPModule Common https://github.com/CocoaPods/CocoaPods/pull/11953 💥
  22. Using SPM modules inside Cocoapods How to create .xcframeworks swift

    package generate-xcodeproj xcodebuild archive xcodebuild -create-xcframework Swift 5.8 Create Xcode Project from .podspec xcodebuild archive xcodebuild -create-xcframework Swift 5.9
  23. • Module migration status • Product containers • SPM Schemes

    management • One or Multiple Swift Packages • Using SPM products in Cocoapods • Cyclic dependencies between languages Migration challenges
  24. Conclusions • De f ining more than one package helps

    to create good practices boundaries for your internal modules • Having a roadmap before starting helps to convince your team and management • Build time was not reduced by using only SPM, but because we improved f irst our architecture • Gradual migration helps us to not having unexpected surprises
  25. Thanks to all our mates Markus Faßbender Shammi Didla Andreas

    Koslowski Mark Schütte Özgün Zor Eslam Foad Akshay Shetty