Skip to content

Commit 5ed3d8c

Browse files
Automatic migration to Swift 2.0
Converted using Xcode 7.0 GM release (Version 7A218).
1 parent ca65096 commit 5ed3d8c

8 files changed

Lines changed: 18 additions & 17 deletions

File tree

Validator.xcodeproj/project.pbxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
62D1AE0F1A1E6D4400E4DFF8 /* Project object */ = {
223223
isa = PBXProject;
224224
attributes = {
225+
LastSwiftMigration = 0700;
225226
LastUpgradeCheck = 0610;
226227
ORGANIZATIONNAME = jpotts18;
227228
TargetAttributes = {

Validator/FloatRule.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public class FloatRule:Rule {
1717
}
1818

1919
public func validate(value: String) -> Bool {
20-
let regex = NSRegularExpression(pattern: "[-+]?(\\d*[.])?\\d+", options: nil, error: nil)
20+
let regex = try? NSRegularExpression(pattern: "[-+]?(\\d*[.])?\\d+", options: [])
2121
if let regex = regex {
22-
let match = regex.numberOfMatchesInString(value, options: nil, range: NSRange(location: 0, length: count(value)))
22+
let match = regex.numberOfMatchesInString(value, options: [], range: NSRange(location: 0, length: value.characters.count))
2323
return match == 1
2424
}
2525
return false

Validator/FullNameRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class FullNameRule : Rule {
1818
}
1919

2020
public func validate(value: String) -> Bool {
21-
var nameArray: [String] = split(value) { $0 == " " }
21+
let nameArray: [String] = value.characters.split { $0 == " " }.map { String($0) }
2222
return nameArray.count >= 2
2323
}
2424

Validator/MaxLengthRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class MaxLengthRule: Rule {
2020
}
2121

2222
public func validate(value: String) -> Bool {
23-
return count(value) <= DEFAULT_LENGTH
23+
return value.characters.count <= DEFAULT_LENGTH
2424
}
2525

2626
public func errorMessage() -> String {

Validator/MinLengthRule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class MinLengthRule: Rule {
2121
}
2222

2323
public func validate(value: String) -> Bool {
24-
return count(value) >= DEFAULT_LENGTH
24+
return value.characters.count >= DEFAULT_LENGTH
2525
}
2626

2727
public func errorMessage() -> String {

Validator/Validator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class Validator {
3030
errors = [:]
3131

3232
for (textField, rule) in validations {
33-
if var error = rule.validateField() {
33+
if let error = rule.validateField() {
3434
errors[textField] = error
3535

3636
// let the user transform the field if they want
@@ -49,7 +49,7 @@ public class Validator {
4949

5050
// MARK: Using Keys
5151

52-
public func styleTransformers(#success:((validationRule:ValidationRule)->Void)?, error:((validationError:ValidationError)->Void)?) {
52+
public func styleTransformers(success success:((validationRule:ValidationRule)->Void)?, error:((validationError:ValidationError)->Void)?) {
5353
self.successStyleTransform = success
5454
self.errorStyleTransform = error
5555
}

Validator/ViewController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
3434
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "hideKeyboard"))
3535

3636
validator.styleTransformers(success:{ (validationRule) -> Void in
37-
println("here")
37+
print("here")
3838
// clear error label
3939
validationRule.errorLabel?.hidden = true
4040
validationRule.errorLabel?.text = ""
4141
validationRule.textField.layer.borderColor = UIColor.greenColor().CGColor
4242
validationRule.textField.layer.borderWidth = 0.5
4343

4444
}, error:{ (validationError) -> Void in
45-
println("error")
45+
print("error")
4646
validationError.errorLabel?.hidden = false
4747
validationError.errorLabel?.text = validationError.errorMessage
4848
validationError.textField.layer.borderColor = UIColor.redColor().CGColor
@@ -57,22 +57,22 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
5757
}
5858

5959
@IBAction func submitTapped(sender: AnyObject) {
60-
println("Validating...")
60+
print("Validating...")
6161
validator.validate(self)
6262
}
6363

6464
// MARK: ValidationDelegate Methods
6565

6666
func validationSuccessful() {
67-
println("Validation Success!")
68-
var alert = UIAlertController(title: "Success", message: "You are validated!", preferredStyle: UIAlertControllerStyle.Alert)
69-
var defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
67+
print("Validation Success!")
68+
let alert = UIAlertController(title: "Success", message: "You are validated!", preferredStyle: UIAlertControllerStyle.Alert)
69+
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
7070
alert.addAction(defaultAction)
7171
self.presentViewController(alert, animated: true, completion: nil)
7272

7373
}
7474
func validationFailed(errors:[UITextField:ValidationError]) {
75-
println("Validation FAILED!")
75+
print("Validation FAILED!")
7676
}
7777

7878
func hideKeyboard(){

ValidatorTests/ValidatorTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ class ValidatorTests: XCTestCase {
3535
let LEN_20 = "Paint the cat orange"
3636

3737
let REGISTER_TXT_FIELD = UITextField()
38-
let REGISTER_VALIDATOR = Validator()
38+
let REGISTER_VALIDATOR = Validator
3939
let REGISTER_RULES = [Rule]()
4040

4141
let UNREGISTER_TXT_FIELD = UITextField()
42-
let UNREGISTER_VALIDATOR = Validator()
42+
let UNREGISTER_VALIDATOR = Validator
4343
let UNREGISTER_RULES = [Rule]()
4444

4545
let UNREGISTER_ERRORS_TXT_FIELD = UITextField()
46-
let UNREGISTER_ERRORS_VALIDATOR = Validator()
46+
let UNREGISTER_ERRORS_VALIDATOR = Validator
4747

4848
let ERROR_LABEL = UILabel()
4949

0 commit comments

Comments
 (0)