A journey into Frameworks and Swift

A journey into Frameworks and Swift

The exciting journey of changing your project architecture basing it on Frameworks and allowing developers to start using Swift in the SoundCloud main app.

Since the launch of Swift in 2014 we had used Swift only in the SoundCloud watch app. The need of having reusable business logic among other reasons led to a new architecture for the project based on dynamic frameworks where Swift would be a first citizen member. In this talk we'll explain the approach we followed at SoundCloud to change our app architecture allowing developers to start using Swift in the project. Learnings, caveats, and how the project and the company has benefit from this journey.

B0a336761194918a853deeff1f22b537?s=128

Pedro Piñera Buendía

September 15, 2016
Tweet

Transcript

  1. A journey into Frameworks and Swift September 2016

  2. Pedro Piñera @pepibumur pepi@soundcloud.com Matej Balantič @skavt matej@soundcloud.com

  3. None
  4. None
  5. None
  6. None
  7. None
  8. None
  9. • Architecture • Test coverage • Coupled • From iOS

    3
  10. None
  11. • Reactive • Fully tested • Reusable code

  12. None
  13. Reusing code Local pods Podfile

  14. CocoaPods && !Versioning Conflicts changing between branches 1

  15. Messy Dependency Graph Too many horizontal dependencies 2

  16. None
  17. None
  18. None
  19. Everyone touching everything Conflicts everywhere

  20. Growing platforms 2007 2016

  21. Scaling up the team

  22. Scaling up the team

  23. None
  24. Swift Platform Independent Reduce conflicts Compatible with all the Apple

    platforms: iOS, tvOS, macOS, watchOS Avoid unnecessary overhead when working with the new setup. Opportunity to start coding Swift. Objc public interface. Vertical dependencies Simple dependency graph that aims vertical dependency over horizontal. Goals
  25. How?

  26. iOS tvOS watchOS Core UI

  27. iOS tvOS watchOS Core UI

  28. iOS tvOS watchOS Core UI • Shared models. • Architectural

    components. • Tooling ◦ Accessing the Core Data ◦ Networking layer • Colors • Fonts • Custom Views
  29. iOS tvOS watchOS Core UI API Config API Config •

    Base URL • HTTP Headers • Session token
  30. iOS tvOS watchOS Core UI API Config API Config •

    Base URL • HTTP Headers • Session token Tooling
  31. iOS tvOS watchOS Core UI Logging Analytics Fabric

  32. Search iOS Core UI tvOS watchOS ...

  33. Search iOS Core UI tvOS watchOS SearchiOS SearchtvOS ...

  34. Search iOS Core UI tvOS watchOS Payments SearchiOS SearchtvOS Offline

    ...
  35. Search iOS Core UI tvOS watchOS Payments SearchiOS SearchtvOS Offline

    ...
  36. Are not reusable among platforms XIBs/Storyboards Platform reusability

  37. FeatureCore (Business Logic) Platform independent feature Using frameworks FeatureiOS FeaturetvOS

    FeaturemacOS FeaturetvOS Feature
  38. ⋁ ⋁ “A good target number of dynamic frameworks to

    have is about half a dozen.” WWDC 2016 - Optimizing Startup Time
  39. FeatureCore (Business Logic) Platform independent feature Alternative: Using Macros Feature

    Presentation (Views in code)
  40. Search iOS Core UI tvOS watchOS SearchiOS SearchtvOS Offline ...

    App Core Data Offline Database App Keychain
  41. Search iOS UI tvOS watchOS SearchiOS SearchtvOS Offline ... App

    Core Data Offline Database App Keychain Core DB Wrapper
  42. Search iOS UI tvOS watchOS SearchiOS SearchtvOS Offline ... App

    Core Data Offline Database App Keychain Core DB Wrapper Stream Stream Database
  43. Benefits • Fully vertical features. ◦ Almost no dependendencies between

    teams. • Cleaner data models. Concerns • Migration time. • Deletion cascading. Alternatives • 1 shared with independent tables. • Dynamically generated merging models. Independent databases Each feature its own database
  44. Tooling

  45. Example projects To play with your Frameworks

  46. Ensuring multi-platform compatibility With Fastlane Thanks Felix #yatusabes

  47. Playgrounds Easy onboarding Thanks Apple #yatusabes

  48. Epilogue (There’s no epilogue)

  49. • Find if it works for you. ◦ Team structure/size?

    ◦ Supported platforms/targets? ◦ Need to enforce good practices? • Be aware of the downsides: ◦ Xcode still has a long way to go ◦ More than 6 dynamic frameworks are discouraged. Are Frameworks for me?
  50. • Framework oriented programming Link • Library oriented programming Link

    • Building modern frameworks Link • How to create a Framework for iOS Link • The unofficial guide to xcconfig files Link • Static or dynamic libraries Link • Framework vs library Link • Micro Features Architecture for iOS Link This slides http://bit.ly/2cTYsrv References
  51. Gracias Questions? @skavt | @pepibumur (thanks to @LenartLeo for amazing

    journey map)