Combine in the raywenderlich.com App

Oct 6 2020 · Video Course (16 mins) · Advanced

Take a look at how Combine is used to power parts of the open-source raywenderlich.com app based on changes that get stored in User Defaults.

5/5 3 Ratings

Version

  • Swift 5.2, iOS 13, Xcode 11

User settings for the app are stored in User Defaults. To publish changes from them, an ObservableObject, PassthroughSubjects, and AnyPublishers are employed.

1

Unit Tests

1:54 Free

GRDB, which the app uses for data storage, relies on the CombineExpectations library. SettingsManagerTestCase makes use of its Recorders as well.

2

Any Cancellables

4:09 Free

Any Cancellable (which the sink method returns) is a type-erased, Hashable class that you'll be using a lot with Combine.

3

Observable Objects

3:55 Free

ObservableObjects make use of a publisher, named objectWillChange, which doesn't send any data, and can't fail.

4

Published

1:48 Free

Published is a property wrapper which automatically adds a publisher that emits new values. It can be cleaner than calling objectWillChange.

5

Who is this for?

Intermediate to Advanced iOS developers with some experience using SwiftUI and User Defaults, but not necessarily any Combine experience.

Check out the open source code for the raywenderlich.com app here.

Covered concepts

  • Combine
  • Publishers and Subscribers
  • Observable Objects
  • Passthrough Subjects
  • Type Erasure
  • Storing Cancellables

Contributors

Comments