How to use Combine with MVVM for UIKit and SwiftUI - fetching tweets example project

Опубликовано: 23 Март 2026
на канале: Karin Prater
17,689
473

In this Combine tutorial, I am going to show you how to use MVVM with UIKit and SwiftUI. We will build data streams from the view to the view model and back.

I am refactoring another Combine tutorial which you can find here on the youtube cannel of Lets build that app:
   • Adv. Swift Combine Framework: Debounce Sea...  

The completed source code can be found in this blog post:
https://www.swiftyplace.com/blog/comb...

The example project has a search textfield and a tableview, where you can search for tweets. In the list you will see 10 search results. I don't like the STTwitter API and I couldn't figure out how to change this correctly.

What you will use in the demo:
use MVVM to prevent the massive ViewController problem
integrate the STTwitter API with Combine by using Future publishers for ad-hoc callbacks
write functions that create publishers with AnyPublisher and eraseToAnyPublisher
create data streams with Decode and Catch errors
use CurrentValueSubject and @Published to pass values into data streams
write a complex data stream to fetch tweets with SwitchToLatest
use resource management tools in Combine like debounce and removeDuplicates

Here is an overview of the tutorial:
00:00 Intro
02:27 refactoring to MVVM in UIKit
07:29 CurrentValueSubject for view model properties
10:33 Future for ad-hoc callbacks
18:14 data stream setup in the view model
26:38 data stream between UIViewController and view model
30:40 @Published and UIKit
33:18 SwiftUI setup
36:16 SwiftUI views
40:50 Combine conditional applying publisher
42:24 wrap up


If you want to have a refresher on Model-View Model -View, you can check my other video here:
   • How to use MVVM in iOS - State Management ...  

If you liked what you learned and you want to see more, check out one of my courses!
👨‍💻 my SwiftUI course https://school.swiftyplace.com/course...
👨‍💻 my Core Data and SwiftUI course https://school.swiftyplace.com/course...
👩🏻‍💻 Combine course https://school.swiftyplace.com/course...


#CombineFramework #SwiftUI​ #Xcode​ #iOS