diff --git a/Validator/ConfirmRule.swift b/Validator/ConfirmRule.swift index e51d259..61d27b9 100644 --- a/Validator/ConfirmRule.swift +++ b/Validator/ConfirmRule.swift @@ -9,7 +9,7 @@ import Foundation import UIKit -class ConfirmationRule: Rule { +public class ConfirmationRule: Rule { let confirmField: UITextField @@ -17,7 +17,7 @@ class ConfirmationRule: Rule { self.confirmField = confirmField } - func validate(value: String) -> Bool { + public func validate(value: String) -> Bool { if self.confirmField.text == value { return true } else { @@ -25,7 +25,7 @@ class ConfirmationRule: Rule { } } - func errorMessage() -> String { + public func errorMessage() -> String { return "This field does not match" } diff --git a/Validator/EmailRule.swift b/Validator/EmailRule.swift index 4203a2a..908d006 100644 --- a/Validator/EmailRule.swift +++ b/Validator/EmailRule.swift @@ -8,19 +8,19 @@ import Foundation -class EmailRule: Rule { +public class EmailRule: Rule { var REGEX : String - init(){ + public init(){ self.REGEX = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6}" } - init(regex:String){ + public init(regex:String){ REGEX = regex } - func validate(value: String) -> Bool { + public func validate(value: String) -> Bool { if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) { if test.evaluateWithObject(value) { return true @@ -28,8 +28,7 @@ class EmailRule: Rule { } return false } - - func errorMessage() -> String { + public func errorMessage() -> String { return "Must be a valid email address" } } \ No newline at end of file diff --git a/Validator/FullNameRule.swift b/Validator/FullNameRule.swift index af9ea87..a29423d 100644 --- a/Validator/FullNameRule.swift +++ b/Validator/FullNameRule.swift @@ -9,13 +9,13 @@ import Foundation -class FullNameRule : Rule { +public class FullNameRule : Rule { var message:String { return "Please provide a first & last name" } - func validate(value:String) -> Bool { + public func validate(value:String) -> Bool { var nameArray:[String] = split(value) { $0 == " " } if nameArray.count >= 2 { @@ -23,8 +23,7 @@ class FullNameRule : Rule { } return false } - - func errorMessage() -> String { + public func errorMessage() -> String { return message } } \ No newline at end of file diff --git a/Validator/PasswordRule.swift b/Validator/PasswordRule.swift index 5dbe149..20607b3 100644 --- a/Validator/PasswordRule.swift +++ b/Validator/PasswordRule.swift @@ -8,7 +8,7 @@ import Foundation -class PasswordRule : Rule { +public class PasswordRule : Rule { // Alternative Regexes @@ -22,15 +22,15 @@ class PasswordRule : Rule { private let REGEX: String - init(){ + public init(){ self.REGEX = "^(?=.*?[A-Z]).{8,}$" } - init(regex:String){ + public init(regex:String){ self.REGEX = regex } - func validate(value: String) -> Bool { + public func validate(value: String) -> Bool { if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) { if test.evaluateWithObject(value) { return true @@ -39,7 +39,7 @@ class PasswordRule : Rule { return false } - func errorMessage() -> String { + public func errorMessage() -> String { return "Must be 8 characters with 1 uppercase" } } \ No newline at end of file diff --git a/Validator/RequiredRule.swift b/Validator/RequiredRule.swift index 3075912..361a592 100644 --- a/Validator/RequiredRule.swift +++ b/Validator/RequiredRule.swift @@ -9,22 +9,22 @@ import Foundation -class RequiredRule: Rule { +public class RequiredRule: Rule { - init(){} + public init(){} var message: String { return "This field is required" } - func validate(value:String) -> Bool { + public func validate(value:String) -> Bool { if value.isEmpty { return false } return true } - func errorMessage() -> String { + public func errorMessage() -> String { return message } } \ No newline at end of file diff --git a/Validator/Rule.swift b/Validator/Rule.swift index 2d97304..caed81f 100644 --- a/Validator/Rule.swift +++ b/Validator/Rule.swift @@ -8,7 +8,7 @@ import Foundation -protocol Rule { +public protocol Rule { func validate(value:String) -> Bool func errorMessage() -> String } diff --git a/Validator/ValidationError.swift b/Validator/ValidationError.swift index ba1e20b..d882355 100644 --- a/Validator/ValidationError.swift +++ b/Validator/ValidationError.swift @@ -9,12 +9,12 @@ import Foundation import UIKit -class ValidationError { +public class ValidationError { let textField:UITextField var errorLabel:UILabel? let errorMessage:String - init(textField:UITextField, error:String){ + public init(textField:UITextField, error:String){ self.textField = textField self.errorMessage = error } diff --git a/Validator/ValidationRule.swift b/Validator/ValidationRule.swift index bd11395..e9f3ec3 100644 --- a/Validator/ValidationRule.swift +++ b/Validator/ValidationRule.swift @@ -9,12 +9,12 @@ import Foundation import UIKit -class ValidationRule { +public class ValidationRule { var textField:UITextField var errorLabel:UILabel? var rules:[Rule] = [] - init(textField: UITextField, rules:[Rule], errorLabel:UILabel?){ + public init(textField: UITextField, rules:[Rule], errorLabel:UILabel?){ self.textField = textField self.errorLabel = errorLabel self.rules = rules diff --git a/Validator/Validator.swift b/Validator/Validator.swift index 753dd3f..f55f553 100644 --- a/Validator/Validator.swift +++ b/Validator/Validator.swift @@ -9,17 +9,17 @@ import Foundation import UIKit -@objc protocol ValidationDelegate { +@objc public protocol ValidationDelegate { func validationWasSuccessful() func validationFailed(errors:[UITextField:ValidationError]) } -class Validator { +public class Validator { // dictionary to handle complex view hierarchies like dynamic tableview cells var errors:[UITextField:ValidationError] = [:] var validations:[UITextField:ValidationRule] = [:] - init(){} + public init(){} // MARK: Using Keys diff --git a/Validator/ZipCodeRule.swift b/Validator/ZipCodeRule.swift index 4d35c30..01f1b23 100644 --- a/Validator/ZipCodeRule.swift +++ b/Validator/ZipCodeRule.swift @@ -8,7 +8,7 @@ import Foundation -class ZipCodeRule: Rule { +public class ZipCodeRule: Rule { private let REGEX: String init(){ @@ -18,7 +18,7 @@ class ZipCodeRule: Rule { self.REGEX = regex } - func validate(value: String) -> Bool { + public func validate(value: String) -> Bool { if let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX) { if test.evaluateWithObject(value) { return true @@ -27,7 +27,7 @@ class ZipCodeRule: Rule { return false } - func errorMessage() -> String { + public func errorMessage() -> String { return "Enter a valid 5 digit zipcode" }