Skip to content

Instantly share code, notes, and snippets.

@Koshimizu-Takehito
Koshimizu-Takehito / StateObject_init.swift
Last active September 22, 2022 09:39
StateObject(wrappedValue:) を直接呼び出すと余計なオブジェクトを作る
import SwiftUI
// MARK: - ObservableObject
final class Counter: ObservableObject {
@Published private(set) var count: Int
deinit {
print("🍂", #function, count)
}
import Combine
import UIKit
public protocol CombineCompatible {}
// MARK: - UIControl
public extension UIControl {
final class Subscription<SubscriberType: Subscriber, Control: UIControl>: Combine.Subscription where SubscriberType.Input == Control {
private var subscriber: SubscriberType?
private let input: Control