Skip to content

Instantly share code, notes, and snippets.

View bill350's full-sized avatar

Jean-Charles SORIN bill350

View GitHub Profile
import Foundation
class Form {
var formItems = [FormItem]()
var title: String?
var username: String?
var mail: String?
var phoneNumber: String?
/// 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
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()
}
import UIKit
/// UIKit properties for ViewModels
struct FormItemUIProperties {
var tintColor = UIColor.red
var keyboardType = UIKeyboardType.default
var cellType: FormItemCellType?
}
/// 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}
}
import Reusable
class FormTextFieldTableViewCell: UITableViewCell, NibReusable, FormConformity {
@IBOutlet weak var ibTextField: UITextField!
var formItem: FormItem?
override func awakeFromNib() {
super.awakeFromNib()
import UIKit
class FormViewController: UIViewController {
@IBOutlet weak var ibTableView: UITableView!
fileprivate var form = Form()
// MARK: View Life Cycle
override func viewDidLoad() {
@bill350
bill350 / FormItem.swift
Created March 22, 2017 18:18
FormItem base class
class FormItem {
var value: String?
var placeholder = ""
var indexPath: IndexPath?
var valueCompletion: ((String?) -> Void)?
var uiProperties = FormItemUIProperties()
}
/// Conform receiver to have data validation behavior
protocol FormValidable {
var isValid: Bool {get set}
var isMandatory: Bool {get set}
func checkValidity()
}
class Form {
var formItems = [FormItem]()
var title: String?
var username: String?
var mail: String?
var phoneNumber: String?
}