@@ -24,7 +24,7 @@ public protocol FormDelegate {
2424
2525 - Return: The first input.
2626 */
27- func getFirstInput( form: Form ) -> FormInput
27+ func getFirstInput( _ form: Form ) -> FormInput
2828
2929 /*
3030 Returns the following input of a form input
@@ -34,12 +34,12 @@ public protocol FormDelegate {
3434
3535 - Return: If the current input is the last one, nil. If not, the following input.
3636 */
37- func getNextInput( form: Form , currentInput: FormInput ) -> FormInput ?
37+ func getNextInput( _ form: Form , currentInput: FormInput ) -> FormInput ?
3838}
3939
4040// MARK: Class
4141/// UIScrollView child class for forms handling
42- public class Form : UIScrollView {
42+ open class Form : UIScrollView {
4343 // MARK: Class properties
4444 /// The original frame of the form
4545 var originalFrame : CGRect !
@@ -51,10 +51,10 @@ public class Form: UIScrollView {
5151 var keyboardViewHeight : CGFloat = 216
5252
5353 /// The stored delegate
54- public var formDelegate : FormDelegate !
54+ open var formDelegate : FormDelegate !
5555
5656 /// The current input which has been focused
57- private var currentInput : FormInput ! {
57+ fileprivate var currentInput : FormInput ! {
5858 didSet {
5959 handleInputsReturnKeys ( )
6060 }
@@ -71,7 +71,7 @@ public class Form: UIScrollView {
7171 commonInit ( )
7272 }
7373
74- override public func addSubview( view: UIView ) {
74+ override open func addSubview( _ view: UIView ) {
7575 super. addSubview ( view)
7676
7777 if let input: FormInput = view as? FormInput {
@@ -84,25 +84,25 @@ public class Form: UIScrollView {
8484 /**
8585 Custom initializer
8686 */
87- private func commonInit( ) {
88- NSNotificationCenter . defaultCenter ( ) . addObserver (
87+ fileprivate func commonInit( ) {
88+ NotificationCenter . default . addObserver (
8989 self ,
9090 selector: #selector( Form . keyboardShown ( _: ) ) ,
91- name: UIKeyboardDidShowNotification ,
91+ name: NSNotification . Name . UIKeyboardDidShow ,
9292 object: nil
9393 )
9494
95- NSNotificationCenter . defaultCenter ( ) . addObserver (
95+ NotificationCenter . default . addObserver (
9696 self ,
9797 selector: #selector( Form . textFieldReturnedFired ( _: ) ) ,
98- name: tfReturnedNotifName,
98+ name: NSNotification . Name ( rawValue : tfReturnedNotifName) ,
9999 object: nil
100100 )
101101
102- NSNotificationCenter . defaultCenter ( ) . addObserver (
102+ NotificationCenter . default . addObserver (
103103 self ,
104104 selector: #selector( Form . textFieldBecameFirstResponder ( _: ) ) ,
105- name: tfBecameFirstResponderNotifName,
105+ name: NSNotification . Name ( rawValue : tfBecameFirstResponderNotifName) ,
106106 object: nil
107107 )
108108 if let _ = formDelegate {
@@ -113,14 +113,14 @@ public class Form: UIScrollView {
113113 /**
114114 Handles return keys type for inputs
115115 */
116- private func handleInputsReturnKeys( ) {
116+ fileprivate func handleInputsReturnKeys( ) {
117117 let inputs = getOrderedInputs ( )
118118 for input in inputs {
119119 if let textField: UITextField = input as? UITextField {
120120 if textField == inputs. last as? UITextField {
121- textField. returnKeyType = . Go
121+ textField. returnKeyType = . go
122122 } else {
123- textField. returnKeyType = . Next
123+ textField. returnKeyType = . next
124124 }
125125 }
126126 }
@@ -130,7 +130,7 @@ public class Form: UIScrollView {
130130 Updates the scrollview frame when keyboard appears.
131131 Scrolls to make the current field visible.
132132 */
133- private func minimizeScrollingZone( input: FormInput ) {
133+ fileprivate func minimizeScrollingZone( _ input: FormInput ) {
134134 if ( !viewScrolledForKeyboard) {
135135 viewScrolledForKeyboard = true
136136 originalFrame = self . frame
@@ -144,15 +144,15 @@ public class Form: UIScrollView {
144144 self . frame = newFrame
145145 }
146146
147- UIView . animateWithDuration ( 0.2 ) {
147+ UIView . animate ( withDuration : 0.2 , animations : {
148148 self . contentOffset = CGPoint ( x: 0 , y: input. frame. origin. y - self . frame. height/ 2 + input. frame. height/ 2 )
149- }
149+ } )
150150 }
151151
152152 /**
153153 Resets the scrolling zone to its original value.
154154 */
155- private func resetScrollingZone( ) {
155+ fileprivate func resetScrollingZone( ) {
156156 viewScrolledForKeyboard = false
157157 if let _ = originalFrame {
158158 self . frame = originalFrame
@@ -166,7 +166,7 @@ public class Form: UIScrollView {
166166
167167 - Parameter notification: the received notification.
168168 */
169- func textFieldReturnedFired( notification: NSNotification ) {
169+ func textFieldReturnedFired( _ notification: Notification ) {
170170 if let textfield = notification. object as? FormInput {
171171 if isLastInput ( textfield) {
172172 textfield. stopEditing ( )
@@ -187,12 +187,12 @@ public class Form: UIScrollView {
187187
188188 - Parameter notification: the received notification
189189 */
190- func keyboardShown( notification: NSNotification ) {
191- let info = notification. userInfo!
192- let value : AnyObject = info [ UIKeyboardFrameEndUserInfoKey] !
190+ func keyboardShown( _ notification: Notification ) {
191+ let info = ( notification as NSNotification ) . userInfo!
192+ let value : AnyObject = info [ UIKeyboardFrameEndUserInfoKey] ! as AnyObject
193193
194- let rawFrame = value. CGRectValue
195- let keyboardFrame = self . convertRect ( rawFrame, fromView : nil )
194+ let rawFrame = value. cgRectValue
195+ let keyboardFrame = self . convert ( rawFrame! , from : nil )
196196
197197 keyboardViewHeight = keyboardFrame. height
198198 }
@@ -202,7 +202,7 @@ public class Form: UIScrollView {
202202
203203 - Parameter notification: the received notification
204204 */
205- func textFieldBecameFirstResponder( notification: NSNotification ) {
205+ func textFieldBecameFirstResponder( _ notification: Notification ) {
206206 if let textfield = notification. object as? FormInput {
207207 currentInput = textfield
208208 }
@@ -213,7 +213,7 @@ public class Form: UIScrollView {
213213
214214 - Parameter input: the input to compare
215215 */
216- private func isLastInput( input: FormInput ) -> Bool {
216+ fileprivate func isLastInput( _ input: FormInput ) -> Bool {
217217 if let _ = formDelegate {
218218 if let nextInput: FormInput = formDelegate. getNextInput ( self , currentInput: currentInput) {
219219 return false
@@ -244,11 +244,11 @@ public class Form: UIScrollView {
244244
245245// MARK: Extensions
246246extension Form : FormInputDelegate {
247- public func didEnterEditionMode( input: FormInput ) {
248- dispatch_async ( dispatch_get_main_queue ( ) ) {
247+ public func didEnterEditionMode( _ input: FormInput ) {
248+ DispatchQueue . main . async {
249249 self . minimizeScrollingZone ( input)
250250 }
251251 }
252252
253- public func didExitEditionMode( input: FormInput ) { }
253+ public func didExitEditionMode( _ input: FormInput ) { }
254254}
0 commit comments