This file contains 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 Foundation | |
class Form { | |
var formItems = [FormItem]() | |
var title: String? | |
var username: String? | |
var mail: String? | |
var phoneNumber: String? |
This file contains 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
/// ViewModel to display and react to text events, to update data | |
class FormItem: FormValidable { | |
var value: String? | |
var placeholder = "" | |
var indexPath: IndexPath? | |
var valueCompletion: ((String?) -> Void)? | |
var isMandatory = true | |
This file contains 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 Foundation | |
import UIKit | |
/// Conform receiver to have data validation behavior | |
protocol FormValidable { | |
var isValid: Bool {get set} | |
var isMandatory: Bool {get set} | |
func checkValidity() | |
} |
This file contains 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 | |
/// UIKit properties for ViewModels | |
struct FormItemUIProperties { | |
var tintColor = UIColor.red | |
var keyboardType = UIKeyboardType.default | |
var cellType: FormItemCellType? | |
} |
This file contains 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
/// Conform the view receiver to be updated with a form item | |
protocol FormUpdatable { | |
func update(with formItem: FormItem) | |
} | |
/// Conform receiver to have a form item property | |
protocol FormConformity { | |
var formItem: FormItem? {get set} | |
} |
This file contains 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 Reusable | |
class FormTextFieldTableViewCell: UITableViewCell, NibReusable, FormConformity { | |
@IBOutlet weak var ibTextField: UITextField! | |
var formItem: FormItem? | |
override func awakeFromNib() { | |
super.awakeFromNib() |
This file contains 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 | |
class FormViewController: UIViewController { | |
@IBOutlet weak var ibTableView: UITableView! | |
fileprivate var form = Form() | |
// MARK: View Life Cycle | |
override func viewDidLoad() { |
This file contains 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 FormItem { | |
var value: String? | |
var placeholder = "" | |
var indexPath: IndexPath? | |
var valueCompletion: ((String?) -> Void)? | |
var uiProperties = FormItemUIProperties() | |
} |
This file contains 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
/// Conform receiver to have data validation behavior | |
protocol FormValidable { | |
var isValid: Bool {get set} | |
var isMandatory: Bool {get set} | |
func checkValidity() | |
} |
This file contains 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 Form { | |
var formItems = [FormItem]() | |
var title: String? | |
var username: String? | |
var mail: String? | |
var phoneNumber: String? | |
} |
OlderNewer