This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AVKit | |
struct ContentView: View { | |
@State var videos: [Video] = [] | |
var body: some View { | |
VideoView() | |
.onReceive( | |
NotificationCenter.default.publisher(for: .AVPlayerItemDidPlayToEndTime), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// many publishers | |
var cancellables = Set<AnyCancellable>() | |
$textSubject | |
.compactMap { $0 } | |
.assign(to: \.text, on: label) | |
.store(in: &cancellables) | |
// or single publisher |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new search subject with a default value | |
class ViewController: UIViewController { | |
@Published var buttonTapSubject: Int = 0 | |
@Published var textSubject: String = "" | |
var cancellables = Set<AnyCancellable>() | |
let button = UIButton() | |
let label = UILabel() | |
override func viewDidLoad() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Just("hello world!") | |
.sink { str in | |
print("the string is:", str) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new search subject with a default value | |
final class ViewController: UIViewController { | |
// Published subject initialized to zero | |
@Published var buttonTapSubject: Int = 0 | |
var cancellables = Set<AnyCancellable>() | |
let button = UIButton() | |
let label = UILabel() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a new search subject with a default value | |
let searchSubject = CurrentValueSubject<String, Never>("") | |
// Subscribe to updates | |
searchSubject | |
.debounce(for: 0.3, scheduler: DispatchQueue.main) | |
.map(searchBook(for:)) | |
.flatMap {$0.map(\.author)} | |
.subscribe(on: DispatchQueue.main) | |
.sink { author in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create passthrough subject | |
let todoSubject = PassthroughSubject<Todo, Never>() | |
// Release subscription from memory when done | |
var cancellable: AnyCancellable? | |
// Subscribe to updates | |
cancellable = todoSubject | |
.sink { todo in | |
print("New todo to add to table view:", todo.task) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Combine | |
import PlaygroundSupport | |
let label = UILabel(frame: .init(origin: .zero, size: CGSize(width: 100, height: 100))) | |
let url = URL(string: "https://api.mocki.io/v1/aebff128")! | |
var cancellables = Set<AnyCancellable>() | |
URLSession | |
.shared |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Header = styled.div` // 1 | |
height: 100px; | |
width: 100%; | |
background: #fff; | |
display: flex; // 2 | |
justify-content: center; | |
`; | |
function App() { | |
return ( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import styled from 'styled-components'; | |
const Container = styled.div` | |
background: #36393e; | |
display: flex; | |
justify-content: center; // 1 | |
flex-flow: column wrap; // 2 | |
width: 100%; | |
height: 100%; |