Skip to content

Commit beb2459

Browse files
committed
release(0.5.0): migrated to swiftpm / sbPickerSelector Swift
1 parent 0c834c1 commit beb2459

14 files changed

+524
-47
lines changed

Package.resolved

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// swift-tools-version:5.3
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "iOSFormUtils",
8+
platforms: [
9+
.iOS(.v10)
10+
],
11+
products: [
12+
// Products define the executables and libraries a package produces, and make them visible to other packages.
13+
.library(
14+
name: "iOSFormUtils",
15+
targets: ["iOSFormUtils"]),
16+
],
17+
dependencies: [
18+
// Dependencies declare other packages that this package depends on.
19+
.package(url: "https://github.com/code-troopers/UIKitExtensions", .upToNextMajor(from: "0.3.0")),
20+
.package(url: "https://github.com/SnapKit/SnapKit.git", .upToNextMajor(from: "5.0.1"))
21+
],
22+
targets: [
23+
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
24+
// Targets can depend on other targets in this package, and on products in packages this package depends on.
25+
.target(
26+
name: "iOSFormUtils",
27+
dependencies: ["UIKitExtensions", "SnapKit"]),
28+
]
29+
)

iOSFormUtils/DateDropDown.swift renamed to Sources/iOSFormUtils/DateDropDown.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ open class DateDropDown: DropDown {
3636

3737
override open func loadView() {
3838
super.loadView()
39-
40-
picker.pickerType = .date
39+
picker = SBPickerSwiftSelector(mode: .dateDefault)
40+
/*
41+
picker.pickerType = .date
4142
picker.onlyDayPicker = true
4243
picker.datePickerType = .onlyDay
44+
*/
4345
}
4446
}

iOSFormUtils/DropDown.swift renamed to Sources/iOSFormUtils/DropDown.swift

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
import Foundation
10-
import SBPickerSelector
1110
import UIKit
1211
import UIKitExtensions
1312
import SnapKit
@@ -46,7 +45,7 @@ open class DropDown: OwnView {
4645
}
4746
public var dataSource: DropDownDataSource!
4847

49-
var picker: SBPickerSelector = SBPickerSelector.picker()
48+
var picker: SBPickerSwiftSelector? //FIXME CG = SBPickerSwiftSelector.picker()
5049
var values: [String]!
5150
var currentTextField: TextInput!
5251
public var selectedIndex: Int!
@@ -63,7 +62,7 @@ open class DropDown: OwnView {
6362
self.addSubview(self.titleTextField)
6463

6564
rightIcon = UIImageView(frame: CGRect())
66-
rightIcon.contentMode = UIViewContentMode.center
65+
rightIcon.contentMode = UIView.ContentMode.center
6766
self.addSubview(rightIcon)
6867

6968
mainButton = UIButton(type: .custom)
@@ -88,12 +87,11 @@ open class DropDown: OwnView {
8887
self.layoutIfNeeded()
8988
self.layoutSubviews()
9089

91-
picker.delegate = self
92-
picker.pickerType = SBPickerSelectorType.text
93-
picker.doneButtonTitle = "OK"
94-
picker.doneButton?.tintColor = mainColor
95-
picker.cancelButtonTitle = "Annuler"
96-
picker.cancelButton?.tintColor = mainColor
90+
picker = SBPickerSwiftSelector(mode: .text)
91+
picker?.doneButton?.title = "OK"
92+
picker?.doneButton?.tintColor = mainColor
93+
picker?.cancelButton?.title = "Annuler"
94+
picker?.cancelButton?.tintColor = mainColor
9795

9896
updateUI()
9997

@@ -109,8 +107,8 @@ open class DropDown: OwnView {
109107

110108
func updateUI() {
111109
if let _ = dataSource, let _ = uiDataSource {
112-
picker.doneButton?.tintColor = uiDataSource.getButtonsColor()
113-
picker.cancelButton?.tintColor = uiDataSource.getButtonsColor()
110+
picker?.doneButton?.tintColor = uiDataSource.getButtonsColor()
111+
picker?.cancelButton?.tintColor = uiDataSource.getButtonsColor()
114112

115113
if let existingPlaceholder = dataSource.placeholderKeyForDropDown(self) {
116114
updatePlaceholderWithValue(existingPlaceholder)
@@ -126,18 +124,18 @@ open class DropDown: OwnView {
126124
titleTextField.attributedPlaceholder = NSAttributedString(
127125
string: value,
128126
attributes: [
129-
NSForegroundColorAttributeName: self.uiDataSource.getPlaceholderColor(),
130-
NSFontAttributeName: UIFont(name: self.uiDataSource.getFontName(), size: self.uiDataSource.getFontSize())!
127+
NSAttributedString.Key.foregroundColor: self.uiDataSource.getPlaceholderColor(),
128+
NSAttributedString.Key.font: UIFont(name: self.uiDataSource.getFontName(), size: self.uiDataSource.getFontSize())!
131129
]
132130
)
133131
}
134132

135133
func updateSelectedIndex(_ newIndex: Int) {
136134
selectedIndex = newIndex
137-
picker.pickerView.selectRow(selectedIndex, inComponent: 0, animated: true)
138-
if let data: [String] = picker.pickerData as? [String] {
135+
picker?.pickerView.selectRow(selectedIndex, inComponent: 0, animated: true)
136+
if let data: [String] = picker?.data as? [String] {
139137
pickerSelector(picker, selectedValue: data[selectedIndex], index: selectedIndex)
140-
picker.pickerView(picker.pickerView, didSelectRow: selectedIndex, inComponent: 0)
138+
picker!.pickerView.delegate?.pickerView?(picker!.pickerView, didSelectRow: selectedIndex, inComponent: 0)
141139
}
142140
}
143141

@@ -155,7 +153,7 @@ open class DropDown: OwnView {
155153
offset = 1
156154
}
157155

158-
picker.pickerData = values
156+
picker?.data = values
159157
if let dataSourceSelectedIndex: Int = itsDataSource.selectedIndexForDropDown(self) {
160158
updateSelectedIndex(dataSourceSelectedIndex + offset)
161159
}
@@ -167,15 +165,15 @@ open class DropDown: OwnView {
167165
if let textField = currentTextField {
168166
textField.resignFirstResponder()
169167
}
170-
picker.showPickerOver(itsDataSource.controllerForDropDownDisplaying(self))
168+
picker?.present(into: itsDataSource.controllerForDropDownDisplaying(self))
171169
}
172170
}
173171

174-
func mainButtonTouched(_ sender: AnyObject) {
172+
@objc func mainButtonTouched(_ sender: AnyObject) {
175173
presentDropDown()
176174
}
177175

178-
func textFieldBecameFirstResponder(_ notification: Notification) {
176+
@objc func textFieldBecameFirstResponder(_ notification: Notification) {
179177
if let textField: TextInput = notification.object as? TextInput {
180178
if textField != titleTextField {
181179
currentTextField = textField
@@ -186,8 +184,8 @@ open class DropDown: OwnView {
186184
}
187185
}
188186

189-
extension DropDown: SBPickerSelectorDelegate {
190-
public func pickerSelector(_ selector: SBPickerSelector!, selectedValue value: String!, index idx: Int) {
187+
extension DropDown /*: SBPickerSelectorDelegate */{
188+
public func pickerSelector(_ selector: SBPickerSwiftSelector!, selectedValue value: String!, index idx: Int) {
191189
let required = (nil != dataSource && !dataSource.isRequired(self))
192190
var offset = 0
193191
if (required && 0 != idx) || !required {
@@ -212,8 +210,8 @@ extension DropDown: SBPickerSelectorDelegate {
212210
}
213211
}
214212

215-
public func pickerSelector(_ selector: SBPickerSelector!, dateSelected date: Date!) {
216-
if .date == picker.pickerType {
213+
public func pickerSelector(_ selector: SBPickerSwiftSelector!, dateSelected date: Date!) {
214+
if SBPickerSwiftSelector.Mode.dateDefault == picker?.pickerMode {
217215
if let _ = date {
218216
let dateFormatter = DateFormatter()
219217
dateFormatter.dateFormat = self.dateFormat

iOSFormUtils/Form.swift renamed to Sources/iOSFormUtils/Form.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ open class Form: UIScrollView {
9999
NotificationCenter.default.addObserver(
100100
self,
101101
selector: #selector(Form.keyboardShown(_:)),
102-
name: NSNotification.Name.UIKeyboardDidShow,
102+
name: UIResponder.keyboardDidShowNotification,
103103
object: nil
104104
)
105105

106106
NotificationCenter.default.addObserver(
107107
self,
108108
selector: #selector(Form.keyboardHidden(_:)),
109-
name: NSNotification.Name.UIKeyboardDidHide,
109+
name: UIResponder.keyboardDidHideNotification,
110110
object: nil
111111
)
112112

@@ -204,7 +204,7 @@ open class Form: UIScrollView {
204204

205205
- Parameter notification: the received notification.
206206
*/
207-
func textFieldReturnedFired(_ notification: Notification) {
207+
@objc func textFieldReturnedFired(_ notification: Notification) {
208208
if let textfield = notification.object as? TextInput {
209209
if isLastInput(textfield) {
210210
textfield.stopEditing()
@@ -225,7 +225,7 @@ open class Form: UIScrollView {
225225

226226
- Parameter notification: the received notification.
227227
*/
228-
func textFieldResignedFirstResponderFired(_ notification: Notification) {
228+
@objc func textFieldResignedFirstResponderFired(_ notification: Notification) {
229229
resetScrollingZone()
230230
}
231231

@@ -234,9 +234,9 @@ open class Form: UIScrollView {
234234

235235
- Parameter notification: the received notification
236236
*/
237-
func keyboardShown(_ notification: Notification) {
237+
@objc func keyboardShown(_ notification: Notification) {
238238
let info = (notification as NSNotification).userInfo!
239-
let value: AnyObject = info[UIKeyboardFrameEndUserInfoKey]! as AnyObject
239+
let value: AnyObject = info[UIResponder.keyboardFrameEndUserInfoKey]! as AnyObject
240240

241241
let rawFrame = value.cgRectValue
242242
let keyboardFrame = self.convert(rawFrame!, from: nil)
@@ -248,7 +248,7 @@ open class Form: UIScrollView {
248248
}
249249
}
250250

251-
func keyboardHidden(_ notification: Notification) {
251+
@objc func keyboardHidden(_ notification: Notification) {
252252
resetScrollingZone()
253253
}
254254

@@ -257,7 +257,7 @@ open class Form: UIScrollView {
257257

258258
- Parameter notification: the received notification
259259
*/
260-
func textFieldBecameFirstResponder(_ notification: Notification) {
260+
@objc func textFieldBecameFirstResponder(_ notification: Notification) {
261261
if let textfield = notification.object as? TextInput {
262262
currentInput = textfield
263263
}

iOSFormUtils/ImagePicker.swift renamed to Sources/iOSFormUtils/ImagePicker.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class ImagePicker: UIButton {
7272
}
7373
}
7474

75-
func selfTouched(_ sender: Any) {
75+
@objc func selfTouched(_ sender: Any) {
7676
if let _ = dataSource {
7777
dataSource.controllerForDisplaying().present(actionSheet, animated: true)
7878
} else {
@@ -82,8 +82,8 @@ public class ImagePicker: UIButton {
8282
}
8383

8484
extension ImagePicker: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
85-
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
86-
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
85+
public func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
86+
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
8787
if let _ = delegate {
8888
self.selectedImage = pickedImage
8989
delegate.imagePicker(self, selectedImage: pickedImage)

iOSFormUtils/TextInput.swift renamed to Sources/iOSFormUtils/TextInput.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Created by Nicolas LELOUP on 18/09/2015.
66
// Copyright © 2015 Nicolas LELOUP - Buzznative. All rights reserved.
77
//
8+
import UIKit
89

910
// MARK: Constants
1011
let tfBecameFirstResponderNotifName = "textFieldBecameFirstResponder"
@@ -105,7 +106,7 @@ extension TextInput: UITextFieldDelegate {
105106

106107
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
107108
if let _ = limit, "" != string {
108-
return textField.text!.characters.count < limit
109+
return textField.text!.count < limit
109110
}
110111

111112
return true

iOSFormUtils/ValidatedTextInput.swift renamed to Sources/iOSFormUtils/ValidatedTextInput.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension TextInput: ValidatedTextInput {
6767
if let _ = validationDataSource {
6868
switch validationDataSource.validationTypeForInput(self) {
6969
case .NotBlank :
70-
if (0 < self.text!.characters.count) {
70+
if (0 < self.text!.count) {
7171
return true
7272
}
7373
case .Email :

0 commit comments

Comments
 (0)