In the past we had to set the countdown by Timer.TimePublisher.
We maybe coding to like bellow.
let timer = Timer.publish(every: 0.01, on: .main, in: .common)
.autoconnect()
.map { _ in return 0.01 }
extension Publisher { | |
func awaitOutput() async throws -> Output { | |
return try await withCheckedThrowingContinuation { continuation in | |
let lock = NSRecursiveLock() | |
var nillableContinuation: CheckedContinuation<Self.Output, Error>? = continuation | |
var cancelable: AnyCancellable? | |
cancelable = first().sink(receiveCompletion: { | |
lock.lock(); defer { lock.unlock() } | |
switch $0 { |
import Foundation | |
import Combine | |
import XCTest | |
extension XCTestCase { | |
func awaitPublisher<P: Publisher>( | |
_ publisher: P, | |
timeout: TimeInterval, | |
description: String, | |
trigger: (() -> Void)? = nil, |
// | |
// ViewController.swift | |
// CombineCombine | |
// | |
// Created by Woody Liu on 2021/8/16. | |
// | |
import UIKit | |
import Combine |
此篇將以
Swift
的角度去簡化 RP 理論的解釋
對於 iOS/OS 開發前端,這兩年很頻繁的會聽到這個名詞。
尤其是 Apple 推出 SwiftUI 與 Combine 以後,似乎 RxSwift 已經變成不是選修條件,越來越多公司在職缺條件中 Combine 或 RxSwift 是必要條件。
註:Combine/ RXSwift 是 RP 的高階封裝框架。
相信很多人 Google 之後會更加模糊,尤其是閱讀完 Wikipedia 艱深又空洞的理論介紹後,只看到一堆專業術語跟更多沒見過的名詞。
Pervious ParseTCA, I created some encapsulation to reproduce how TCA to implement in binding to ViewStore and Store.
Today, I will try to refactor them to more complete, like composable action and flexibility.
Refocator Reducer
// refactor after:
// | |
// OptionalNotified.swift | |
// | |
// Created by Woody Liu on 2021/7/24. | |
// | |
import Foundation | |
@propertyWrapper | |
public class OptionalNotified<Value: Equatable> { |
// | |
// KitProviderLayout.swift | |
// | |
// Created by Woody on 2022/2/11. | |
// | |
import UIKit | |
#if canImport(SwiftUI) && DEBUG | |
class ViewLayout { |
// | |
// KitProviderLayout.swift | |
// | |
// Created by Woody on 2022/2/11. | |
// | |
import UIKit | |
#if canImport(SwiftUI) && DEBUG | |
class ViewLayout { |