|
| 1 | +<!-- Run this slideshow via the following command: --> |
| 2 | +<!-- reveal-md README.md -w --> |
| 3 | + |
| 4 | + |
| 5 | +<!-- .slide: class="header" --> |
| 6 | + |
| 7 | +# Combine |
| 8 | + |
| 9 | +## [Slides](https://make-school-courses.github.io/MOB-2.4-Advanced-Architectural-Patterns-in-iOS/Slides/Combine-Pt.2/README.html ':ignore') |
| 10 | + |
| 11 | +<!-- > --> |
| 12 | + |
| 13 | +## Learning Objectives |
| 14 | + |
| 15 | +By the end of this lesson, you will be able to: |
| 16 | + |
| 17 | +**Implement**: |
| 18 | +- Combine to update UI with UIKit |
| 19 | +- Combine to fetch and display data |
| 20 | + |
| 21 | +<!-- > --> |
| 22 | + |
| 23 | +## @Published |
| 24 | + |
| 25 | +A type that publishes a property marked with an attribute. |
| 26 | + |
| 27 | +```swift |
| 28 | +@propertyWrapper struct Published<Value> |
| 29 | +``` |
| 30 | +- Publishing a property with the `@Published` attribute creates a publisher of this type. |
| 31 | +- You access the publisher with the $ operator |
| 32 | +- Class constrained |
| 33 | + |
| 34 | +[Docs](https://developer.apple.com/documentation/combine/published) |
| 35 | + |
| 36 | +<!-- v --> |
| 37 | + |
| 38 | +```swift |
| 39 | +class Weather { |
| 40 | + ... |
| 41 | + @Published var temperature : Int! |
| 42 | + ... |
| 43 | + let _ = $temperature |
| 44 | + .sink() { value in |
| 45 | + print ("Temperature now: \(value)") |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +<!-- v --> |
| 51 | + |
| 52 | +## Integration with UIKIt |
| 53 | + |
| 54 | +Declarative UI updates from user input. |
| 55 | + |
| 56 | +<!-- > --> |
| 57 | + |
| 58 | +## Integration with Networking |
| 59 | + |
| 60 | +Fetching, transforming and displaying data. |
| 61 | + |
| 62 | +<!-- > --> |
| 63 | + |
| 64 | +## After Class |
| 65 | + |
| 66 | +Combine is a new framework and it will take more reading and practice to get used to it. But you can start using what you already know, little by little. 😉 |
| 67 | + |
| 68 | + |
| 69 | +<!-- > --> |
| 70 | + |
| 71 | +## Additional Resources |
| 72 | + |
| 73 | +- [Using Combine](https://heckj.github.io/swiftui-notes/#coreconcepts-publisher-subscriber) |
| 74 | +- Book: Practical Combine by Donny Walls |
| 75 | +- Book: Combine - Asynchronous programming with Swift By Shai Mishali, Marin Todorov, Florent Pillet and Scott Gardner |
| 76 | + |
0 commit comments