You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

52 lines
1.3 KiB

//
// CheckBox+Rx.swift
// GME Remit
//
// Created by InKwon James Kim on 2020/01/02.
// Copyright © 2020 Gobal Money Express Co. Ltd. All rights reserved.
//
import RxSwift
import RxCocoa
extension Reactive where Base: CheckBox {
fileprivate var delegate : RxCheckBoxDelegateProxy {
return RxCheckBoxDelegateProxy.proxy(for: base)
}
var isSelected : Observable<Bool> {
return delegate.isSelected.asObservable()
}
}
// MARK: RxCheckBoxDelegateProxy
class RxCheckBoxDelegateProxy: DelegateProxy<CheckBox, CheckBoxDelegate>,
DelegateProxyType, CheckBoxDelegate {
internal var isSelected = BehaviorSubject<Bool>(value: false)
init(parentObject: CheckBox) {
super.init(parentObject: parentObject, delegateProxy: RxCheckBoxDelegateProxy.self)
}
public static func registerKnownImplementations() {
self.register { RxCheckBoxDelegateProxy(parentObject: $0) }
}
func checkBox(_ checkBox: CheckBox, isSelected: Bool) {
self.isSelected.onNext(isSelected)
self.forwardToDelegate()?.checkBox(checkBox, isSelected: isSelected)
}
static func currentDelegate(for object: CheckBox) -> CheckBoxDelegate? {
return object.delegate
}
static func setCurrentDelegate(_ delegate: CheckBoxDelegate?, to object: CheckBox) {
object.delegate = delegate
}
deinit {
isSelected.onCompleted()
}
}