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
// | |
// Deduplicated.swift | |
// CountriesSwiftUI | |
// | |
// Created by Alexey Naumov on 17.12.2019. | |
// Copyright © 2019 Alexey Naumov. All rights reserved. | |
// | |
import Foundation | |
import Combine |
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
// Copyright © 2019 Alexey Naumov. MIT License | |
import Combine | |
typealias CancelBag = Set<AnyCancellable> | |
extension CancelBag { | |
mutating func collect(@Builder _ cancellables: () -> [AnyCancellable]) { | |
formUnion(cancellables()) | |
} |
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
struct NavigationCoordinator: EnvironmentKey { | |
let selectedTab = PassthroughSubject<ContentView.Tab, Never>() | |
let showActionSheet = PassthroughSubject<Bool, Never>() | |
} | |
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
lazy var navigation = NavigationCoordinator() | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { |
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
protocol BinaryEquatable: Equatable { } | |
extension BinaryEquatable { | |
static func == (lhs: Self, rhs: Self) -> Bool { | |
withUnsafeBytes(of: lhs) { lhsBytes -> Bool in | |
withUnsafeBytes(of: rhs) { rhsBytes -> Bool in | |
lhsBytes.elementsEqual(rhsBytes) | |
} | |
} | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" | |
"http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.rsync.backup</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>open</string> |
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
class AppState: ObservableObject { | |
@Published var value: Int = 0 | |
} | |
struct CustomView: View { | |
@EnvironmentObject var appState: AppState | |
var body: some View { | |
Text("Value: \(appState.value)") | |
} |
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
class HomeViewModel: ObservableObject { | |
@Published var isLoadingData = false | |
func doSomething() { ... } | |
} | |
class HomeViewController: UIViewController { | |
let loadingIndicator: UIActivityIndicatorView! | |
let viewModel = HomeViewModel() |
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
viewModel.$userName // Publisher | |
.asObservable() // Observable | |
.bind(to: nameLabel.rx.text) // RxCocoa binding | |
.disposed(by: disposeBag) |
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
viewModel.$userName | |
.sink { [weak self] name in | |
self?.nameLabel.text = name | |
} | |
.store(in: &cancelBag) |
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 RxCombine | |
import RxCocoa | |
extension Driver { | |
var publisher: AnyPublisher<Element, Never> { | |
return self.asObservable() | |
.publisher | |
.catch { _ in Empty<Element, Never>() } | |
.eraseToAnyPublisher() | |
} |
NewerOlder