Skip to content
This repository has been archived by the owner on Apr 19, 2021. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/Swift3'
Browse files Browse the repository at this point in the history
  • Loading branch information
ortuman committed Sep 14, 2016
2 parents d53a371 + 0bc86a4 commit b569bf2
Show file tree
Hide file tree
Showing 26 changed files with 469 additions and 454 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

[![Version](https://img.shields.io/badge/pod-1.6.3-green.svg)](http://cocoadocs.org/docsets/SwiftForms)
[![Version](https://img.shields.io/badge/pod-1.7-green.svg)](http://cocoadocs.org/docsets/SwiftForms)
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)

[![License](https://img.shields.io/badge/license-MIT-gray.svg)](http://cocoadocs.org/docsets/SwiftForms)
Expand Down
4 changes: 2 additions & 2 deletions SwiftForms.podspec
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Pod::Spec.new do |s|
s.name = "SwiftForms"
s.version = "1.6.3"
s.version = "1.7"
s.summary = "A small and lightweight library written in Swift that allows you to easily create forms"
s.homepage = "https://github.com/ortuman/SwiftForms"
s.license = { :type => "MIT", :file => "LICENSE" }
s.authors = "Miguel Ángel Ortuño"
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/ortuman/SwiftForms.git", :tag => '1.6.3' }
s.source = { :git => "https://github.com/ortuman/SwiftForms.git", :tag => '1.7' }
s.source_files = 'SwiftForms/*.swift','SwiftForms/descriptors/*.swift', 'SwiftForms/cells/base/*.swift', 'SwiftForms/cells/*.swift', 'SwiftForms/controllers/*.swift'
end
6 changes: 3 additions & 3 deletions SwiftForms/FormErrorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 4 additions & 4 deletions SwiftForms/cells/FormButtonCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 10 additions & 10 deletions SwiftForms/cells/FormCheckCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,28 +28,28 @@ 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
}
else {
newValue = true
}
rowDescriptor?.value = newValue
rowDescriptor?.value = newValue as AnyObject
update()
}
}
64 changes: 32 additions & 32 deletions SwiftForms/cells/FormDateCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,89 +8,89 @@

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()
}

titleLabel.text = rowDescriptor?.title

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
}
Expand Down
22 changes: 11 additions & 11 deletions SwiftForms/cells/FormLabelCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
36 changes: 18 additions & 18 deletions SwiftForms/cells/FormPickerCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,21 +28,21 @@ 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()
}

titleLabel.text = rowDescriptor?.title

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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit b569bf2

Please sign in to comment.