This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let redView = UIView() | |
| redView.backgroundColor = .red | |
| addSubview(redView) { | |
| $0.edges(20).equalToSuperview() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let redView = UIView() | |
| redView.backgroundColor = .red | |
| addSubview(redView) | |
| redView.translatesAutoresizingMaskIntoConstraints = false | |
| NSLayoutConstraint.activate([ | |
| redView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20), | |
| redView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20), | |
| redView.topAnchor.constraint(equalTo: topAnchor, constant: 20), | |
| redView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -20) | |
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final class LoginViewController: UIViewController { | |
| @EmailStyle private var emailTextField | |
| @PasswordStyle private var passwordTextField | |
| @SubmitStyle private var submitButton | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class FormTextField: UITextField { | |
| var isValid: Bool = false { | |
| didSet { layer.borderColor = isValid ? validColor.cgColor : invalidColor.cgColor } | |
| } | |
| var validColor: UIColor = .black | |
| var invalidColor: UIColor = .black | |
| } | |
| @propertyWrapper | |
| struct EmailStyle { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @propertyWrapper | |
| struct EmailStyle { | |
| var wrappedValue: UITextField | |
| init(_ textField: UITextField = .init()) { | |
| wrappedValue = textField | |
| textField.autocapitalizationType = .none | |
| textField.autocorrectionType = .no | |
| textField.placeholder = "Email" | |
| textField.keyboardType = .emailAddress | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| final class LoginViewController: UIViewController { | |
| private lazy var emailTextField = UITextField() | |
| private lazy var passwordTextField = UITextField() | |
| private lazy var submitButton = UIButton() | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| emailTextField.keyboardType = .emailAddress | |
| emailTextField.autocapitalizationType = .none | |
| emailTextField.autocorrectionType = .no |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| @resultBuilder | |
| enum AutoLayoutBuilder { | |
| /// Required by every result builder to build combined results from statement blocks. | |
| static func buildBlock(_ components: ConstraintProvider...) -> [NSLayoutConstraint] { | |
| components.flatMap(\.constraints) | |
| } | |
| /// Provides support for `for..in` loops. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension Sequence where Element: Hashable { | |
| func removingDuplicates() -> [Element] { | |
| var uniques = Set<Element>() | |
| return filter { uniques.insert($0).inserted } | |
| } | |
| mutating func removeDuplicates() { | |
| self = removingDuplicates() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| // Domain layer should be platform agnostic rules that | |
| // can be fully tested against stubs and spies. This gives | |
| // us confidence our business logic is working even when | |
| // we may have issues with particular platforms integration | |
| // layers. | |
| // | |
| // Integration layer could be split out per platform. | |
| // For example on macOS you could check a MySQL database |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Combine | |
| public extension Publishers { | |
| /// Map each case in an enum to a corresponding `Publisher`. | |
| /// All `Publishers` must adhere to same response type. | |
| /// Order of `Publishers` must match `CaseIterable` order. | |
| struct CaseMap<A: Publisher, B: Publisher>: Publisher where A.Output: CaseIterable, A.Output: Equatable, A.Failure == B.Failure { | |
| public typealias Output = B.Output | |
| public typealias Failure = B.Failure |