Skip to content

Commit

Permalink
Fixes to support Xcode Beta 6
Browse files Browse the repository at this point in the history
  • Loading branch information
ed-mejia committed Aug 17, 2016
1 parent 8339c8c commit 90e141e
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 23 deletions.
26 changes: 13 additions & 13 deletions SwiftValidator/Core/Validator.swift
Expand Up @@ -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(){}

Expand All @@ -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)
}
}
}
Expand All @@ -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)
}
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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) } )
}
}
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/CharacterSetRule.swift
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/ExactLengthRule.swift
Expand Up @@ -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)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions SwiftValidator/Rules/ISBNRule.swift
Expand Up @@ -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 {
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/MaxLengthRule.swift
Expand Up @@ -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)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion SwiftValidator/Rules/MinLengthRule.swift
Expand Up @@ -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)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions SwiftValidator/Rules/ValidationRule.swift
Expand Up @@ -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
}
}
}
2 changes: 1 addition & 1 deletion SwiftValidatorTests/SwiftValidatorTests.swift
Expand Up @@ -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'")
}
}

Expand Down
2 changes: 1 addition & 1 deletion Validator/AppDelegate.swift
Expand Up @@ -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
}
Expand Down

0 comments on commit 90e141e

Please sign in to comment.