Skip to content

Commit c5a6bcb

Browse files
committed
Merge pull request #11 from asotog/master
Pods support fixes
2 parents b949078 + 2c4ffda commit c5a6bcb

11 files changed

+71
-56
lines changed
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
Pod::Spec.new do |s|
2-
s.name = "Swift-Validator"
3-
s.version = "2.0.2"
2+
s.name = "Swift_Validator"
3+
s.version = "2.0.5"
44
s.summary = "A UITextField Validation library for Swift"
55
s.homepage = "https://github.com/jpotts18/swift-validator"
66
s.screenshots = "https://raw.githubusercontent.com/jpotts18/swift-validator/master/swift-validator-v2.gif"
77
s.license = { :type => "Apache 2.0", :file => "LICENCE.txt" }
88
s.author = { "Jeff" => "jeff.potter6@gmail.com" }
99
s.social_media_url = "http://twitter.com/jpotts18"
1010
s.platform = :ios
11-
s.ios.deployment_target = '8.0'
12-
s.source = { :git => "https://github.com/jpotts18/swift-validator.git", :tag => "2.0.2" }
11+
s.ios.deployment_target = '8.0'
12+
s.source = { :git => "https://github.com/asotog/swift-validator.git", :tag => "2.0.5" }
1313
s.source_files = "Validator/*.swift"
14+
s.frameworks = ['Foundation', 'UIKit']
15+
s.requires_arc = true
1416
end

Validator/ConfirmRule.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@
99
import Foundation
1010
import UIKit
1111

12-
class ConfirmationRule: Rule {
12+
public class ConfirmationRule: Rule {
1313

1414
let confirmField: UITextField
1515

1616
init(confirmField: UITextField) {
1717
self.confirmField = confirmField
1818
}
1919

20-
func validate(value: String) -> Bool {
20+
public func validate(value: String) -> Bool {
2121
if self.confirmField.text == value {
2222
return true
2323
} else {
2424
return false
2525
}
2626
}
2727

28-
func errorMessage() -> String {
28+
public func errorMessage() -> String {
2929
return "This field does not match"
3030
}
3131

Validator/EmailRule.swift

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@
88

99
import Foundation
1010

11-
class EmailRule: Rule {
11+
public class EmailRule: Rule {
1212

1313
private let REGEX: String
1414

15-
init(){
15+
public init(){
1616
self.REGEX = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}"
1717
}
1818

19-
init(regex:String){
19+
public init(regex:String){
2020
REGEX = regex
2121
}
22-
23-
func validate(value: String) -> Bool {
24-
return NSPredicate(format: "SELF MATCHES %@", self.REGEX).evaluateWithObject(value)
22+
23+
public func validate(value: String) -> Bool {
24+
if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) {
25+
if test.evaluateWithObject(value) {
26+
return true
27+
}
28+
}
29+
return false
2530
}
26-
27-
func errorMessage() -> String {
31+
public func errorMessage() -> String {
2832
return "Must be a valid email address"
2933
}
3034
}

Validator/FullNameRule.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@
99
import Foundation
1010

1111

12-
class FullNameRule : Rule {
12+
public class FullNameRule : Rule {
1313

1414
var message:String {
1515
return "Please provide a first & last name"
1616
}
1717

18-
func validate(value:String) -> Bool {
18+
public func validate(value:String) -> Bool {
1919

2020
var nameArray:[String] = split(value) { $0 == " " }
2121
if nameArray.count >= 2 {
2222
return true
2323
}
2424
return false
2525
}
26-
27-
func errorMessage() -> String {
26+
public func errorMessage() -> String {
2827
return message
2928
}
3029
}

Validator/PasswordRule.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
class PasswordRule : Rule {
11+
public class PasswordRule : Rule {
1212

1313
// Alternative Regexes
1414

@@ -22,19 +22,24 @@ class PasswordRule : Rule {
2222

2323
private let REGEX: String
2424

25-
init(){
25+
public init(){
2626
self.REGEX = "^(?=.*?[A-Z]).{8,}$"
2727
}
2828

29-
init(regex:String){
29+
public init(regex:String){
3030
self.REGEX = regex
3131
}
32-
33-
func validate(value: String) -> Bool {
34-
return NSPredicate(format: "SELF MATCHES %@", self.REGEX).evaluateWithObject(value)
32+
33+
public func validate(value: String) -> Bool {
34+
if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) {
35+
if test.evaluateWithObject(value) {
36+
return true
37+
}
38+
}
39+
return false
3540
}
3641

37-
func errorMessage() -> String {
42+
public func errorMessage() -> String {
3843
return "Must be 8 characters with 1 uppercase"
3944
}
4045
}

Validator/RequiredRule.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@
99
import Foundation
1010

1111

12-
class RequiredRule: Rule {
12+
public class RequiredRule: Rule {
1313

14-
init(){}
14+
public init(){}
1515

1616
var message: String {
1717
return "This field is required"
1818
}
1919

20-
func validate(value:String) -> Bool {
20+
public func validate(value:String) -> Bool {
2121
if value.isEmpty {
2222
return false
2323
}
2424
return true
2525
}
2626

27-
func errorMessage() -> String {
27+
public func errorMessage() -> String {
2828
return message
2929
}
3030
}

Validator/Rule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import Foundation
1010

11-
protocol Rule {
11+
public protocol Rule {
1212
func validate(value:String) -> Bool
1313
func errorMessage() -> String
1414
}

Validator/ValidationError.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import Foundation
1010
import UIKit
1111

12-
class ValidationError {
13-
let textField:UITextField
14-
var errorLabel:UILabel?
15-
let errorMessage:String
12+
public class ValidationError {
13+
public let textField:UITextField
14+
public var errorLabel:UILabel?
15+
public let errorMessage:String
1616

17-
init(textField:UITextField, error:String){
17+
public init(textField:UITextField, error:String){
1818
self.textField = textField
1919
self.errorMessage = error
2020
}

Validator/ValidationRule.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
import Foundation
1010
import UIKit
1111

12-
class ValidationRule {
13-
var textField:UITextField
14-
var errorLabel:UILabel?
15-
var rules:[Rule] = []
12+
public class ValidationRule {
13+
public var textField:UITextField
14+
public var errorLabel:UILabel?
15+
public var rules:[Rule] = []
1616

17-
init(textField: UITextField, rules:[Rule], errorLabel:UILabel?){
17+
public init(textField: UITextField, rules:[Rule], errorLabel:UILabel?){
1818
self.textField = textField
1919
self.errorLabel = errorLabel
2020
self.rules = rules
2121
}
2222

23-
func validateField() -> ValidationError? {
23+
public func validateField() -> ValidationError? {
2424
for rule in rules {
2525
var isValid:Bool = rule.validate(textField.text)
2626
if !isValid {

Validator/Validator.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,29 @@
99
import Foundation
1010
import UIKit
1111

12-
@objc protocol ValidationDelegate {
12+
@objc public protocol ValidationDelegate {
1313
func validationWasSuccessful()
1414
func validationFailed(errors:[UITextField:ValidationError])
1515
}
1616

17-
class Validator {
17+
public class Validator {
1818
// dictionary to handle complex view hierarchies like dynamic tableview cells
19-
var errors:[UITextField:ValidationError] = [:]
20-
var validations:[UITextField:ValidationRule] = [:]
19+
public var errors:[UITextField:ValidationError] = [:]
20+
public var validations:[UITextField:ValidationRule] = [:]
2121

22-
init(){}
22+
public init(){}
2323

2424
// MARK: Using Keys
2525

26-
func registerField(textField:UITextField, rules:[Rule]) {
26+
public func registerField(textField:UITextField, rules:[Rule]) {
2727
validations[textField] = ValidationRule(textField: textField, rules: rules, errorLabel: nil)
2828
}
2929

30-
func registerField(textField:UITextField, errorLabel:UILabel, rules:[Rule]) {
30+
public func registerField(textField:UITextField, errorLabel:UILabel, rules:[Rule]) {
3131
validations[textField] = ValidationRule(textField: textField, rules:rules, errorLabel:errorLabel)
3232
}
3333

34-
func validateAll(delegate:ValidationDelegate) {
34+
public func validateAll(delegate:ValidationDelegate) {
3535

3636
for field in validations.keys {
3737
if let currentRule:ValidationRule = validations[field] {

0 commit comments

Comments
 (0)