From cda62768dd5f49feda4ce81c480f3744c5a76c35 Mon Sep 17 00:00:00 2001 From: Vlad Date: Tue, 25 Aug 2020 20:49:25 +0300 Subject: [PATCH] Add closures --- .../Views/OTPSwiftView/OTPSwiftView.swift | 2 +- .../Views/OTPTextField/OTPTextField.swift | 2 +- TISwiftUtils/Sources/Helpers/Typealias.swift | 30 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/OTPSwiftView/Sources/Views/OTPSwiftView/OTPSwiftView.swift b/OTPSwiftView/Sources/Views/OTPSwiftView/OTPSwiftView.swift index c596d1f2..1df6a0b1 100644 --- a/OTPSwiftView/Sources/Views/OTPSwiftView/OTPSwiftView.swift +++ b/OTPSwiftView/Sources/Views/OTPSwiftView/OTPSwiftView.swift @@ -33,7 +33,7 @@ open class OTPSwiftView: BaseInitializableControl { public private(set) var codeStackView = UIStackView() public private(set) var textFieldsCollection: [View] = [] - public var onTextEnter: ValueClosure? + public var onTextEnter: ParameterClosure? public var code: String { get { diff --git a/OTPSwiftView/Sources/Views/OTPTextField/OTPTextField.swift b/OTPSwiftView/Sources/Views/OTPTextField/OTPTextField.swift index 8974c6a2..19d47813 100644 --- a/OTPSwiftView/Sources/Views/OTPTextField/OTPTextField.swift +++ b/OTPSwiftView/Sources/Views/OTPTextField/OTPTextField.swift @@ -31,7 +31,7 @@ open class OTPTextField: UITextField { public weak var nextTextField: OTPTextField? public var onTextChangedSignal: VoidClosure? - public var validationClosure: ValidationClosure? + public var validationClosure: Closure? public var caretHeight: CGFloat? public var lastNotEmpty: OTPTextField { diff --git a/TISwiftUtils/Sources/Helpers/Typealias.swift b/TISwiftUtils/Sources/Helpers/Typealias.swift index cccaaac7..897d1f09 100644 --- a/TISwiftUtils/Sources/Helpers/Typealias.swift +++ b/TISwiftUtils/Sources/Helpers/Typealias.swift @@ -22,6 +22,30 @@ import UIKit -public typealias ValueClosure = ((T) -> Void) -public typealias VoidClosure = (() -> Void) -public typealias ValidationClosure = ((T) -> Bool) +/// Closure with custom arguments and return value. +public typealias Closure = (Input) -> Output + +/// Closure with no arguments and custom return value. +public typealias ResultClosure = () -> Output + +/// Closure that takes custom arguments and returns Void. +public typealias ParameterClosure = Closure + +// MARK: Throwable versions + +/// Closure with custom arguments and return value, may throw an error. +public typealias ThrowableClosure = (Input) throws -> Output + +/// Closure with no arguments and custom return value, may throw an error. +public typealias ThrowableResultClosure = () throws -> Output + +/// Closure that takes custom arguments and returns Void, may throw an error. +public typealias ThrowableParameterClosure = ThrowableClosure + +// MARK: Concrete closures + +/// Closure that takes no arguments and returns Void. +public typealias VoidClosure = ResultClosure + +/// Closure that takes no arguments, may throw an error and returns Void. +public typealias ThrowableVoidClosure = () throws -> Void