From 0bc86a49e2146be5e1a97f50292efc46c2942066 Mon Sep 17 00:00:00 2001 From: Juan Pedro Lozano Date: Fri, 2 Sep 2016 12:46:35 +0200 Subject: [PATCH] Adapted to Swift 3.0 --- SwiftForms/FormErrorType.swift | 6 +- SwiftForms/cells/FormButtonCell.swift | 8 +- SwiftForms/cells/FormCheckCell.swift | 20 +-- SwiftForms/cells/FormDateCell.swift | 64 ++++----- SwiftForms/cells/FormLabelCell.swift | 22 +-- SwiftForms/cells/FormPickerCell.swift | 36 ++--- .../cells/FormSegmentedControlCell.swift | 44 +++--- SwiftForms/cells/FormSelectorCell.swift | 14 +- SwiftForms/cells/FormSliderCell.swift | 28 ++-- SwiftForms/cells/FormStepperCell.swift | 30 ++-- SwiftForms/cells/FormSwitchCell.swift | 20 +-- SwiftForms/cells/FormTextFieldCell.swift | 127 ++++++++--------- SwiftForms/cells/FormTextViewCell.swift | 54 +++---- SwiftForms/cells/base/FormBaseCell.swift | 38 ++--- SwiftForms/cells/base/FormTitleCell.swift | 16 +-- SwiftForms/cells/base/FormValueCell.swift | 40 +++--- .../FormOptionsViewController.swift | 62 ++++---- .../controllers/FormViewController.swift | 134 +++++++++--------- SwiftForms/descriptors/FormDescriptor.swift | 2 +- .../descriptors/FormRowDescriptor.swift | 54 +++---- .../project.pbxproj | 15 +- .../xcschemes/SwiftForms.xcscheme | 2 +- SwiftFormsApplication/AppDelegate.swift | 12 +- .../ExampleFormViewController.swift | 70 ++++----- 24 files changed, 466 insertions(+), 452 deletions(-) diff --git a/SwiftForms/FormErrorType.swift b/SwiftForms/FormErrorType.swift index c537988..37356e8 100644 --- a/SwiftForms/FormErrorType.swift +++ b/SwiftForms/FormErrorType.swift @@ -6,7 +6,7 @@ // Copyright © 2016 Miguel Angel Ortuno Ortuno. All rights reserved. // -public enum FormErrorType: ErrorType { - case SectionOutOfIndex - case RowOutOfIndex +public enum FormErrorType: Error { + case sectionOutOfIndex + case rowOutOfIndex } diff --git a/SwiftForms/cells/FormButtonCell.swift b/SwiftForms/cells/FormButtonCell.swift index 73ad4e2..0d3dcdb 100644 --- a/SwiftForms/cells/FormButtonCell.swift +++ b/SwiftForms/cells/FormButtonCell.swift @@ -8,16 +8,16 @@ import UIKit -public class FormButtonCell: FormTitleCell { +open class FormButtonCell: FormTitleCell { // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - titleLabel.textAlignment = .Center + titleLabel.textAlignment = .center } - public override func update() { + open override func update() { super.update() titleLabel.text = rowDescriptor?.title } diff --git a/SwiftForms/cells/FormCheckCell.swift b/SwiftForms/cells/FormCheckCell.swift index 6d98fc3..818c355 100644 --- a/SwiftForms/cells/FormCheckCell.swift +++ b/SwiftForms/cells/FormCheckCell.swift @@ -8,17 +8,17 @@ import UIKit -public class FormCheckCell: FormTitleCell { +open class FormCheckCell: FormTitleCell { // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - selectionStyle = .Default - accessoryType = .None + selectionStyle = .default + accessoryType = .none } - public override func update() { + open override func update() { super.update() titleLabel.text = rowDescriptor?.title @@ -28,20 +28,20 @@ public class FormCheckCell: FormTitleCell { rowValue = value } else { rowValue = false - rowDescriptor?.value = rowValue + rowDescriptor?.value = rowValue as AnyObject } - accessoryType = (rowValue) ? .Checkmark : .None + accessoryType = (rowValue) ? .checkmark : .none } - public override class func formViewController(formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { + open override class func formViewController(_ formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { guard let row = selectedRow as? FormCheckCell else { return } row.check() } // MARK: Private interface - private func check() { + fileprivate func check() { var newValue: Bool if let value = rowDescriptor?.value as? Bool { newValue = !value @@ -49,7 +49,7 @@ public class FormCheckCell: FormTitleCell { else { newValue = true } - rowDescriptor?.value = newValue + rowDescriptor?.value = newValue as AnyObject update() } } diff --git a/SwiftForms/cells/FormDateCell.swift b/SwiftForms/cells/FormDateCell.swift index 5ac5537..e9093ec 100644 --- a/SwiftForms/cells/FormDateCell.swift +++ b/SwiftForms/cells/FormDateCell.swift @@ -8,29 +8,29 @@ import UIKit -public class FormDateCell: FormValueCell { +open class FormDateCell: FormValueCell { // MARK: Properties - private let datePicker = UIDatePicker() - private let hiddenTextField = UITextField(frame: CGRectZero) + fileprivate let datePicker = UIDatePicker() + fileprivate let hiddenTextField = UITextField(frame: CGRect.zero) - private let defaultDateFormatter = NSDateFormatter() + fileprivate let defaultDateFormatter = DateFormatter() // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() contentView.addSubview(hiddenTextField) hiddenTextField.inputView = datePicker - datePicker.datePickerMode = .Date - datePicker.addTarget(self, action: #selector(FormDateCell.valueChanged(_:)), forControlEvents: .ValueChanged) + datePicker.datePickerMode = .date + datePicker.addTarget(self, action: #selector(FormDateCell.valueChanged(_:)), for: .valueChanged) } - public override func update() { + open override func update() { super.update() - if let showsInputToolbar = rowDescriptor?.configuration.cell.showsInputToolbar where showsInputToolbar && hiddenTextField.inputAccessoryView == nil { + if let showsInputToolbar = rowDescriptor?.configuration.cell.showsInputToolbar , showsInputToolbar && hiddenTextField.inputAccessoryView == nil { hiddenTextField.inputAccessoryView = inputAccesoryView() } @@ -38,59 +38,59 @@ public class FormDateCell: FormValueCell { if let rowType = rowDescriptor?.type { switch rowType { - case .Date: - datePicker.datePickerMode = .Date - defaultDateFormatter.dateStyle = .LongStyle - defaultDateFormatter.timeStyle = .NoStyle - case .Time: - datePicker.datePickerMode = .Time - defaultDateFormatter.dateStyle = .NoStyle - defaultDateFormatter.timeStyle = .ShortStyle + case .date: + datePicker.datePickerMode = .date + defaultDateFormatter.dateStyle = .long + defaultDateFormatter.timeStyle = .none + case .time: + datePicker.datePickerMode = .time + defaultDateFormatter.dateStyle = .none + defaultDateFormatter.timeStyle = .short default: - datePicker.datePickerMode = .DateAndTime - defaultDateFormatter.dateStyle = .LongStyle - defaultDateFormatter.timeStyle = .ShortStyle + datePicker.datePickerMode = .dateAndTime + defaultDateFormatter.dateStyle = .long + defaultDateFormatter.timeStyle = .short } } - if let date = rowDescriptor?.value as? NSDate { + if let date = rowDescriptor?.value as? Date { datePicker.date = date - valueLabel.text = getDateFormatter().stringFromDate(date) + valueLabel.text = getDateFormatter().string(from: date) } } - public override class func formViewController(formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { + open override class func formViewController(_ formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { guard let row = selectedRow as? FormDateCell else { return } if row.rowDescriptor?.value == nil { - let date = NSDate() - row.rowDescriptor?.value = date - row.valueLabel.text = row.getDateFormatter().stringFromDate(date) + let date = Date() + row.rowDescriptor?.value = date as AnyObject + row.valueLabel.text = row.getDateFormatter().string(from: date) row.update() } row.hiddenTextField.becomeFirstResponder() } - public override func firstResponderElement() -> UIResponder? { + open override func firstResponderElement() -> UIResponder? { return hiddenTextField } - public override class func formRowCanBecomeFirstResponder() -> Bool { + open override class func formRowCanBecomeFirstResponder() -> Bool { return true } // MARK: Actions - internal func valueChanged(sender: UIDatePicker) { - rowDescriptor?.value = sender.date - valueLabel.text = getDateFormatter().stringFromDate(sender.date) + internal func valueChanged(_ sender: UIDatePicker) { + rowDescriptor?.value = sender.date as AnyObject + valueLabel.text = getDateFormatter().string(from: sender.date) update() } // MARK: Private interface - private func getDateFormatter() -> NSDateFormatter { + fileprivate func getDateFormatter() -> DateFormatter { guard let dateFormatter = rowDescriptor?.configuration.date.dateFormatter else { return defaultDateFormatter } return dateFormatter } diff --git a/SwiftForms/cells/FormLabelCell.swift b/SwiftForms/cells/FormLabelCell.swift index 533171d..5104b29 100644 --- a/SwiftForms/cells/FormLabelCell.swift +++ b/SwiftForms/cells/FormLabelCell.swift @@ -15,28 +15,28 @@ class FormLabelCell: FormValueCell { override func configure() { super.configure() - accessoryType = .None + accessoryType = .none titleLabel.translatesAutoresizingMaskIntoConstraints = false valueLabel.translatesAutoresizingMaskIntoConstraints = false - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) - valueLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) + valueLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) - valueLabel.textColor = UIColor.lightGrayColor() - valueLabel.textAlignment = .Right + valueLabel.textColor = UIColor.lightGray + valueLabel.textAlignment = .right contentView.addSubview(titleLabel) contentView.addSubview(valueLabel) - titleLabel.setContentHuggingPriority(500, forAxis: .Horizontal) - titleLabel.setContentCompressionResistancePriority(1000, forAxis: .Horizontal) + titleLabel.setContentHuggingPriority(500, for: .horizontal) + titleLabel.setContentCompressionResistancePriority(1000, for: .horizontal) // apply constant constraints - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) } override func update() { diff --git a/SwiftForms/cells/FormPickerCell.swift b/SwiftForms/cells/FormPickerCell.swift index 1eff270..580cea9 100644 --- a/SwiftForms/cells/FormPickerCell.swift +++ b/SwiftForms/cells/FormPickerCell.swift @@ -8,18 +8,18 @@ import UIKit -public class FormPickerCell: FormValueCell, UIPickerViewDelegate, UIPickerViewDataSource { +open class FormPickerCell: FormValueCell, UIPickerViewDelegate, UIPickerViewDataSource { // MARK: Properties - private let picker = UIPickerView() - private let hiddenTextField = UITextField(frame: CGRectZero) + fileprivate let picker = UIPickerView() + fileprivate let hiddenTextField = UITextField(frame: CGRect.zero) // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - accessoryType = .None + accessoryType = .none picker.delegate = self picker.dataSource = self @@ -28,11 +28,11 @@ public class FormPickerCell: FormValueCell, UIPickerViewDelegate, UIPickerViewDa contentView.addSubview(hiddenTextField) } - public override func update() { + open override func update() { super.update() picker.reloadAllComponents() - if let showsInputToolbar = rowDescriptor?.configuration.cell.showsInputToolbar where showsInputToolbar && hiddenTextField.inputAccessoryView == nil { + if let showsInputToolbar = rowDescriptor?.configuration.cell.showsInputToolbar , showsInputToolbar && hiddenTextField.inputAccessoryView == nil { hiddenTextField.inputAccessoryView = inputAccesoryView() } @@ -40,9 +40,9 @@ public class FormPickerCell: FormValueCell, UIPickerViewDelegate, UIPickerViewDa if let selectedValue = rowDescriptor?.value { valueLabel.text = rowDescriptor?.configuration.selection.optionTitleClosure?(selectedValue) - if let options = rowDescriptor?.configuration.selection.options where !options.isEmpty { + if let options = rowDescriptor?.configuration.selection.options , !options.isEmpty { var selectedIndex: Int? - for (index, value) in options.enumerate() { + for (index, value) in options.enumerated() { if value === selectedValue { selectedIndex = index break @@ -55,15 +55,15 @@ public class FormPickerCell: FormValueCell, UIPickerViewDelegate, UIPickerViewDa } } - public override func firstResponderElement() -> UIResponder? { + open override func firstResponderElement() -> UIResponder? { return hiddenTextField } - public override class func formViewController(formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { + open override class func formViewController(_ formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { guard let row = selectedRow as? FormPickerCell else { return } if selectedRow.rowDescriptor?.value == nil { - guard let options = selectedRow.rowDescriptor?.configuration.selection.options where !options.isEmpty else { return } + guard let options = selectedRow.rowDescriptor?.configuration.selection.options , !options.isEmpty else { return } let value = options[0] selectedRow.rowDescriptor?.value = value row.valueLabel.text = selectedRow.rowDescriptor?.configuration.selection.optionTitleClosure?(value) @@ -77,14 +77,14 @@ public class FormPickerCell: FormValueCell, UIPickerViewDelegate, UIPickerViewDa // MARK: UIPickerViewDelegate - public func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { - guard let options = rowDescriptor?.configuration.selection.options where !options.isEmpty else { return nil } + open func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { + guard let options = rowDescriptor?.configuration.selection.options , !options.isEmpty else { return nil } guard row < options.count else { return nil } return rowDescriptor?.configuration.selection.optionTitleClosure?(options[row]) } - public func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { - guard let options = rowDescriptor?.configuration.selection.options where !options.isEmpty else { return } + open func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { + guard let options = rowDescriptor?.configuration.selection.options , !options.isEmpty else { return } guard row < options.count else { return } let newValue = options[row] rowDescriptor?.value = newValue @@ -93,11 +93,11 @@ public class FormPickerCell: FormValueCell, UIPickerViewDelegate, UIPickerViewDa // MARK: UIPickerViewDataSource - public func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { + open func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } - public func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { + open func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { guard let options = rowDescriptor?.configuration.selection.options else { return 0 } return options.count } diff --git a/SwiftForms/cells/FormSegmentedControlCell.swift b/SwiftForms/cells/FormSegmentedControlCell.swift index 146f65c..b3f05d7 100644 --- a/SwiftForms/cells/FormSegmentedControlCell.swift +++ b/SwiftForms/cells/FormSegmentedControlCell.swift @@ -8,49 +8,49 @@ import UIKit -public class FormSegmentedControlCell: FormBaseCell { +open class FormSegmentedControlCell: FormBaseCell { // MARK: Cell views - public let titleLabel = UILabel() - public let segmentedControl = UISegmentedControl() + open let titleLabel = UILabel() + open let segmentedControl = UISegmentedControl() // MARK: Properties - private var customConstraints: [AnyObject] = [] + fileprivate var customConstraints: [AnyObject] = [] // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - selectionStyle = .None + selectionStyle = .none titleLabel.translatesAutoresizingMaskIntoConstraints = false segmentedControl.translatesAutoresizingMaskIntoConstraints = false - titleLabel.setContentCompressionResistancePriority(500, forAxis: .Horizontal) - segmentedControl.setContentCompressionResistancePriority(500, forAxis: .Horizontal) + titleLabel.setContentCompressionResistancePriority(500, for: .horizontal) + segmentedControl.setContentCompressionResistancePriority(500, for: .horizontal) - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) contentView.addSubview(titleLabel) contentView.addSubview(segmentedControl) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: segmentedControl, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: segmentedControl, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) - segmentedControl.addTarget(self, action: #selector(FormSegmentedControlCell.valueChanged(_:)), forControlEvents: .ValueChanged) + segmentedControl.addTarget(self, action: #selector(FormSegmentedControlCell.valueChanged(_:)), for: .valueChanged) } - public override func update() { + open override func update() { super.update() titleLabel.text = rowDescriptor?.title updateSegmentedControl() guard let value = rowDescriptor?.value else { return } - guard let options = rowDescriptor?.configuration.selection.options where !options.isEmpty else { return } + guard let options = rowDescriptor?.configuration.selection.options , !options.isEmpty else { return } var idx = 0 for optionValue in options { @@ -62,12 +62,12 @@ public class FormSegmentedControlCell: FormBaseCell { } } - public override func constraintsViews() -> [String : UIView] { + open override func constraintsViews() -> [String : UIView] { return ["titleLabel" : titleLabel, "segmentedControl" : segmentedControl] } - public override func defaultVisualConstraints() -> [String] { - if let text = titleLabel.text where text.characters.count > 0 { + open override func defaultVisualConstraints() -> [String] { + if let text = titleLabel.text , text.characters.count > 0 { return ["H:|-16-[titleLabel]-16-[segmentedControl]-16-|"] } else { return ["H:|-16-[segmentedControl]-16-|"] @@ -76,23 +76,23 @@ public class FormSegmentedControlCell: FormBaseCell { // MARK: Actions - internal func valueChanged(sender: UISegmentedControl) { - guard let options = rowDescriptor?.configuration.selection.options where !options.isEmpty else { return } + internal func valueChanged(_ sender: UISegmentedControl) { + guard let options = rowDescriptor?.configuration.selection.options , !options.isEmpty else { return } let value = options[sender.selectedSegmentIndex] rowDescriptor?.value = value } // MARK: Private - private func updateSegmentedControl() { + fileprivate func updateSegmentedControl() { segmentedControl.removeAllSegments() - guard let options = rowDescriptor?.configuration.selection.options where !options.isEmpty else { return } + guard let options = rowDescriptor?.configuration.selection.options , !options.isEmpty else { return } var idx = 0 for value in options { let title = rowDescriptor?.configuration.selection.optionTitleClosure?(value) - segmentedControl.insertSegmentWithTitle(title, atIndex: idx, animated: false) + segmentedControl.insertSegment(withTitle: title, at: idx, animated: false) idx += 1 } } diff --git a/SwiftForms/cells/FormSelectorCell.swift b/SwiftForms/cells/FormSelectorCell.swift index 016deb1..7906778 100644 --- a/SwiftForms/cells/FormSelectorCell.swift +++ b/SwiftForms/cells/FormSelectorCell.swift @@ -8,11 +8,11 @@ import UIKit -public class FormSelectorCell: FormValueCell { +open class FormSelectorCell: FormValueCell { // MARK: FormBaseCell - public override func update() { + open override func update() { super.update() titleLabel.text = rowDescriptor?.title @@ -20,7 +20,7 @@ public class FormSelectorCell: FormValueCell { var title: String? if let multipleValues = rowDescriptor?.value as? [AnyObject] { var multipleValuesTitle = "" - for (index, selectedValue) in multipleValues.enumerate() { + for (index, selectedValue) in multipleValues.enumerated() { guard let selectedValueTitle = rowDescriptor?.configuration.selection.optionTitleClosure?(selectedValue) else { continue } if index != 0 { multipleValuesTitle += ", " @@ -32,16 +32,16 @@ public class FormSelectorCell: FormValueCell { title = rowDescriptor?.configuration.selection.optionTitleClosure?(singleValue) } - if let title = title where title.characters.count > 0 { + if let title = title , title.characters.count > 0 { valueLabel.text = title - valueLabel.textColor = UIColor.blackColor() + valueLabel.textColor = UIColor.black } else { valueLabel.text = rowDescriptor?.configuration.cell.placeholder - valueLabel.textColor = UIColor.lightGrayColor() + valueLabel.textColor = UIColor.lightGray } } - public override class func formViewController(formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { + open override class func formViewController(_ formViewController: FormViewController, didSelectRow selectedRow: FormBaseCell) { guard let row = selectedRow as? FormSelectorCell else { return } formViewController.view.endEditing(true) diff --git a/SwiftForms/cells/FormSliderCell.swift b/SwiftForms/cells/FormSliderCell.swift index ff5ed96..7466df0 100644 --- a/SwiftForms/cells/FormSliderCell.swift +++ b/SwiftForms/cells/FormSliderCell.swift @@ -8,40 +8,40 @@ import UIKit -public class FormSliderCell: FormTitleCell { +open class FormSliderCell: FormTitleCell { // MARK: Cell views - public let sliderView = UISlider() + open let sliderView = UISlider() // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - selectionStyle = .None + selectionStyle = .none titleLabel.translatesAutoresizingMaskIntoConstraints = false sliderView.translatesAutoresizingMaskIntoConstraints = false - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) contentView.addSubview(titleLabel) contentView.addSubview(sliderView) - titleLabel.setContentHuggingPriority(500, forAxis: .Horizontal) + titleLabel.setContentHuggingPriority(500, for: .horizontal) - contentView.addConstraint(NSLayoutConstraint(item: sliderView, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: sliderView, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) - sliderView.addTarget(self, action: #selector(FormSliderCell.valueChanged(_:)), forControlEvents: .ValueChanged) + sliderView.addTarget(self, action: #selector(FormSliderCell.valueChanged(_:)), for: .valueChanged) } - public override func update() { + open override func update() { super.update() if let maximumValue = rowDescriptor?.configuration.stepper.maximumValue { sliderView.maximumValue = Float(maximumValue) } if let minimumValue = rowDescriptor?.configuration.stepper.minimumValue { sliderView.minimumValue = Float(minimumValue) } - if let continuous = rowDescriptor?.configuration.stepper.continuous { sliderView.continuous = continuous } + if let continuous = rowDescriptor?.configuration.stepper.continuous { sliderView.isContinuous = continuous } titleLabel.text = rowDescriptor?.title @@ -49,15 +49,15 @@ public class FormSliderCell: FormTitleCell { sliderView.value = value } else { sliderView.value = sliderView.minimumValue - rowDescriptor?.value = sliderView.minimumValue + rowDescriptor?.value = sliderView.minimumValue as AnyObject } } - public override func constraintsViews() -> [String : UIView] { + open override func constraintsViews() -> [String : UIView] { return ["titleLabel" : titleLabel, "sliderView" : sliderView] } - public override func defaultVisualConstraints() -> [String] { + open override func defaultVisualConstraints() -> [String] { var constraints: [String] = [] constraints.append("V:|[titleLabel]|") @@ -69,7 +69,7 @@ public class FormSliderCell: FormTitleCell { // MARK: Actions internal func valueChanged(_: UISlider) { - rowDescriptor?.value = sliderView.value + rowDescriptor?.value = sliderView.value as AnyObject update() } } diff --git a/SwiftForms/cells/FormStepperCell.swift b/SwiftForms/cells/FormStepperCell.swift index b530f7c..16a021e 100644 --- a/SwiftForms/cells/FormStepperCell.swift +++ b/SwiftForms/cells/FormStepperCell.swift @@ -8,39 +8,39 @@ import UIKit -public class FormStepperCell: FormTitleCell { +open class FormStepperCell: FormTitleCell { // MARK: Cell views - public let stepperView = UIStepper() - public let countLabel = UILabel() + open let stepperView = UIStepper() + open let countLabel = UILabel() // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - selectionStyle = .None + selectionStyle = .none titleLabel.translatesAutoresizingMaskIntoConstraints = false stepperView.translatesAutoresizingMaskIntoConstraints = false countLabel.translatesAutoresizingMaskIntoConstraints = false - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) - countLabel.textAlignment = .Right + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) + countLabel.textAlignment = .right contentView.addSubview(titleLabel) contentView.addSubview(countLabel) contentView.addSubview(stepperView) - titleLabel.setContentHuggingPriority(500, forAxis: .Horizontal) + titleLabel.setContentHuggingPriority(500, for: .horizontal) - contentView.addConstraint(NSLayoutConstraint(item: stepperView, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: stepperView, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) - stepperView.addTarget(self, action: #selector(FormStepperCell.valueChanged(_:)), forControlEvents: .ValueChanged) + stepperView.addTarget(self, action: #selector(FormStepperCell.valueChanged(_:)), for: .valueChanged) } - public override func update() { + open override func update() { super.update() if let maximumValue = rowDescriptor?.configuration.stepper.maximumValue { stepperView.maximumValue = maximumValue } @@ -54,16 +54,16 @@ public class FormStepperCell: FormTitleCell { countLabel.text = String(value) } else { stepperView.value = stepperView.minimumValue - rowDescriptor?.value = stepperView.minimumValue + rowDescriptor?.value = stepperView.minimumValue as AnyObject countLabel.text = String(stepperView.minimumValue) } } - public override func constraintsViews() -> [String : UIView] { + open override func constraintsViews() -> [String : UIView] { return ["titleLabel" : titleLabel, "countLabel" : countLabel, "stepperView" : stepperView] } - public override func defaultVisualConstraints() -> [String] { + open override func defaultVisualConstraints() -> [String] { var constraints: [String] = [] constraints.append("V:|[titleLabel]|") @@ -76,7 +76,7 @@ public class FormStepperCell: FormTitleCell { // MARK: Actions internal func valueChanged(_: UISwitch) { - rowDescriptor?.value = stepperView.value + rowDescriptor?.value = stepperView.value as AnyObject update() } } diff --git a/SwiftForms/cells/FormSwitchCell.swift b/SwiftForms/cells/FormSwitchCell.swift index e9f3f58..064eccf 100644 --- a/SwiftForms/cells/FormSwitchCell.swift +++ b/SwiftForms/cells/FormSwitchCell.swift @@ -8,40 +8,40 @@ import UIKit -public class FormSwitchCell: FormTitleCell { +open class FormSwitchCell: FormTitleCell { // MARK: Cell views - public let switchView = UISwitch() + open let switchView = UISwitch() // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - selectionStyle = .None + selectionStyle = .none - switchView.addTarget(self, action: #selector(FormSwitchCell.valueChanged(_:)), forControlEvents: .ValueChanged) + switchView.addTarget(self, action: #selector(FormSwitchCell.valueChanged(_:)), for: .valueChanged) accessoryView = switchView } - public override func update() { + open override func update() { super.update() titleLabel.text = rowDescriptor?.title if let value = rowDescriptor?.value as? Bool { - switchView.on = value + switchView.isOn = value } else { - switchView.on = false - rowDescriptor?.value = false + switchView.isOn = false + rowDescriptor?.value = false as AnyObject } } // MARK: Actions internal func valueChanged(_: UISwitch) { - rowDescriptor?.value = switchView.on + rowDescriptor?.value = switchView.isOn as AnyObject update() } } diff --git a/SwiftForms/cells/FormTextFieldCell.swift b/SwiftForms/cells/FormTextFieldCell.swift index 76bb606..63b4cc7 100644 --- a/SwiftForms/cells/FormTextFieldCell.swift +++ b/SwiftForms/cells/FormTextFieldCell.swift @@ -8,48 +8,48 @@ import UIKit -public class FormTextFieldCell: FormBaseCell { +open class FormTextFieldCell: FormBaseCell { // MARK: Cell views - public let titleLabel = UILabel() - public let textField = UITextField() + open let titleLabel = UILabel() + open let textField = UITextField() // MARK: Properties - private var customConstraints: [AnyObject] = [] + fileprivate var customConstraints: [AnyObject] = [] // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - selectionStyle = .None + selectionStyle = .none titleLabel.translatesAutoresizingMaskIntoConstraints = false textField.translatesAutoresizingMaskIntoConstraints = false - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) - textField.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) + textField.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) contentView.addSubview(titleLabel) contentView.addSubview(textField) - titleLabel.setContentHuggingPriority(500, forAxis: .Horizontal) - titleLabel.setContentCompressionResistancePriority(1000, forAxis: .Horizontal) + titleLabel.setContentHuggingPriority(500, for: .horizontal) + titleLabel.setContentCompressionResistancePriority(1000, for: .horizontal) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) - textField.addTarget(self, action: #selector(FormTextFieldCell.editingChanged(_:)), forControlEvents: .EditingChanged) + textField.addTarget(self, action: #selector(FormTextFieldCell.editingChanged(_:)), for: .editingChanged) } - public override func update() { + open override func update() { super.update() - if let showsInputToolbar = rowDescriptor?.configuration.cell.showsInputToolbar where showsInputToolbar && textField.inputAccessoryView == nil { + if let showsInputToolbar = rowDescriptor?.configuration.cell.showsInputToolbar , showsInputToolbar && textField.inputAccessoryView == nil { textField.inputAccessoryView = inputAccesoryView() } @@ -57,49 +57,49 @@ public class FormTextFieldCell: FormBaseCell { textField.text = rowDescriptor?.value as? String textField.placeholder = rowDescriptor?.configuration.cell.placeholder - textField.secureTextEntry = false - textField.clearButtonMode = .WhileEditing + textField.isSecureTextEntry = false + textField.clearButtonMode = .whileEditing if let type = rowDescriptor?.type { switch type { - case .Text: - textField.autocorrectionType = .Default - textField.autocapitalizationType = .Sentences - textField.keyboardType = .Default - case .Number: - textField.keyboardType = .NumberPad - case .NumbersAndPunctuation: - textField.keyboardType = .NumbersAndPunctuation - case .Decimal: - textField.keyboardType = .DecimalPad - case .Name: - textField.autocorrectionType = .No - textField.autocapitalizationType = .Words - textField.keyboardType = .Default - case .Phone: - textField.keyboardType = .PhonePad - case .NamePhone: - textField.autocorrectionType = .No - textField.autocapitalizationType = .Words - textField.keyboardType = .NamePhonePad - case .URL: - textField.autocorrectionType = .No - textField.autocapitalizationType = .None + case .text: + textField.autocorrectionType = .default + textField.autocapitalizationType = .sentences + textField.keyboardType = .default + case .number: + textField.keyboardType = .numberPad + case .numbersAndPunctuation: + textField.keyboardType = .numbersAndPunctuation + case .decimal: + textField.keyboardType = .decimalPad + case .name: + textField.autocorrectionType = .no + textField.autocapitalizationType = .words + textField.keyboardType = .default + case .phone: + textField.keyboardType = .phonePad + case .namePhone: + textField.autocorrectionType = .no + textField.autocapitalizationType = .words + textField.keyboardType = .namePhonePad + case .url: + textField.autocorrectionType = .no + textField.autocapitalizationType = .none textField.keyboardType = .URL - case .Twitter: - textField.autocorrectionType = .No - textField.autocapitalizationType = .None - textField.keyboardType = .Twitter - case .Email: - textField.autocorrectionType = .No - textField.autocapitalizationType = .None - textField.keyboardType = .EmailAddress - case .ASCIICapable: - textField.autocorrectionType = .No - textField.autocapitalizationType = .None - textField.keyboardType = .ASCIICapable - case .Password: - textField.secureTextEntry = true + case .twitter: + textField.autocorrectionType = .no + textField.autocapitalizationType = .none + textField.keyboardType = .twitter + case .email: + textField.autocorrectionType = .no + textField.autocapitalizationType = .none + textField.keyboardType = .emailAddress + case .asciiCapable: + textField.autocorrectionType = .no + textField.autocapitalizationType = .none + textField.keyboardType = .asciiCapable + case .password: + textField.isSecureTextEntry = true textField.clearsOnBeginEditing = false default: break @@ -107,7 +107,7 @@ public class FormTextFieldCell: FormBaseCell { } } - public override func constraintsViews() -> [String : UIView] { + open override func constraintsViews() -> [String : UIView] { var views = ["titleLabel" : titleLabel, "textField" : textField] if self.imageView!.image != nil { views["imageView"] = imageView @@ -115,7 +115,7 @@ public class FormTextFieldCell: FormBaseCell { return views } - public override func defaultVisualConstraints() -> [String] { + open override func defaultVisualConstraints() -> [String] { if self.imageView!.image != nil { if titleLabel.text != nil && (titleLabel.text!).characters.count > 0 { return ["H:[imageView]-[titleLabel]-[textField]-16-|"] @@ -131,19 +131,18 @@ public class FormTextFieldCell: FormBaseCell { } } - public override func firstResponderElement() -> UIResponder? { + open override func firstResponderElement() -> UIResponder? { return textField } - public override class func formRowCanBecomeFirstResponder() -> Bool { + open override class func formRowCanBecomeFirstResponder() -> Bool { return true } // MARK: Actions - internal func editingChanged(sender: UITextField) { - guard let text = sender.text where text.characters.count > 0 else { rowDescriptor?.value = nil; update(); return } - rowDescriptor?.value = text - update() + internal func editingChanged(_ sender: UITextField) { + guard let text = sender.text, text.characters.count > 0 else { rowDescriptor?.value = nil; update(); return } + rowDescriptor?.value = text as AnyObject } } diff --git a/SwiftForms/cells/FormTextViewCell.swift b/SwiftForms/cells/FormTextViewCell.swift index 0f0d38d..179463d 100644 --- a/SwiftForms/cells/FormTextViewCell.swift +++ b/SwiftForms/cells/FormTextViewCell.swift @@ -8,61 +8,61 @@ import UIKit -public class FormTextViewCell : FormBaseCell, UITextViewDelegate { +open class FormTextViewCell : FormBaseCell, UITextViewDelegate { // MARK: Cell views - public let titleLabel = UILabel() - public let textField = UITextView() + open let titleLabel = UILabel() + open let textField = UITextView() // MARK: Properties - private var customConstraints: [AnyObject]! + fileprivate var customConstraints: [AnyObject]! // MARK: Class Funcs - public override class func formRowCellHeight() -> CGFloat { + open override class func formRowCellHeight() -> CGFloat { return 110.0 } // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - selectionStyle = .None + selectionStyle = .none titleLabel.translatesAutoresizingMaskIntoConstraints = false textField.translatesAutoresizingMaskIntoConstraints = false - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) - textField.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) + textField.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) contentView.addSubview(titleLabel) contentView.addSubview(textField) - titleLabel.setContentHuggingPriority(500, forAxis: .Horizontal) + titleLabel.setContentHuggingPriority(500, for: .horizontal) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .Top, relatedBy: .Equal, toItem: contentView, attribute: .Top, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .Bottom, relatedBy: .Equal, toItem: contentView, attribute: .Bottom, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .top, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: textField, attribute: .bottom, relatedBy: .equal, toItem: contentView, attribute: .bottom, multiplier: 1.0, constant: 0.0)) textField.delegate = self } - public override func update() { + open override func update() { titleLabel.text = rowDescriptor?.title textField.text = rowDescriptor?.value as? String - textField.secureTextEntry = false - textField.autocorrectionType = .Default - textField.autocapitalizationType = .Sentences - textField.keyboardType = .Default + textField.isSecureTextEntry = false + textField.autocorrectionType = .default + textField.autocapitalizationType = .sentences + textField.keyboardType = .default } - public override func constraintsViews() -> [String : UIView] { + open override func constraintsViews() -> [String : UIView] { var views = ["titleLabel" : titleLabel, "textField" : textField] if self.imageView!.image != nil { views["imageView"] = imageView @@ -70,15 +70,15 @@ public class FormTextViewCell : FormBaseCell, UITextViewDelegate { return views } - public override func defaultVisualConstraints() -> [String] { + open override func defaultVisualConstraints() -> [String] { if self.imageView!.image != nil { - if let text = titleLabel.text where text.characters.count > 0 { + if let text = titleLabel.text , text.characters.count > 0 { return ["H:[imageView]-[titleLabel]-[textField]-16-|"] } else { return ["H:[imageView]-[textField]-16-|"] } } else { - if let text = titleLabel.text where text.characters.count > 0 { + if let text = titleLabel.text , text.characters.count > 0 { return ["H:|-16-[titleLabel]-[textField]-16-|"] } else { return ["H:|-16-[textField]-16-|"] @@ -88,9 +88,9 @@ public class FormTextViewCell : FormBaseCell, UITextViewDelegate { // MARK: UITextViewDelegate - public func textViewDidChange(textView: UITextView) { - guard let text = textView.text where text.characters.count > 0 else { rowDescriptor?.value = nil; update(); return } - rowDescriptor?.value = text + open func textViewDidChange(_ textView: UITextView) { + guard let text = textView.text , text.characters.count > 0 else { rowDescriptor?.value = nil; update(); return } + rowDescriptor?.value = text as AnyObject update() } -} \ No newline at end of file +} diff --git a/SwiftForms/cells/base/FormBaseCell.swift b/SwiftForms/cells/base/FormBaseCell.swift index eb43ae4..e294eb1 100644 --- a/SwiftForms/cells/base/FormBaseCell.swift +++ b/SwiftForms/cells/base/FormBaseCell.swift @@ -8,19 +8,19 @@ import UIKit -public class FormBaseCell: UITableViewCell { +open class FormBaseCell: UITableViewCell { // MARK: Properties - public var rowDescriptor: FormRowDescriptor? { + open var rowDescriptor: FormRowDescriptor? { didSet { self.update() } } - public weak var formViewController: FormViewController? + open weak var formViewController: FormViewController? - private var customConstraints: [NSLayoutConstraint] = [] + fileprivate var customConstraints: [NSLayoutConstraint] = [] // MARK: Init @@ -34,39 +34,39 @@ public class FormBaseCell: UITableViewCell { // MARK: Public interface - public func configure() { + open func configure() { /// override } - public func update() { + open func update() { /// override } - public func defaultVisualConstraints() -> [String] { + open func defaultVisualConstraints() -> [String] { /// override return [] } - public func constraintsViews() -> [String : UIView] { + open func constraintsViews() -> [String : UIView] { /// override return [:] } - public func firstResponderElement() -> UIResponder? { + open func firstResponderElement() -> UIResponder? { /// override return nil } - public func inputAccesoryView() -> UIToolbar { + open func inputAccesoryView() -> UIToolbar { let actionBar = UIToolbar() - actionBar.translucent = true + actionBar.isTranslucent = true actionBar.sizeToFit() - actionBar.barStyle = .Default + actionBar.barStyle = .default - let doneButton = UIBarButtonItem(title: NSLocalizedString("Done", comment: ""), style: .Done, target: self, action: #selector(FormBaseCell.handleDoneAction(_:))) + let doneButton = UIBarButtonItem(title: NSLocalizedString("Done", comment: ""), style: .done, target: self, action: #selector(FormBaseCell.handleDoneAction(_:))) - let flexible = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil) + let flexible = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) actionBar.items = [flexible, doneButton] return actionBar @@ -76,20 +76,20 @@ public class FormBaseCell: UITableViewCell { firstResponderElement()?.resignFirstResponder() } - public class func formRowCellHeight() -> CGFloat { + open class func formRowCellHeight() -> CGFloat { return 44.0 } - public class func formRowCanBecomeFirstResponder() -> Bool { + open class func formRowCanBecomeFirstResponder() -> Bool { return false } - public class func formViewController(formViewController: FormViewController, didSelectRow: FormBaseCell) { + open class func formViewController(_ formViewController: FormViewController, didSelectRow: FormBaseCell) { } // MARK: Constraints - public override func updateConstraints() { + open override func updateConstraints() { if customConstraints.count > 0 { contentView.removeConstraints(customConstraints) } @@ -107,7 +107,7 @@ public class FormBaseCell: UITableViewCell { } for visualConstraint in visualConstraints { - let constraints = NSLayoutConstraint.constraintsWithVisualFormat(visualConstraint, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views) + let constraints = NSLayoutConstraint.constraints(withVisualFormat: visualConstraint, options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views) for constraint in constraints { customConstraints.append(constraint) } diff --git a/SwiftForms/cells/base/FormTitleCell.swift b/SwiftForms/cells/base/FormTitleCell.swift index c6c9fb9..aefe09d 100644 --- a/SwiftForms/cells/base/FormTitleCell.swift +++ b/SwiftForms/cells/base/FormTitleCell.swift @@ -8,31 +8,31 @@ import UIKit -public class FormTitleCell: FormBaseCell { +open class FormTitleCell: FormBaseCell { // MARK: Cell views - public let titleLabel = UILabel() + open let titleLabel = UILabel() // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() titleLabel.translatesAutoresizingMaskIntoConstraints = false - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) // apply constant constraints contentView.addSubview(titleLabel) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) } - public override func constraintsViews() -> [String : UIView] { + open override func constraintsViews() -> [String : UIView] { return ["titleLabel" : titleLabel] } - public override func defaultVisualConstraints() -> [String] { + open override func defaultVisualConstraints() -> [String] { return ["H:|-16-[titleLabel]-16-|"] } } diff --git a/SwiftForms/cells/base/FormValueCell.swift b/SwiftForms/cells/base/FormValueCell.swift index 818baa2..db28b10 100644 --- a/SwiftForms/cells/base/FormValueCell.swift +++ b/SwiftForms/cells/base/FormValueCell.swift @@ -8,55 +8,55 @@ import UIKit -public class FormValueCell: FormBaseCell { +open class FormValueCell: FormBaseCell { // MARK: Cell views - public let titleLabel = UILabel() - public let valueLabel = UILabel() + open let titleLabel = UILabel() + open let valueLabel = UILabel() // MARK: Properties - private var customConstraints: [AnyObject]! + fileprivate var customConstraints: [AnyObject]! // MARK: FormBaseCell - public override func configure() { + open override func configure() { super.configure() - accessoryType = .DisclosureIndicator + accessoryType = .disclosureIndicator titleLabel.translatesAutoresizingMaskIntoConstraints = false valueLabel.translatesAutoresizingMaskIntoConstraints = false - titleLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) - valueLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleBody) + titleLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) + valueLabel.font = UIFont.preferredFont(forTextStyle: UIFontTextStyle.body) - valueLabel.textColor = UIColor.lightGrayColor() - valueLabel.textAlignment = .Right + valueLabel.textColor = UIColor.lightGray + valueLabel.textAlignment = .right contentView.addSubview(titleLabel) contentView.addSubview(valueLabel) - titleLabel.setContentHuggingPriority(500, forAxis: .Horizontal) - titleLabel.setContentCompressionResistancePriority(1000, forAxis: .Horizontal) + titleLabel.setContentHuggingPriority(500, for: .horizontal) + titleLabel.setContentCompressionResistancePriority(1000, for: .horizontal) // apply constant constraints - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .Height, relatedBy: .Equal, toItem: contentView, attribute: .Height, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) - contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .height, relatedBy: .equal, toItem: contentView, attribute: .height, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: titleLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) + contentView.addConstraint(NSLayoutConstraint(item: valueLabel, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0.0)) } - public override func constraintsViews() -> [String : UIView] { + open override func constraintsViews() -> [String : UIView] { return ["titleLabel" : titleLabel, "valueLabel" : valueLabel] } - public override func defaultVisualConstraints() -> [String] { + open override func defaultVisualConstraints() -> [String] { // apply default constraints var rightPadding = 0 - if accessoryType == .None { + if accessoryType == .none { rightPadding = 16 } @@ -67,4 +67,4 @@ public class FormValueCell: FormBaseCell { return ["H:|-16-[valueLabel]-\(rightPadding)-|"] } } -} \ No newline at end of file +} diff --git a/SwiftForms/controllers/FormOptionsViewController.swift b/SwiftForms/controllers/FormOptionsViewController.swift index 7cc61f6..1146359 100644 --- a/SwiftForms/controllers/FormOptionsViewController.swift +++ b/SwiftForms/controllers/FormOptionsViewController.swift @@ -8,72 +8,72 @@ import UIKit -public class FormOptionsSelectorController: UITableViewController, FormSelector { +open class FormOptionsSelectorController: UITableViewController, FormSelector { // MARK: FormSelector - public var formCell: FormBaseCell? + open var formCell: FormBaseCell? // MARK: Init public init() { - super.init(style: .Grouped) + super.init(style: .grouped) } public required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder)! } - override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } - public override func viewDidLoad() { + open override func viewDidLoad() { super.viewDidLoad() self.navigationItem.title = formCell?.rowDescriptor?.title } // MARK: UITableViewDataSource - public override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + open override func numberOfSections(in tableView: UITableView) -> Int { return 1 } - public override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - guard let options = formCell?.rowDescriptor?.configuration.selection.options where !options.isEmpty else { return 0 } + open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + guard let options = formCell?.rowDescriptor?.configuration.selection.options , !options.isEmpty else { return 0 } return options.count } - public override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + open override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return 0.1 } - public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let reuseIdentifier = NSStringFromClass(self.dynamicType) + let reuseIdentifier = NSStringFromClass(type(of: self)) - var cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) + var cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier) if cell == nil { - cell = UITableViewCell(style: .Default, reuseIdentifier: reuseIdentifier) + cell = UITableViewCell(style: .default, reuseIdentifier: reuseIdentifier) } let options = formCell!.rowDescriptor!.configuration.selection.options - let optionValue = options[indexPath.row] + let optionValue = options[(indexPath as NSIndexPath).row] cell?.textLabel?.text = formCell?.rowDescriptor?.configuration.selection.optionTitleClosure?(optionValue) if let selectedOptions = formCell?.rowDescriptor?.value as? [AnyObject] { - if let _ = selectedOptions.indexOf({ $0 === optionValue }) { - cell?.accessoryType = .Checkmark + if let _ = selectedOptions.index(where: { $0 === optionValue }) { + cell?.accessoryType = .checkmark } else { - cell?.accessoryType = .None + cell?.accessoryType = .none } } else if let selectedOption = formCell?.rowDescriptor?.value { if optionValue === selectedOption { - cell?.accessoryType = .Checkmark + cell?.accessoryType = .checkmark } else { - cell?.accessoryType = .None + cell?.accessoryType = .none } } @@ -82,9 +82,9 @@ public class FormOptionsSelectorController: UITableViewController, FormSelector // MARK: UITableViewDelegate - public override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + open override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - let cell = tableView.cellForRowAtIndexPath(indexPath) + let cell = tableView.cellForRow(at: indexPath) var allowsMultipleSelection = false if let allowsMultipleSelectionValue = formCell?.rowDescriptor?.configuration.selection.allowsMultipleSelection { @@ -92,22 +92,22 @@ public class FormOptionsSelectorController: UITableViewController, FormSelector } let options = formCell!.rowDescriptor!.configuration.selection.options - let selectedOption = options[indexPath.row] + let selectedOption = options[(indexPath as NSIndexPath).row] if allowsMultipleSelection { if var selectedOptions = formCell?.rowDescriptor?.value as? [AnyObject] { - if let index = selectedOptions.indexOf({ $0 === selectedOption }) { - selectedOptions.removeAtIndex(index) - cell?.accessoryType = .None + if let index = selectedOptions.index(where: { $0 === selectedOption }) { + selectedOptions.remove(at: index) + cell?.accessoryType = .none } else { selectedOptions.append(selectedOption) - cell?.accessoryType = .Checkmark + cell?.accessoryType = .checkmark } - formCell?.rowDescriptor?.value = selectedOptions + formCell?.rowDescriptor?.value = selectedOptions as AnyObject } else { - formCell?.rowDescriptor?.value = [AnyObject](arrayLiteral: selectedOption) - cell?.accessoryType = .Checkmark + formCell?.rowDescriptor?.value = [AnyObject](arrayLiteral: selectedOption) as AnyObject + cell?.accessoryType = .checkmark } } else { @@ -117,9 +117,9 @@ public class FormOptionsSelectorController: UITableViewController, FormSelector formCell?.update() if allowsMultipleSelection { - tableView.deselectRowAtIndexPath(indexPath, animated: true) + tableView.deselectRow(at: indexPath, animated: true) } else { - self.navigationController?.popViewControllerAnimated(true) + let _ = self.navigationController?.popViewController(animated: true) } } } diff --git a/SwiftForms/controllers/FormViewController.swift b/SwiftForms/controllers/FormViewController.swift index 0ab5bc5..79c488e 100644 --- a/SwiftForms/controllers/FormViewController.swift +++ b/SwiftForms/controllers/FormViewController.swift @@ -8,25 +8,53 @@ import UIKit -public class FormViewController : UITableViewController { +open class FormViewController : UITableViewController { + + private static var __once: () = { + FormViewController.defaultCellClasses[.text] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.label] = FormLabelCell.self + FormViewController.defaultCellClasses[.number] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.numbersAndPunctuation] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.decimal] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.name] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.phone] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.url] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.twitter] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.namePhone] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.email] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.asciiCapable] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.password] = FormTextFieldCell.self + FormViewController.defaultCellClasses[.button] = FormButtonCell.self + FormViewController.defaultCellClasses[.booleanSwitch] = FormSwitchCell.self + FormViewController.defaultCellClasses[.booleanCheck] = FormCheckCell.self + FormViewController.defaultCellClasses[.segmentedControl] = FormSegmentedControlCell.self + FormViewController.defaultCellClasses[.picker] = FormPickerCell.self + FormViewController.defaultCellClasses[.date] = FormDateCell.self + FormViewController.defaultCellClasses[.time] = FormDateCell.self + FormViewController.defaultCellClasses[.dateAndTime] = FormDateCell.self + FormViewController.defaultCellClasses[.stepper] = FormStepperCell.self + FormViewController.defaultCellClasses[.slider] = FormSliderCell.self + FormViewController.defaultCellClasses[.multipleSelector] = FormSelectorCell.self + FormViewController.defaultCellClasses[.multilineText] = FormTextViewCell.self + }() // MARK: Class variables - private static var onceDefaultCellClass: dispatch_once_t = 0 - private static var defaultCellClasses: [FormRowDescriptor.RowType : FormBaseCell.Type] = [:] + fileprivate static var onceDefaultCellClass: Int = 0 + fileprivate static var defaultCellClasses: [FormRowDescriptor.RowType : FormBaseCell.Type] = [:] // MARK: Properties - public var form = FormDescriptor() + open var form = FormDescriptor() // MARK: Init public convenience init() { - self.init(style: .Grouped) + self.init(style: .grouped) } public convenience init(form: FormDescriptor) { - self.init(style: .Grouped) + self.init(style: .grouped) self.form = form } @@ -34,7 +62,7 @@ public class FormViewController : UITableViewController { super.init(style: style) } - public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { + public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil) } @@ -44,14 +72,14 @@ public class FormViewController : UITableViewController { // MARK: View life cycle - public override func viewDidLoad() { + open override func viewDidLoad() { super.viewDidLoad() navigationItem.title = form.title } // MARK: Public interface - public func valueForTag(tag: String) -> AnyObject? { + open func valueForTag(_ tag: String) -> AnyObject? { for section in form.sections { for row in section.rows { if row.tag == tag { @@ -62,12 +90,12 @@ public class FormViewController : UITableViewController { return nil } - public func setValue(value: AnyObject, forTag tag: String) { - for (sectionIndex, section) in form.sections.enumerate() { - for (rowIndex, row) in section.rows.enumerate() { + open func setValue(_ value: AnyObject, forTag tag: String) { + for (sectionIndex, section) in form.sections.enumerated() { + for (rowIndex, row) in section.rows.enumerated() { if row.tag == tag { form.sections[sectionIndex].rows[rowIndex].value = value - if let cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: rowIndex, inSection: sectionIndex)) as? FormBaseCell { + if let cell = self.tableView.cellForRow(at: IndexPath(row: rowIndex, section: sectionIndex)) as? FormBaseCell { cell.update() } return @@ -78,25 +106,25 @@ public class FormViewController : UITableViewController { // MARK: UITableViewDataSource - public override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + open override func numberOfSections(in tableView: UITableView) -> Int { return form.sections.count } - public override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + open override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return form.sections[section].rows.count } - public override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let rowDescriptor = formRowDescriptorAtIndexPath(indexPath) let formBaseCellClass = formBaseCellClassFromRowDescriptor(rowDescriptor) - let reuseIdentifier = NSStringFromClass(formBaseCellClass) + let reuseIdentifier = NSStringFromClass(formBaseCellClass!) - var cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier) as? FormBaseCell + var cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier) as? FormBaseCell if cell == nil { - cell = formBaseCellClass.init(style: .Default, reuseIdentifier: reuseIdentifier) + cell = formBaseCellClass?.init(style: .default, reuseIdentifier: reuseIdentifier) cell?.formViewController = self cell?.configure() } @@ -110,33 +138,33 @@ public class FormViewController : UITableViewController { return cell! } - public override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + open override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { return form.sections[section].headerTitle } - public override func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? { + open override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? { return form.sections[section].footerTitle } - public override func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { + open override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { guard let headerView = form.sections[section].headerView else { return nil } return headerView } - public override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { + open override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { guard let footerView = form.sections[section].footerView else { return nil } return footerView } - public override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { - guard let headerView = form.sections[section].headerView where headerView.translatesAutoresizingMaskIntoConstraints else { + open override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { + guard let headerView = form.sections[section].headerView , headerView.translatesAutoresizingMaskIntoConstraints else { return form.sections[section].headerViewHeight } return headerView.frame.size.height } - public override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { - guard let footerView = form.sections[section].footerView where footerView.translatesAutoresizingMaskIntoConstraints else { + open override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { + guard let footerView = form.sections[section].footerView , footerView.translatesAutoresizingMaskIntoConstraints else { return form.sections[section].footerViewHeight } return footerView.frame.size.height @@ -144,21 +172,21 @@ public class FormViewController : UITableViewController { // MARK: UITableViewDelegate - public override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { + open override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { let rowDescriptor = formRowDescriptorAtIndexPath(indexPath) if let formBaseCellClass = formBaseCellClassFromRowDescriptor(rowDescriptor) { return formBaseCellClass.formRowCellHeight() } - return super.tableView(tableView, heightForRowAtIndexPath: indexPath) + return super.tableView(tableView, heightForRowAt: indexPath) } - public override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + open override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let rowDescriptor = formRowDescriptorAtIndexPath(indexPath) - if let selectedRow = tableView.cellForRowAtIndexPath(indexPath) as? FormBaseCell { + if let selectedRow = tableView.cellForRow(at: indexPath) as? FormBaseCell { if let formBaseCellClass = formBaseCellClassFromRowDescriptor(rowDescriptor) { formBaseCellClass.formViewController(self, didSelectRow: selectedRow) } @@ -168,48 +196,22 @@ public class FormViewController : UITableViewController { didSelectClosure(rowDescriptor) } - tableView.deselectRowAtIndexPath(indexPath, animated: true) - } - - private class func defaultCellClassForRowType(rowType: FormRowDescriptor.RowType) -> FormBaseCell.Type { - dispatch_once(&FormViewController.onceDefaultCellClass) { - FormViewController.defaultCellClasses[.Text] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Label] = FormLabelCell.self - FormViewController.defaultCellClasses[.Number] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.NumbersAndPunctuation] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Decimal] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Name] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Phone] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.URL] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Twitter] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.NamePhone] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Email] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.ASCIICapable] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Password] = FormTextFieldCell.self - FormViewController.defaultCellClasses[.Button] = FormButtonCell.self - FormViewController.defaultCellClasses[.BooleanSwitch] = FormSwitchCell.self - FormViewController.defaultCellClasses[.BooleanCheck] = FormCheckCell.self - FormViewController.defaultCellClasses[.SegmentedControl] = FormSegmentedControlCell.self - FormViewController.defaultCellClasses[.Picker] = FormPickerCell.self - FormViewController.defaultCellClasses[.Date] = FormDateCell.self - FormViewController.defaultCellClasses[.Time] = FormDateCell.self - FormViewController.defaultCellClasses[.DateAndTime] = FormDateCell.self - FormViewController.defaultCellClasses[.Stepper] = FormStepperCell.self - FormViewController.defaultCellClasses[.Slider] = FormSliderCell.self - FormViewController.defaultCellClasses[.MultipleSelector] = FormSelectorCell.self - FormViewController.defaultCellClasses[.MultilineText] = FormTextViewCell.self - } + tableView.deselectRow(at: indexPath, animated: true) + } + + fileprivate class func defaultCellClassForRowType(_ rowType: FormRowDescriptor.RowType) -> FormBaseCell.Type { + _ = FormViewController.__once return FormViewController.defaultCellClasses[rowType]! } - private func formRowDescriptorAtIndexPath(indexPath: NSIndexPath) -> FormRowDescriptor { + fileprivate func formRowDescriptorAtIndexPath(_ indexPath: IndexPath) -> FormRowDescriptor { - let section = form.sections[indexPath.section] - let rowDescriptor = section.rows[indexPath.row] + let section = form.sections[(indexPath as NSIndexPath).section] + let rowDescriptor = section.rows[(indexPath as NSIndexPath).row] return rowDescriptor } - private func formBaseCellClassFromRowDescriptor(rowDescriptor: FormRowDescriptor) -> FormBaseCell.Type! { + fileprivate func formBaseCellClassFromRowDescriptor(_ rowDescriptor: FormRowDescriptor) -> FormBaseCell.Type! { var formBaseCellClass: FormBaseCell.Type diff --git a/SwiftForms/descriptors/FormDescriptor.swift b/SwiftForms/descriptors/FormDescriptor.swift index b9b1006..fbe7980 100644 --- a/SwiftForms/descriptors/FormDescriptor.swift +++ b/SwiftForms/descriptors/FormDescriptor.swift @@ -33,7 +33,7 @@ public final class FormDescriptor { for section in sections { for row in section.rows { - if row.type != .Button { + if row.type != .button { if let value = row.value { formValues[row.tag] = value } else { diff --git a/SwiftForms/descriptors/FormRowDescriptor.swift b/SwiftForms/descriptors/FormRowDescriptor.swift index 418ebf4..9760ca3 100644 --- a/SwiftForms/descriptors/FormRowDescriptor.swift +++ b/SwiftForms/descriptors/FormRowDescriptor.swift @@ -13,32 +13,32 @@ public final class FormRowDescriptor { // MARK: Types public enum RowType { - case Unknown - case Label - case Text - case URL - case Number - case NumbersAndPunctuation - case Decimal - case Name - case Phone - case NamePhone - case Email - case Twitter - case ASCIICapable - case Password - case Button - case BooleanSwitch - case BooleanCheck - case SegmentedControl - case Picker - case Date - case Time - case DateAndTime - case Stepper - case Slider - case MultipleSelector - case MultilineText + case unknown + case label + case text + case url + case number + case numbersAndPunctuation + case decimal + case name + case phone + case namePhone + case email + case twitter + case asciiCapable + case password + case button + case booleanSwitch + case booleanCheck + case segmentedControl + case picker + case date + case time + case dateAndTime + case stepper + case slider + case multipleSelector + case multilineText } public struct CellConfiguration { @@ -100,7 +100,7 @@ public final class FormRowDescriptor { } public struct DateConfiguration { - public var dateFormatter: NSDateFormatter? + public var dateFormatter: DateFormatter? } public struct RowConfiguration { diff --git a/SwiftFormsApplication.xcodeproj/project.pbxproj b/SwiftFormsApplication.xcodeproj/project.pbxproj index 83bd272..c394a40 100644 --- a/SwiftFormsApplication.xcodeproj/project.pbxproj +++ b/SwiftFormsApplication.xcodeproj/project.pbxproj @@ -309,14 +309,16 @@ attributes = { LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0720; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Miguel Angel Ortuno Ortuno"; TargetAttributes = { 0CCA33D61B04FA5A006D9666 = { CreatedOnToolsVersion = 6.3.1; + LastSwiftMigration = 0800; }; 0CCA342B1B04FBDF006D9666 = { CreatedOnToolsVersion = 6.3.1; + LastSwiftMigration = 0800; }; }; }; @@ -434,8 +436,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -480,8 +484,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -500,6 +506,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -514,6 +521,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ortulabs.SwiftFormsApplication; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -526,12 +534,14 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.ortulabs.SwiftFormsApplication; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; 0CCA34461B04FBE0006D9666 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -548,6 +558,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.ortulabs.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -556,6 +567,7 @@ 0CCA34471B04FBE0006D9666 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -568,6 +580,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.ortulabs.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; diff --git a/SwiftFormsApplication.xcodeproj/xcshareddata/xcschemes/SwiftForms.xcscheme b/SwiftFormsApplication.xcodeproj/xcshareddata/xcschemes/SwiftForms.xcscheme index 09181f6..57f8f84 100644 --- a/SwiftFormsApplication.xcodeproj/xcshareddata/xcschemes/SwiftForms.xcscheme +++ b/SwiftFormsApplication.xcodeproj/xcshareddata/xcschemes/SwiftForms.xcscheme @@ -1,6 +1,6 @@ Bool { + private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : Any]?) -> Bool { return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { } } diff --git a/SwiftFormsApplication/ExampleFormViewController.swift b/SwiftFormsApplication/ExampleFormViewController.swift index 99d0aa1..4bcd5ea 100644 --- a/SwiftFormsApplication/ExampleFormViewController.swift +++ b/SwiftFormsApplication/ExampleFormViewController.swift @@ -38,7 +38,7 @@ class ExampleFormViewController: FormViewController { override func viewDidLoad() { super.viewDidLoad() - self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Submit", style: .Plain, target: self, action: #selector(ExampleFormViewController.submit(_:))) + self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Submit", style: .plain, target: self, action: #selector(ExampleFormViewController.submit(_:))) } // MARK: Actions @@ -47,66 +47,66 @@ class ExampleFormViewController: FormViewController { let message = self.form.formValues().description - let alertController = UIAlertController(title: "Form output", message: message, preferredStyle: .Alert) + let alertController = UIAlertController(title: "Form output", message: message, preferredStyle: .alert) - let cancel = UIAlertAction(title: "OK", style: .Cancel) { (action) in + let cancel = UIAlertAction(title: "OK", style: .cancel) { (action) in } alertController.addAction(cancel) - self.presentViewController(alertController, animated: true, completion: nil) + self.present(alertController, animated: true, completion: nil) } // MARK: Private interface - private func loadForm() { + fileprivate func loadForm() { let form = FormDescriptor(title: "Example Form") let section1 = FormSectionDescriptor(headerTitle: nil, footerTitle: nil) - var row = FormRowDescriptor(tag: Static.emailTag, type: .Email, title: "Email") - row.configuration.cell.appearance = ["textField.placeholder" : "john@gmail.com", "textField.textAlignment" : NSTextAlignment.Right.rawValue] + var row = FormRowDescriptor(tag: Static.emailTag, type: .email, title: "Email") + row.configuration.cell.appearance = ["textField.placeholder" : "john@gmail.com" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject] section1.rows.append(row) - row = FormRowDescriptor(tag: Static.passwordTag, type: .Password, title: "Password") - row.configuration.cell.appearance = ["textField.placeholder" : "Enter password", "textField.textAlignment" : NSTextAlignment.Right.rawValue] + row = FormRowDescriptor(tag: Static.passwordTag, type: .password, title: "Password") + row.configuration.cell.appearance = ["textField.placeholder" : "Enter password" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject] section1.rows.append(row) let section2 = FormSectionDescriptor(headerTitle: nil, footerTitle: nil) - row = FormRowDescriptor(tag: Static.nameTag, type: .Name, title: "First Name") - row.configuration.cell.appearance = ["textField.placeholder" : "e.g. Miguel Ángel", "textField.textAlignment" : NSTextAlignment.Right.rawValue] + row = FormRowDescriptor(tag: Static.nameTag, type: .name, title: "First Name") + row.configuration.cell.appearance = ["textField.placeholder" : "e.g. Miguel Ángel" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject] section2.rows.append(row) - row = FormRowDescriptor(tag: Static.lastNameTag, type: .Name, title: "Last Name") - row.configuration.cell.appearance = ["textField.placeholder" : "e.g. Ortuño", "textField.textAlignment" : NSTextAlignment.Right.rawValue] + row = FormRowDescriptor(tag: Static.lastNameTag, type: .name, title: "Last Name") + row.configuration.cell.appearance = ["textField.placeholder" : "e.g. Ortuño" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject] section2.rows.append(row) - row = FormRowDescriptor(tag: Static.jobTag, type: .Text, title: "Job") - row.configuration.cell.appearance = ["textField.placeholder" : "e.g. Entrepreneur", "textField.textAlignment" : NSTextAlignment.Right.rawValue] + row = FormRowDescriptor(tag: Static.jobTag, type: .text, title: "Job") + row.configuration.cell.appearance = ["textField.placeholder" : "e.g. Entrepreneur" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject] section2.rows.append(row) let section3 = FormSectionDescriptor(headerTitle: nil, footerTitle: nil) - row = FormRowDescriptor(tag: Static.URLTag, type: .URL, title: "URL") - row.configuration.cell.appearance = ["textField.placeholder" : "e.g. gethooksapp.com", "textField.textAlignment" : NSTextAlignment.Right.rawValue] + row = FormRowDescriptor(tag: Static.URLTag, type: .url, title: "URL") + row.configuration.cell.appearance = ["textField.placeholder" : "e.g. gethooksapp.com" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject] section3.rows.append(row) - row = FormRowDescriptor(tag: Static.phoneTag, type: .Phone, title: "Phone") - row.configuration.cell.appearance = ["textField.placeholder" : "e.g. 0034666777999", "textField.textAlignment" : NSTextAlignment.Right.rawValue] + row = FormRowDescriptor(tag: Static.phoneTag, type: .phone, title: "Phone") + row.configuration.cell.appearance = ["textField.placeholder" : "e.g. 0034666777999" as AnyObject, "textField.textAlignment" : NSTextAlignment.right.rawValue as AnyObject] section3.rows.append(row) let section4 = FormSectionDescriptor(headerTitle: "An example header title", footerTitle: "An example footer title") - row = FormRowDescriptor(tag: Static.enabled, type: .BooleanSwitch, title: "Enable") + row = FormRowDescriptor(tag: Static.enabled, type: .booleanSwitch, title: "Enable") section4.rows.append(row) - row = FormRowDescriptor(tag: Static.check, type: .BooleanCheck, title: "Doable") + row = FormRowDescriptor(tag: Static.check, type: .booleanCheck, title: "Doable") section4.rows.append(row) - row = FormRowDescriptor(tag: Static.segmented, type: .SegmentedControl, title: "Priority") - row.configuration.selection.options = [0, 1, 2, 3] + row = FormRowDescriptor(tag: Static.segmented, type: .segmentedControl, title: "Priority") + row.configuration.selection.options = ([0, 1, 2, 3] as [Int]) as [AnyObject] row.configuration.selection.optionTitleClosure = { value in guard let option = value as? Int else { return "" } switch option { @@ -123,15 +123,15 @@ class ExampleFormViewController: FormViewController { } } - row.configuration.cell.appearance = ["titleLabel.font" : UIFont.boldSystemFontOfSize(30.0), "segmentedControl.tintColor" : UIColor.redColor()] + row.configuration.cell.appearance = ["titleLabel.font" : UIFont.boldSystemFont(ofSize: 30.0), "segmentedControl.tintColor" : UIColor.red] section4.rows.append(row) let section5 = FormSectionDescriptor(headerTitle: nil, footerTitle: nil) - row = FormRowDescriptor(tag: Static.picker, type: .Picker, title: "Gender") + row = FormRowDescriptor(tag: Static.picker, type: .picker, title: "Gender") row.configuration.cell.showsInputToolbar = true - row.configuration.selection.options = ["F", "M", "U"] + row.configuration.selection.options = (["F", "M", "U"] as [String]) as [AnyObject] row.configuration.selection.optionTitleClosure = { value in guard let option = value as? String else { return "" } switch option { @@ -146,16 +146,16 @@ class ExampleFormViewController: FormViewController { } } - row.value = "M" + row.value = "M" as AnyObject section5.rows.append(row) - row = FormRowDescriptor(tag: Static.birthday, type: .Date, title: "Birthday") + row = FormRowDescriptor(tag: Static.birthday, type: .date, title: "Birthday") row.configuration.cell.showsInputToolbar = true section5.rows.append(row) - row = FormRowDescriptor(tag: Static.categories, type: .MultipleSelector, title: "Categories") - row.configuration.selection.options = [0, 1, 2, 3, 4] + row = FormRowDescriptor(tag: Static.categories, type: .multipleSelector, title: "Categories") + row.configuration.selection.options = ([0, 1, 2, 3, 4] as [Int]) as [AnyObject] row.configuration.selection.allowsMultipleSelection = true row.configuration.selection.optionTitleClosure = { value in guard let option = value as? Int else { return "" } @@ -179,26 +179,26 @@ class ExampleFormViewController: FormViewController { let section6 = FormSectionDescriptor(headerTitle: "Stepper & Slider", footerTitle: nil) - row = FormRowDescriptor(tag: Static.stepper, type: .Stepper, title: "Step count") + row = FormRowDescriptor(tag: Static.stepper, type: .stepper, title: "Step count") row.configuration.stepper.maximumValue = 200.0 row.configuration.stepper.minimumValue = 20.0 row.configuration.stepper.steps = 2.0 section6.rows.append(row) - row = FormRowDescriptor(tag: Static.slider, type: .Slider, title: "Slider") + row = FormRowDescriptor(tag: Static.slider, type: .slider, title: "Slider") row.configuration.stepper.maximumValue = 200.0 row.configuration.stepper.minimumValue = 20.0 row.configuration.stepper.steps = 2.0 - row.value = 0.5 + row.value = 0.5 as AnyObject section6.rows.append(row) let section7 = FormSectionDescriptor(headerTitle: "Multiline TextView", footerTitle: nil) - row = FormRowDescriptor(tag: Static.textView, type: .MultilineText, title: "Notes") + row = FormRowDescriptor(tag: Static.textView, type: .multilineText, title: "Notes") section7.rows.append(row) let section8 = FormSectionDescriptor(headerTitle: nil, footerTitle: nil) - row = FormRowDescriptor(tag: Static.button, type: .Button, title: "Dismiss") + row = FormRowDescriptor(tag: Static.button, type: .button, title: "Dismiss") row.configuration.button.didSelectClosure = { _ in self.view.endEditing(true) }