vds_ios/VDS/Protocols/Changeable.swift
Matt Bruce fa273bad1c added changeable
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-04-03 10:14:44 -05:00

32 lines
680 B
Swift

//
// Changeable.swift
// VDS
//
// Created by Matt Bruce on 4/3/23.
//
import Foundation
import UIKit
import Combine
public protocol Changeable: Handlerable where Self: UIControl {
var onChangeSubscriber: AnyCancellable? { get set }
}
extension Changeable {
public var onChange: ((Self) -> ())? {
get { return nil }
set {
if let newValue {
onChangeSubscriber = publisher(for: .valueChanged)
.sink { c in
newValue(c)
}
} else {
onChangeSubscriber?.cancel()
onChangeSubscriber = nil
}
}
}
}