RxSwift/RxCocoa/iOS/UISwitch+Rx.swift
freak4pc bd6a0b666d Remove all unneeded single-line returns
(cherry picked from commit 0bab5e2545)
2020-10-06 20:36:28 +03:00

39 lines
895 B
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// UISwitch+Rx.swift
// RxCocoa
//
// Created by Carlos García on 8/7/15.
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
//
#if os(iOS)
import UIKit
import RxSwift
extension Reactive where Base: UISwitch {
/// Reactive wrapper for `isOn` property.
public var isOn: ControlProperty<Bool> {
value
}
/// Reactive wrapper for `isOn` property.
///
/// Versions prior to iOS 10.2 were leaking `UISwitch`'s, so on those versions
/// underlying observable sequence won't complete when nothing holds a strong reference
/// to `UISwitch`.
public var value: ControlProperty<Bool> {
return base.rx.controlPropertyWithDefaultEvents(
getter: { uiSwitch in
uiSwitch.isOn
}, setter: { uiSwitch, value in
uiSwitch.isOn = value
}
)
}
}
#endif