Переглядів 38,297
In this course, you will learn the basics of the Combine framework. This is for absolute beginners in functional reactive programming and Combine 🤩.
First I will explain how adding a subscriber like sink or assign to a publisher creates a subscription. You will learn how to cancel a subscription that means how to stop a data stream from passing values. You will also learn that passing an error 💣 will complete the data stream.
In the second section you will learn about a special type of publisher that is Subjects. I will show you how to use CurrentValueSubjects and PassthroughSubjects. In SwiftUI you can also use a publisher with the property wrapper @Published. You will learn the difference between these 3 publishers and their specific use cases.
We will also write 2 demo projects 👋 for UIKit and SwiftUI. The goal is to use Subjects and @Published to create data streams from user input.
By the end of this course, you will be able to create simple data streams between different parts of you projects.
I am using MVVM to illustrate how easy it is to separate tasks into their own components. Combine is a great tool for loose communication between different components. Comparable to the Delegate pattern, closures and observer pattern.
0:00 Intro
03:21 subscriptions
17:49 limited subscriptions
31:43 assign(to,on) Subscriber
40:56 assign(to,on) strong reference and memory cycle problems
46:55 assign(to) with @Published properties
52:55 multithreading with .receive(on) and subscribe(on)
01:01:36 subscription as the contract between publishers and subscribers
01:14:18 publishers
01:18:25 CurrentValueSubject
01:26:24 PassthroughSubject
01:39:42 @Published
01:49:25 Combine in SwiftUI
01:55:47 Demo project UIKit
02:12:13 Demo project SwiftUI
02:37:49 where to go from here
⬇️ download the playgrounds for course here:
school.swiftyplace.com/f/free...
👩🏻💻 Check out the full course:
school.swiftyplace.com/course...
📓 Resources to learn Combine:
www.swiftyplace.com/blog/how-...
How to go from here:
- convenience Publishers: Just, Future, Result, Fail, Empty
developer.apple.com/documenta...
- Foundation: URLSession dataTask publisher, Notification center, KVO publisher
- operators: map, tryMap, compactMap, scan, collect, append, decode
developer.apple.com/documenta...
- throwing errors: Fail publisher, Future with error
- error handling operators: catch, tryCatch, replaceError(with), assertNoFailure , mapError, setFailureType(to)
- multithreading: Schedular protocol, receive(on), subscribe(on), batch processing with flatMap and set number of task executed in parallel with flatMap(maxPublisher)
- control resources: dropFirst, debounce, throttle, filter, removeDupicates
- unit testing: functions that return AnyPublisher, eraseToAnyPublisher, Result.publisher
- communication design patterns can be replaced by Combine data streams: Delegate pattern, closures and Observer patterns
#CombineCourse#HowToUseCombine#SwiftCombine