Fixes to support Xcode Beta 6
This commit is contained in:
parent
8339c8c086
commit
90e141e923
|
|
@ -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:((validationRule:ValidationRule)->Void)?, error:((validationError:ValidationError)->Void)?) {
|
||||
public func styleTransformers(success:((_ validationRule:ValidationRule)->Void)?, error:((_ validationError:ValidationError)->Void)?) {
|
||||
self.successStyleTransform = success
|
||||
self.errorStyleTransform = error
|
||||
}
|
||||
|
|
@ -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) } )
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class CharacterSetRule: Rule {
|
|||
*/
|
||||
public func validate(_ value: String) -> Bool {
|
||||
for uni in value.unicodeScalars {
|
||||
if !characterSet.contains(UnicodeScalar(uni.value)) {
|
||||
guard let uniVal = UnicodeScalar(uni.value), characterSet.contains(uniVal) else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ 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 {
|
||||
|
|
@ -171,7 +171,7 @@ 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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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'")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ 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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue