I'm a newbie in Swift and this is my very first question I want to ask the community. I have a viewcontroller with a textField, custom button and a label and also I have a separate checker to check whether the entered in textField word is correct or not. So when I push the button the checker is checking and changing the color of the label (green/ red / transparent if textfield.text is empty. How can I implement this using callback closure? Thank you so much in advance!
Here is my ViewController:
final class FeedViewController: UIViewController {
private let checkTextField: UITextField = {
let textField = MyCustomTextField(
font: UIFont.systemFont(ofSize: 16),
textColor: .black,
backgroundColor: .white,
placeholder: "Enter the word")
return textField
}()
private lazy var checkButton: UIButton = {
let button = MyCustomButton(
title: "Check the word",
titleColor: .white,
backgroundColor: .systemGray,
backgroundImage: nil) {
}
button.layer.cornerRadius = 6
button.clipsToBounds = true
return button
}()
private let colorLabel: UILabel = {
let label = UILabel()
label.alpha = 0
label.toAutoLayout()
return label
}()
private let checker: CheckTextField
init(checker: CheckTextField) {
self.checker = checker
super .init(nibName: nil, bundle: nil)
}
Here is my Checker:
class CheckTextField {
private let correctWord = "correct word"
func check( word: String) {
}
}
I have managed to complete this task with notifications, but closures for me are too much complicated :(