commit
43fddfb385
11
.travis.yml
11
.travis.yml
|
|
@ -1,15 +1,16 @@
|
|||
language: objective-c
|
||||
osx_image: xcode7.1
|
||||
osx_image: xcode8
|
||||
xcode_sdk: iphonesimulator10.0
|
||||
xcode_project: Validator.xcodeproj
|
||||
xcode_scheme: Validator
|
||||
|
||||
before_install:
|
||||
|
||||
- gem install cocoapods -v '0.32.1'
|
||||
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
|
||||
|
||||
script:
|
||||
|
||||
- xcodebuild clean build test -project Validator.xcodeproj -scheme Validator -sdk iphonesimulator -destination "platform=iOS Simulator,OS=10.0,name=iPhone 6" -enableCodeCoverage YES CODE_SIGNING_REQUIRED=NO | xcpretty
|
||||
- pod lib lint
|
||||
- xcodebuild clean build test -project Validator.xcodeproj -scheme Validator -sdk iphonesimulator9.1 -destination "OS=9.1,name=iPhone 6" -enableCodeCoverage YES | xcpretty
|
||||
|
||||
after_success:
|
||||
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public typealias ValidatableField = protocol<AnyObject, Validatable>
|
||||
public typealias ValidatableField = AnyObject & Validatable
|
||||
|
||||
public protocol Validatable {
|
||||
|
||||
|
|
|
|||
|
|
@ -23,5 +23,5 @@ public protocol ValidationDelegate {
|
|||
|
||||
- returns: No return value.
|
||||
*/
|
||||
func validationFailed(errors: [(Validatable, ValidationError)])
|
||||
func validationFailed(_ errors: [(Validatable, ValidationError)])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,9 @@ public class Validator {
|
|||
/// Dictionary to hold fields by their object identifiers
|
||||
private var fields = ValidatorDictionary<Validatable>()
|
||||
/// Variable that holds success closure to display positive status of field.
|
||||
private var successStyleTransform:((validationRule:ValidationRule)->Void)?
|
||||
private var successStyleTransform:((_ validationRule:ValidationRule)->Void)?
|
||||
/// Variable that holds error closure to display negative status of field.
|
||||
private var errorStyleTransform:((validationError:ValidationError)->Void)?
|
||||
private var errorStyleTransform:((_ validationError:ValidationError)->Void)?
|
||||
/// - returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception.
|
||||
public init(){}
|
||||
|
||||
|
|
@ -44,13 +44,13 @@ public class Validator {
|
|||
|
||||
// let the user transform the field if they want
|
||||
if let transform = self.errorStyleTransform {
|
||||
transform(validationError: error)
|
||||
transform(error)
|
||||
}
|
||||
} else {
|
||||
// No error
|
||||
// let the user transform the field if they want
|
||||
if let transform = self.successStyleTransform {
|
||||
transform(validationRule: rule)
|
||||
transform(rule)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -65,22 +65,22 @@ public class Validator {
|
|||
- parameter field: Holds validator field data.
|
||||
- returns: No return value.
|
||||
*/
|
||||
public func validateField(field: ValidatableField, callback: (error:ValidationError?) -> Void){
|
||||
public func validateField(_ field: ValidatableField, callback: (_ error:ValidationError?) -> Void){
|
||||
if let fieldRule = validations[field] {
|
||||
if let error = fieldRule.validateField() {
|
||||
errors[field] = error
|
||||
if let transform = self.errorStyleTransform {
|
||||
transform(validationError: error)
|
||||
transform(error)
|
||||
}
|
||||
callback(error: error)
|
||||
callback(error)
|
||||
} else {
|
||||
if let transform = self.successStyleTransform {
|
||||
transform(validationRule: fieldRule)
|
||||
transform(fieldRule)
|
||||
}
|
||||
callback(error: nil)
|
||||
callback(nil)
|
||||
}
|
||||
} else {
|
||||
callback(error: nil)
|
||||
callback(nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +93,7 @@ public class Validator {
|
|||
- parameter error: A closure which is called with validationError, an object that holds validation error data
|
||||
- returns: No return value
|
||||
*/
|
||||
public func styleTransformers(success success:((validationRule:ValidationRule)->Void)?, error:((validationError:ValidationError)->Void)?) {
|
||||
public func styleTransformers(success:((_ validationRule:ValidationRule)->Void)?, error:((_ validationError:ValidationError)->Void)?) {
|
||||
self.successStyleTransform = success
|
||||
self.errorStyleTransform = error
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ public class Validator {
|
|||
- parameter rules: A Rule array that holds different rules that apply to said field.
|
||||
- returns: No return value
|
||||
*/
|
||||
public func registerField(field: ValidatableField, errorLabel:UILabel? = nil, rules:[Rule]) {
|
||||
public func registerField(_ field: ValidatableField, errorLabel:UILabel? = nil, rules:[Rule]) {
|
||||
validations[field] = ValidationRule(field: field, rules:rules, errorLabel:errorLabel)
|
||||
fields[field] = field
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ public class Validator {
|
|||
- parameter field: field used to locate and remove field from validator.
|
||||
- returns: No return value
|
||||
*/
|
||||
public func unregisterField(field:ValidatableField) {
|
||||
public func unregisterField(_ field:ValidatableField) {
|
||||
validations.removeValueForKey(field)
|
||||
errors.removeValueForKey(field)
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ public class Validator {
|
|||
|
||||
- returns: No return value.
|
||||
*/
|
||||
public func validate(delegate:ValidationDelegate) {
|
||||
public func validate(_ delegate:ValidationDelegate) {
|
||||
|
||||
self.validateAllFields()
|
||||
|
||||
|
|
@ -145,10 +145,10 @@ public class Validator {
|
|||
- parameter callback: A closure which is called with errors, a dictionary of type Validatable:ValidationError.
|
||||
- returns: No return value.
|
||||
*/
|
||||
public func validate(callback:(errors:[(Validatable, ValidationError)])->Void) -> Void {
|
||||
public func validate(_ callback:(_ errors:[(Validatable, ValidationError)])->Void) -> Void {
|
||||
|
||||
self.validateAllFields()
|
||||
|
||||
callback(errors: errors.map { (fields[$1.field]!, $1) } )
|
||||
callback(errors.map { (fields[$1.field]!, $1) } )
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public struct ValidatorDictionary<T> : SequenceType {
|
||||
public struct ValidatorDictionary<T> : Sequence {
|
||||
|
||||
private var innerDictionary: [ObjectIdentifier: T] = [:];
|
||||
|
||||
|
|
@ -31,15 +31,15 @@ public struct ValidatorDictionary<T> : SequenceType {
|
|||
innerDictionary.removeAll()
|
||||
}
|
||||
|
||||
public mutating func removeValueForKey(key: ValidatableField) {
|
||||
innerDictionary.removeValueForKey(ObjectIdentifier(key))
|
||||
public mutating func removeValueForKey(_ key: ValidatableField) {
|
||||
innerDictionary.removeValue(forKey: ObjectIdentifier(key))
|
||||
}
|
||||
|
||||
public var isEmpty: Bool {
|
||||
return innerDictionary.isEmpty
|
||||
}
|
||||
|
||||
public func generate() -> DictionaryGenerator<ObjectIdentifier ,T> {
|
||||
return innerDictionary.generate()
|
||||
public func makeIterator() -> DictionaryIterator<ObjectIdentifier ,T> {
|
||||
return innerDictionary.makeIterator()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ public class AlphaNumericRule: CharacterSetRule {
|
|||
- returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception.
|
||||
*/
|
||||
public init(message: String = "Enter valid numeric characters") {
|
||||
super.init(characterSet: NSCharacterSet.alphanumericCharacterSet(), message: message)
|
||||
super.init(characterSet: CharacterSet.alphanumerics, message: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ public class AlphaRule: CharacterSetRule {
|
|||
- returns: An initialized object, or nil if an object could not be created for some reason.
|
||||
*/
|
||||
public init(message: String = "Enter valid alphabetic characters") {
|
||||
super.init(characterSet: NSCharacterSet.letterCharacterSet(), message: message)
|
||||
super.init(characterSet: CharacterSet.letters, message: message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import Foundation
|
|||
*/
|
||||
public class CharacterSetRule: Rule {
|
||||
/// NSCharacter that hold set of valid characters to hold
|
||||
private let characterSet: NSCharacterSet
|
||||
private let characterSet: CharacterSet
|
||||
/// String that holds error message
|
||||
private var message: String
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ public class CharacterSetRule: Rule {
|
|||
- parameter message: String of error message.
|
||||
- returns: An initialized object, or nil if an object could not be created for some reason that would not result in an exception.
|
||||
*/
|
||||
public init(characterSet: NSCharacterSet, message: String = "Enter valid alpha") {
|
||||
public init(characterSet: CharacterSet, message: String = "Enter valid alpha") {
|
||||
self.characterSet = characterSet
|
||||
self.message = message
|
||||
}
|
||||
|
|
@ -35,9 +35,9 @@ public class CharacterSetRule: Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: Boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
for uni in value.unicodeScalars {
|
||||
if !characterSet.longCharacterIsMember(uni.value) {
|
||||
guard let uniVal = UnicodeScalar(uni.value), characterSet.contains(uniVal) else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
@ -52,4 +52,4 @@ public class CharacterSetRule: Rule {
|
|||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ConfirmationRule: Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: A boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
return confirmField.validationText == value
|
||||
}
|
||||
|
||||
|
|
@ -49,4 +49,4 @@ public class ConfirmationRule: Rule {
|
|||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ public class ExactLengthRule : Rule {
|
|||
*/
|
||||
public init(length: Int, message : String = "Must be exactly %ld characters long"){
|
||||
self.length = length
|
||||
self.message = NSString(format: message, self.length) as String
|
||||
self.message = String(format: message, self.length)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -35,7 +35,7 @@ public class ExactLengthRule : Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: A boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
return value.characters.count == length
|
||||
}
|
||||
|
||||
|
|
@ -47,4 +47,4 @@ public class ExactLengthRule : Rule {
|
|||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,10 +31,10 @@ public class FloatRule:Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: Boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
let regex = try? NSRegularExpression(pattern: "^[-+]?(\\d*[.])?\\d+$", options: [])
|
||||
if let regex = regex {
|
||||
let match = regex.numberOfMatchesInString(value, options: [], range: NSRange(location: 0, length: value.characters.count))
|
||||
let match = regex.numberOfMatches(in: value, options: [], range: NSRange(location: 0, length: value.characters.count))
|
||||
return match == 1
|
||||
}
|
||||
return false
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class FullNameRule : Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: A boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
let nameArray: [String] = value.characters.split { $0 == " " }.map { String($0) }
|
||||
return nameArray.count >= 2
|
||||
}
|
||||
|
|
@ -43,4 +43,4 @@ public class FullNameRule : Rule {
|
|||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,13 +32,13 @@ public class ISBNRule: Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: Boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
|
||||
guard let regex = try? NSRegularExpression(pattern: "[\\s-]", options: []) else {
|
||||
fatalError("Invalid ISBN sanitizing regex")
|
||||
}
|
||||
|
||||
let sanitized = regex.stringByReplacingMatchesInString(value, options: [], range: NSMakeRange(0, value.characters.count), withTemplate: "")
|
||||
let sanitized = regex.stringByReplacingMatches(in: value, options: [], range: NSMakeRange(0, value.characters.count), withTemplate: "")
|
||||
|
||||
return ISBN10Validator().verify(sanitized) || ISBN13Validator().verify(sanitized)
|
||||
}
|
||||
|
|
@ -67,7 +67,7 @@ private protocol ISBNValidator {
|
|||
- returns: A `Bool` that represents what happened during verification. `false` is returned if
|
||||
it fails, `true` is returned if it was a success.
|
||||
*/
|
||||
func verify(input: String) -> Bool
|
||||
func verify(_ input: String) -> Bool
|
||||
/**
|
||||
Method that verifies regular expression is valid.
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ private protocol ISBNValidator {
|
|||
- returns: A `Bool` that represents the status of the ISBN number. `false` if ISBN number
|
||||
was not valid, `true` if it was valid.
|
||||
*/
|
||||
func checkRegex(input: String) -> Bool
|
||||
func checkRegex(_ input: String) -> Bool
|
||||
|
||||
/**
|
||||
Method that verifies `ISBN` being validated is itself valid. It has to be either ISBN10
|
||||
|
|
@ -85,7 +85,7 @@ private protocol ISBNValidator {
|
|||
- returns: A `Bool` that represents the status of the ISBN number. `false` if ISBN number
|
||||
was not valid, `true` if it was valid.
|
||||
*/
|
||||
func verifyChecksum(input: String) -> Bool
|
||||
func verifyChecksum(_ input: String) -> Bool
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -100,7 +100,7 @@ extension ISBNValidator {
|
|||
- returns: A `Bool` that represents what happened during verification. `false` is returned if
|
||||
it fails, `true` is returned if it was a success.
|
||||
*/
|
||||
func verify(input: String) -> Bool {
|
||||
func verify(_ input: String) -> Bool {
|
||||
return checkRegex(input) && verifyChecksum(input)
|
||||
}
|
||||
|
||||
|
|
@ -112,8 +112,8 @@ extension ISBNValidator {
|
|||
- returns: A `Bool` that represents the status of the ISBN number. `false` if ISBN number
|
||||
was not valid, `true` if it was valid.
|
||||
*/
|
||||
func checkRegex(input: String) -> Bool {
|
||||
guard let _ = input.rangeOfString(regex, options: [.RegularExpressionSearch, .AnchoredSearch]) else {
|
||||
func checkRegex(_ input: String) -> Bool {
|
||||
guard let _ = input.range(of: regex, options: [.regularExpression, .anchored]) else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
@ -136,19 +136,19 @@ private struct ISBN10Validator: ISBNValidator {
|
|||
- parameter input: String that is checked for ISBN10 validation.
|
||||
- returns: `true` if string is a valid ISBN10 and `false` if it is not.
|
||||
*/
|
||||
private func verifyChecksum(input: String) -> Bool {
|
||||
fileprivate func verifyChecksum(_ input: String) -> Bool {
|
||||
var checksum = 0
|
||||
|
||||
for i in 0..<9 {
|
||||
if let intCharacter = Int(String(input[input.startIndex.advancedBy(i)])) {
|
||||
if let intCharacter = Int(String(input[input.characters.index(input.startIndex, offsetBy: i)])) {
|
||||
checksum += (i + 1) * intCharacter
|
||||
}
|
||||
}
|
||||
|
||||
if (input[input.startIndex.advancedBy(9)] == "X") {
|
||||
if (input[input.characters.index(input.startIndex, offsetBy: 9)] == "X") {
|
||||
checksum += 10 * 10
|
||||
} else {
|
||||
if let intCharacter = Int(String(input[input.startIndex.advancedBy(9)])) {
|
||||
if let intCharacter = Int(String(input[input.characters.index(input.startIndex, offsetBy: 9)])) {
|
||||
checksum += 10 * intCharacter
|
||||
}
|
||||
}
|
||||
|
|
@ -171,21 +171,21 @@ private struct ISBN13Validator: ISBNValidator {
|
|||
- parameter input: String that is checked for ISBN13 validation.
|
||||
- returns: `true` if string is a valid ISBN13 and `false` if it is not.
|
||||
*/
|
||||
private func verifyChecksum(input: String) -> Bool {
|
||||
fileprivate func verifyChecksum(_ input: String) -> Bool {
|
||||
let factor = [1, 3]
|
||||
var checksum = 0
|
||||
|
||||
for i in 0..<12 {
|
||||
if let intCharacter = Int(String(input[input.startIndex.advancedBy(i)])) {
|
||||
if let intCharacter = Int(String(input[input.characters.index(input.startIndex, offsetBy: i)])) {
|
||||
print("\(factor[i%2]) * \(intCharacter)")
|
||||
checksum += factor[i % 2] * intCharacter
|
||||
}
|
||||
}
|
||||
|
||||
if let lastInt = Int(String(input[input.startIndex.advancedBy(12)])) {
|
||||
if let lastInt = Int(String(input[input.characters.index(input.startIndex, offsetBy: 12)])) {
|
||||
return (lastInt - ((10 - (checksum % 10)) % 10) == 0)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class MaxLengthRule: Rule {
|
|||
*/
|
||||
public init(length: Int, message : String = "Must be at most %ld characters long"){
|
||||
self.DEFAULT_LENGTH = length
|
||||
self.message = NSString(format: message, self.DEFAULT_LENGTH) as String
|
||||
self.message = String(format: message, self.DEFAULT_LENGTH)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -36,7 +36,7 @@ public class MaxLengthRule: Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: A boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
return value.characters.count <= DEFAULT_LENGTH
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ public class MinLengthRule: Rule {
|
|||
*/
|
||||
public init(length: Int, message : String = "Must be at least %ld characters long"){
|
||||
self.DEFAULT_LENGTH = length
|
||||
self.message = NSString(format: message, self.DEFAULT_LENGTH) as String
|
||||
self.message = String(format: message, self.DEFAULT_LENGTH)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -37,7 +37,7 @@ public class MinLengthRule: Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: A boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
return value.characters.count >= DEFAULT_LENGTH
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ public class RegexRule : Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: Boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
let test = NSPredicate(format: "SELF MATCHES %@", self.REGEX)
|
||||
return test.evaluateWithObject(value)
|
||||
return test.evaluate(with: value)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ public class RequiredRule: Rule {
|
|||
- parameter value: String to checked for validation.
|
||||
- returns: Boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
public func validate(value: String) -> Bool {
|
||||
public func validate(_ value: String) -> Bool {
|
||||
return !value.isEmpty
|
||||
}
|
||||
|
||||
|
|
@ -43,4 +43,4 @@ public class RequiredRule: Rule {
|
|||
public func errorMessage() -> String {
|
||||
return message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public protocol Rule {
|
|||
- parameter value: String of text to be validated.
|
||||
- returns: Boolean value. True if validation is successful; False if validation fails.
|
||||
*/
|
||||
func validate(value: String) -> Bool
|
||||
func validate(_ value: String) -> Bool
|
||||
/**
|
||||
Displays error message of a field that has failed validation.
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ public class ValidationRule {
|
|||
*/
|
||||
public func validateField() -> ValidationError? {
|
||||
return rules.filter{
|
||||
return !$0.validate(field.validationText ?? "")
|
||||
return !$0.validate(field.validationText)
|
||||
}.map{ rule -> ValidationError in return ValidationError(field: self.field, errorLabel:self.errorLabel, error: rule.errorMessage()) }.first
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ class SwiftValidatorTests: XCTestCase {
|
|||
}
|
||||
REGISTER_TXT_FIELD.text = INVALID_EMAIL
|
||||
REGISTER_VALIDATOR.validateField(REGISTER_TXT_FIELD) { error in
|
||||
XCTAssert(error?.errorMessage.characters.count > 0, "Should state 'invalid email'")
|
||||
XCTAssert(error?.errorMessage.characters.count ?? 0 > 0, "Should state 'invalid email'")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -385,9 +385,9 @@ class SwiftValidatorTests: XCTestCase {
|
|||
var successCount = 0
|
||||
var errorCount = 0
|
||||
REGISTER_VALIDATOR.styleTransformers(success: { (validationRule) -> Void in
|
||||
successCount++
|
||||
successCount+=1
|
||||
}) { (validationError) -> Void in
|
||||
errorCount++
|
||||
errorCount+=1
|
||||
}
|
||||
REGISTER_TXT_FIELD.text = INVALID_EMAIL
|
||||
REGISTER_VALIDATOR.validate { (errors) -> Void in
|
||||
|
|
@ -403,9 +403,9 @@ class SwiftValidatorTests: XCTestCase {
|
|||
var successCount = 0
|
||||
var errorCount = 0
|
||||
REGISTER_VALIDATOR.styleTransformers(success: { (validationRule) -> Void in
|
||||
successCount++
|
||||
successCount+=1
|
||||
}) { (validationError) -> Void in
|
||||
errorCount++
|
||||
errorCount+=1
|
||||
}
|
||||
|
||||
REGISTER_TXT_FIELD.text = INVALID_EMAIL
|
||||
|
|
@ -427,7 +427,7 @@ class SwiftValidatorTests: XCTestCase {
|
|||
REGISTER_TXT_FIELD.text = INVALID_EMAIL
|
||||
REGISTER_VALIDATOR.validate { (errors) -> Void in
|
||||
XCTAssert(errors.count == 1, "Should come back with errors")
|
||||
XCTAssert(!CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, UIColor.redColor().CGColor), "Color shouldn't get set at all")
|
||||
XCTAssert(!(self.REGISTER_TXT_FIELD.layer.borderColor! == UIColor.red.cgColor), "Color shouldn't get set at all")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -396,21 +396,25 @@
|
|||
attributes = {
|
||||
LastSwiftMigration = 0700;
|
||||
LastSwiftUpdateCheck = 0700;
|
||||
LastUpgradeCheck = 0700;
|
||||
LastUpgradeCheck = 0800;
|
||||
ORGANIZATIONNAME = jpotts18;
|
||||
TargetAttributes = {
|
||||
62D1AE161A1E6D4400E4DFF8 = {
|
||||
CreatedOnToolsVersion = 6.1;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
62D1AE2B1A1E6D4500E4DFF8 = {
|
||||
CreatedOnToolsVersion = 6.1;
|
||||
LastSwiftMigration = 0800;
|
||||
TestTargetID = 62D1AE161A1E6D4400E4DFF8;
|
||||
};
|
||||
FB465CB21B9884F400398388 = {
|
||||
CreatedOnToolsVersion = 6.4;
|
||||
LastSwiftMigration = 0800;
|
||||
};
|
||||
FB465CBC1B9884F400398388 = {
|
||||
CreatedOnToolsVersion = 6.4;
|
||||
LastSwiftMigration = 0800;
|
||||
TestTargetID = 62D1AE161A1E6D4400E4DFF8;
|
||||
};
|
||||
};
|
||||
|
|
@ -585,8 +589,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
|
@ -595,6 +601,7 @@
|
|||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
|
|
@ -628,8 +635,10 @@
|
|||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
|
||||
|
|
@ -637,6 +646,7 @@
|
|||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu99;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
|
|
@ -658,6 +668,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
|
@ -669,6 +680,8 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
@ -684,6 +697,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
|
||||
};
|
||||
name = Debug;
|
||||
|
|
@ -696,6 +710,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
|
||||
};
|
||||
name = Release;
|
||||
|
|
@ -720,6 +735,7 @@
|
|||
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
|
|
@ -743,6 +759,8 @@
|
|||
PRODUCT_BUNDLE_IDENTIFIER = "me.jeffpotter.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TARGETED_DEVICE_FAMILY = "1,2";
|
||||
VERSIONING_SYSTEM = "apple-generic";
|
||||
VERSION_INFO_PREFIX = "";
|
||||
|
|
@ -767,6 +785,7 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.levous.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
|
||||
};
|
||||
name = Debug;
|
||||
|
|
@ -786,6 +805,8 @@
|
|||
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "com.levous.$(PRODUCT_NAME:rfc1034identifier)";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
|
||||
SWIFT_VERSION = 3.0;
|
||||
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Validator.app/Validator";
|
||||
};
|
||||
name = Release;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0700"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0700"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "0700"
|
||||
LastUpgradeVersion = "0800"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
|
|
@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
var window: UIWindow?
|
||||
|
||||
|
||||
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
|
||||
func applicationWillResignActive(application: UIApplication) {
|
||||
func applicationWillResignActive(_ application: UIApplication) {
|
||||
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
}
|
||||
|
||||
func applicationDidEnterBackground(application: UIApplication) {
|
||||
func applicationDidEnterBackground(_ application: UIApplication) {
|
||||
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
||||
}
|
||||
|
||||
func applicationWillEnterForeground(application: UIApplication) {
|
||||
func applicationWillEnterForeground(_ application: UIApplication) {
|
||||
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
||||
}
|
||||
|
||||
func applicationDidBecomeActive(application: UIApplication) {
|
||||
func applicationDidBecomeActive(_ application: UIApplication) {
|
||||
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
}
|
||||
|
||||
func applicationWillTerminate(application: UIApplication) {
|
||||
func applicationWillTerminate(_ application: UIApplication) {
|
||||
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,24 +31,24 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "hideKeyboard"))
|
||||
self.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(ViewController.hideKeyboard)))
|
||||
|
||||
validator.styleTransformers(success:{ (validationRule) -> Void in
|
||||
print("here")
|
||||
// clear error label
|
||||
validationRule.errorLabel?.hidden = true
|
||||
validationRule.errorLabel?.isHidden = true
|
||||
validationRule.errorLabel?.text = ""
|
||||
if let textField = validationRule.field as? UITextField {
|
||||
textField.layer.borderColor = UIColor.greenColor().CGColor
|
||||
textField.layer.borderColor = UIColor.green.cgColor
|
||||
textField.layer.borderWidth = 0.5
|
||||
|
||||
}
|
||||
}, error:{ (validationError) -> Void in
|
||||
print("error")
|
||||
validationError.errorLabel?.hidden = false
|
||||
validationError.errorLabel?.isHidden = false
|
||||
validationError.errorLabel?.text = validationError.errorMessage
|
||||
if let textField = validationError.field as? UITextField {
|
||||
textField.layer.borderColor = UIColor.redColor().CGColor
|
||||
textField.layer.borderColor = UIColor.red.cgColor
|
||||
textField.layer.borderWidth = 1.0
|
||||
}
|
||||
})
|
||||
|
|
@ -60,7 +60,7 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
|
|||
validator.registerField(zipcodeTextField, errorLabel: zipcodeErrorLabel, rules: [RequiredRule(), ZipCodeRule()])
|
||||
}
|
||||
|
||||
@IBAction func submitTapped(sender: AnyObject) {
|
||||
@IBAction func submitTapped(_ sender: AnyObject) {
|
||||
print("Validating...")
|
||||
validator.validate(self)
|
||||
}
|
||||
|
|
@ -69,13 +69,13 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
|
|||
|
||||
func validationSuccessful() {
|
||||
print("Validation Success!")
|
||||
let alert = UIAlertController(title: "Success", message: "You are validated!", preferredStyle: UIAlertControllerStyle.Alert)
|
||||
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
|
||||
let alert = UIAlertController(title: "Success", message: "You are validated!", preferredStyle: UIAlertControllerStyle.alert)
|
||||
let defaultAction = UIAlertAction(title: "OK", style: .default, handler: nil)
|
||||
alert.addAction(defaultAction)
|
||||
self.presentViewController(alert, animated: true, completion: nil)
|
||||
self.present(alert, animated: true, completion: nil)
|
||||
|
||||
}
|
||||
func validationFailed(errors:[(Validatable, ValidationError)]) {
|
||||
func validationFailed(_ errors:[(Validatable, ValidationError)]) {
|
||||
print("Validation FAILED!")
|
||||
}
|
||||
|
||||
|
|
@ -85,7 +85,7 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
|
|||
|
||||
// MARK: Validate single field
|
||||
// Don't forget to use UITextFieldDelegate
|
||||
func textFieldShouldReturn(textField: UITextField) -> Bool {
|
||||
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
|
||||
validator.validateField(textField){ error in
|
||||
if error == nil {
|
||||
// Field validation was successful
|
||||
|
|
@ -96,4 +96,4 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
|
|||
return true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue