public modifiers for classes, initializers, methods..

This commit is contained in:
alejandro soto 2015-03-30 20:02:46 -06:00
parent 3600cf0d38
commit 56bd39702c
10 changed files with 31 additions and 33 deletions

View File

@ -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"
}

View File

@ -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"
}
}

View File

@ -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
}
}

View File

@ -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"
}
}

View File

@ -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
}
}

View File

@ -8,7 +8,7 @@
import Foundation
protocol Rule {
public protocol Rule {
func validate(value:String) -> Bool
func errorMessage() -> String
}

View File

@ -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
}

View File

@ -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

View File

@ -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

View File

@ -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"
}