Add closures
This commit is contained in:
parent
5b644e1ed3
commit
cda62768dd
|
|
@ -33,7 +33,7 @@ open class OTPSwiftView<View: OTPView>: BaseInitializableControl {
|
|||
public private(set) var codeStackView = UIStackView()
|
||||
public private(set) var textFieldsCollection: [View] = []
|
||||
|
||||
public var onTextEnter: ValueClosure<String>?
|
||||
public var onTextEnter: ParameterClosure<String>?
|
||||
|
||||
public var code: String {
|
||||
get {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ open class OTPTextField: UITextField {
|
|||
public weak var nextTextField: OTPTextField?
|
||||
|
||||
public var onTextChangedSignal: VoidClosure?
|
||||
public var validationClosure: ValidationClosure<String>?
|
||||
public var validationClosure: Closure<String, Bool>?
|
||||
public var caretHeight: CGFloat?
|
||||
|
||||
public var lastNotEmpty: OTPTextField {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,30 @@
|
|||
|
||||
import UIKit
|
||||
|
||||
public typealias ValueClosure<T> = ((T) -> Void)
|
||||
public typealias VoidClosure = (() -> Void)
|
||||
public typealias ValidationClosure<T> = ((T) -> Bool)
|
||||
/// Closure with custom arguments and return value.
|
||||
public typealias Closure<Input, Output> = (Input) -> Output
|
||||
|
||||
/// Closure with no arguments and custom return value.
|
||||
public typealias ResultClosure<Output> = () -> Output
|
||||
|
||||
/// Closure that takes custom arguments and returns Void.
|
||||
public typealias ParameterClosure<Input> = Closure<Input, Void>
|
||||
|
||||
// MARK: Throwable versions
|
||||
|
||||
/// Closure with custom arguments and return value, may throw an error.
|
||||
public typealias ThrowableClosure<Input, Output> = (Input) throws -> Output
|
||||
|
||||
/// Closure with no arguments and custom return value, may throw an error.
|
||||
public typealias ThrowableResultClosure<Output> = () throws -> Output
|
||||
|
||||
/// Closure that takes custom arguments and returns Void, may throw an error.
|
||||
public typealias ThrowableParameterClosure<Input> = ThrowableClosure<Input, Void>
|
||||
|
||||
// MARK: Concrete closures
|
||||
|
||||
/// Closure that takes no arguments and returns Void.
|
||||
public typealias VoidClosure = ResultClosure<Void>
|
||||
|
||||
/// Closure that takes no arguments, may throw an error and returns Void.
|
||||
public typealias ThrowableVoidClosure = () throws -> Void
|
||||
|
|
|
|||
Loading…
Reference in New Issue