From 8339c8c086216096a2e910903a1f599b405cdd8b Mon Sep 17 00:00:00 2001 From: ed-mejia Date: Mon, 8 Aug 2016 17:26:41 +1000 Subject: [PATCH 1/7] Fixes to support Swift 3 Xcode Beta 4 --- SwiftValidator/Core/Validatable.swift | 2 +- SwiftValidator/Core/ValidationDelegate.swift | 2 +- SwiftValidator/Core/Validator.swift | 12 +++---- SwiftValidator/Core/ValidatorDictionary.swift | 10 +++--- SwiftValidator/Rules/AlphaNumericRule.swift | 4 +-- SwiftValidator/Rules/AlphaRule.swift | 4 +-- SwiftValidator/Rules/CharacterSetRule.swift | 10 +++--- SwiftValidator/Rules/ConfirmRule.swift | 4 +-- SwiftValidator/Rules/ExactLengthRule.swift | 4 +-- SwiftValidator/Rules/FloatRule.swift | 4 +-- SwiftValidator/Rules/FullNameRule.swift | 4 +-- SwiftValidator/Rules/ISBNRule.swift | 32 +++++++++---------- SwiftValidator/Rules/MaxLengthRule.swift | 2 +- SwiftValidator/Rules/MinLengthRule.swift | 2 +- SwiftValidator/Rules/RegexRule.swift | 4 +-- SwiftValidator/Rules/RequiredRule.swift | 4 +-- SwiftValidator/Rules/Rule.swift | 2 +- SwiftValidatorTests/SwiftValidatorTests.swift | 10 +++--- Validator.xcodeproj/project.pbxproj | 23 ++++++++++++- .../xcschemes/SwiftValidator.xcscheme | 2 +- .../xcschemes/SwiftValidatorTests.xcscheme | 2 +- .../xcshareddata/xcschemes/Validator.xcscheme | 2 +- Validator/AppDelegate.swift | 12 +++---- Validator/ViewController.swift | 24 +++++++------- 24 files changed, 101 insertions(+), 80 deletions(-) diff --git a/SwiftValidator/Core/Validatable.swift b/SwiftValidator/Core/Validatable.swift index 6a37253..3ca537e 100644 --- a/SwiftValidator/Core/Validatable.swift +++ b/SwiftValidator/Core/Validatable.swift @@ -8,7 +8,7 @@ import Foundation -public typealias ValidatableField = protocol +public typealias ValidatableField = AnyObject & Validatable public protocol Validatable { diff --git a/SwiftValidator/Core/ValidationDelegate.swift b/SwiftValidator/Core/ValidationDelegate.swift index edda1ec..0e073ed 100644 --- a/SwiftValidator/Core/ValidationDelegate.swift +++ b/SwiftValidator/Core/ValidationDelegate.swift @@ -23,5 +23,5 @@ public protocol ValidationDelegate { - returns: No return value. */ - func validationFailed(errors: [(Validatable, ValidationError)]) + func validationFailed(_ errors: [(Validatable, ValidationError)]) } diff --git a/SwiftValidator/Core/Validator.swift b/SwiftValidator/Core/Validator.swift index 411316f..a7a1262 100644 --- a/SwiftValidator/Core/Validator.swift +++ b/SwiftValidator/Core/Validator.swift @@ -65,7 +65,7 @@ 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 @@ -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,7 +145,7 @@ 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() diff --git a/SwiftValidator/Core/ValidatorDictionary.swift b/SwiftValidator/Core/ValidatorDictionary.swift index baab892..e152b0f 100644 --- a/SwiftValidator/Core/ValidatorDictionary.swift +++ b/SwiftValidator/Core/ValidatorDictionary.swift @@ -8,7 +8,7 @@ import Foundation -public struct ValidatorDictionary : SequenceType { +public struct ValidatorDictionary : Sequence { private var innerDictionary: [ObjectIdentifier: T] = [:]; @@ -31,15 +31,15 @@ public struct ValidatorDictionary : 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 { - return innerDictionary.generate() + public func makeIterator() -> DictionaryIterator { + return innerDictionary.makeIterator() } } diff --git a/SwiftValidator/Rules/AlphaNumericRule.swift b/SwiftValidator/Rules/AlphaNumericRule.swift index d21dfe8..ba8f017 100644 --- a/SwiftValidator/Rules/AlphaNumericRule.swift +++ b/SwiftValidator/Rules/AlphaNumericRule.swift @@ -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) } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/AlphaRule.swift b/SwiftValidator/Rules/AlphaRule.swift index 963ea8c..3e9c4cd 100644 --- a/SwiftValidator/Rules/AlphaRule.swift +++ b/SwiftValidator/Rules/AlphaRule.swift @@ -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) } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/CharacterSetRule.swift b/SwiftValidator/Rules/CharacterSetRule.swift index cba73f0..01ec8b0 100644 --- a/SwiftValidator/Rules/CharacterSetRule.swift +++ b/SwiftValidator/Rules/CharacterSetRule.swift @@ -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) { + if !characterSet.contains(UnicodeScalar(uni.value)) { return false } } @@ -52,4 +52,4 @@ public class CharacterSetRule: Rule { public func errorMessage() -> String { return message } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/ConfirmRule.swift b/SwiftValidator/Rules/ConfirmRule.swift index 0df85f8..52f136d 100644 --- a/SwiftValidator/Rules/ConfirmRule.swift +++ b/SwiftValidator/Rules/ConfirmRule.swift @@ -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 } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/ExactLengthRule.swift b/SwiftValidator/Rules/ExactLengthRule.swift index c19d128..d5b2b33 100644 --- a/SwiftValidator/Rules/ExactLengthRule.swift +++ b/SwiftValidator/Rules/ExactLengthRule.swift @@ -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 } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/FloatRule.swift b/SwiftValidator/Rules/FloatRule.swift index 13dea82..cf30557 100644 --- a/SwiftValidator/Rules/FloatRule.swift +++ b/SwiftValidator/Rules/FloatRule.swift @@ -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 diff --git a/SwiftValidator/Rules/FullNameRule.swift b/SwiftValidator/Rules/FullNameRule.swift index 0d7a5c8..b9894e0 100644 --- a/SwiftValidator/Rules/FullNameRule.swift +++ b/SwiftValidator/Rules/FullNameRule.swift @@ -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 } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/ISBNRule.swift b/SwiftValidator/Rules/ISBNRule.swift index a9d724b..f715cdf 100644 --- a/SwiftValidator/Rules/ISBNRule.swift +++ b/SwiftValidator/Rules/ISBNRule.swift @@ -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 { + private 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 { + private 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 } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/MaxLengthRule.swift b/SwiftValidator/Rules/MaxLengthRule.swift index aea2b2a..43aa535 100644 --- a/SwiftValidator/Rules/MaxLengthRule.swift +++ b/SwiftValidator/Rules/MaxLengthRule.swift @@ -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 } diff --git a/SwiftValidator/Rules/MinLengthRule.swift b/SwiftValidator/Rules/MinLengthRule.swift index 300c5d3..e13a330 100644 --- a/SwiftValidator/Rules/MinLengthRule.swift +++ b/SwiftValidator/Rules/MinLengthRule.swift @@ -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 } diff --git a/SwiftValidator/Rules/RegexRule.swift b/SwiftValidator/Rules/RegexRule.swift index 3a4bbfe..697c626 100644 --- a/SwiftValidator/Rules/RegexRule.swift +++ b/SwiftValidator/Rules/RegexRule.swift @@ -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) } /** diff --git a/SwiftValidator/Rules/RequiredRule.swift b/SwiftValidator/Rules/RequiredRule.swift index 519cc06..ace8ee5 100644 --- a/SwiftValidator/Rules/RequiredRule.swift +++ b/SwiftValidator/Rules/RequiredRule.swift @@ -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 } -} \ No newline at end of file +} diff --git a/SwiftValidator/Rules/Rule.swift b/SwiftValidator/Rules/Rule.swift index 6d401ea..2f621c9 100644 --- a/SwiftValidator/Rules/Rule.swift +++ b/SwiftValidator/Rules/Rule.swift @@ -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. diff --git a/SwiftValidatorTests/SwiftValidatorTests.swift b/SwiftValidatorTests/SwiftValidatorTests.swift index c8a7574..1b063e9 100644 --- a/SwiftValidatorTests/SwiftValidatorTests.swift +++ b/SwiftValidatorTests/SwiftValidatorTests.swift @@ -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") } } } diff --git a/Validator.xcodeproj/project.pbxproj b/Validator.xcodeproj/project.pbxproj index 8a746c7..17b420c 100644 --- a/Validator.xcodeproj/project.pbxproj +++ b/Validator.xcodeproj/project.pbxproj @@ -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; diff --git a/Validator.xcodeproj/xcshareddata/xcschemes/SwiftValidator.xcscheme b/Validator.xcodeproj/xcshareddata/xcschemes/SwiftValidator.xcscheme index 9f3a7ff..b8b0c59 100644 --- a/Validator.xcodeproj/xcshareddata/xcschemes/SwiftValidator.xcscheme +++ b/Validator.xcodeproj/xcshareddata/xcschemes/SwiftValidator.xcscheme @@ -1,6 +1,6 @@ Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> 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:. } diff --git a/Validator/ViewController.swift b/Validator/ViewController.swift index 263f914..90c1a5d 100644 --- a/Validator/ViewController.swift +++ b/Validator/ViewController.swift @@ -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 } -} \ No newline at end of file +} From 90e141e923325137e8dfcb593595388aa66c8665 Mon Sep 17 00:00:00 2001 From: Edinson Mejia Date: Wed, 17 Aug 2016 23:10:13 +1000 Subject: [PATCH 2/7] Fixes to support Xcode Beta 6 --- SwiftValidator/Core/Validator.swift | 26 +++++++++---------- SwiftValidator/Rules/CharacterSetRule.swift | 2 +- SwiftValidator/Rules/ExactLengthRule.swift | 2 +- SwiftValidator/Rules/ISBNRule.swift | 4 +-- SwiftValidator/Rules/MaxLengthRule.swift | 2 +- SwiftValidator/Rules/MinLengthRule.swift | 2 +- SwiftValidator/Rules/ValidationRule.swift | 4 +-- SwiftValidatorTests/SwiftValidatorTests.swift | 2 +- Validator/AppDelegate.swift | 2 +- 9 files changed, 23 insertions(+), 23 deletions(-) diff --git a/SwiftValidator/Core/Validator.swift b/SwiftValidator/Core/Validator.swift index a7a1262..2553e47 100644 --- a/SwiftValidator/Core/Validator.swift +++ b/SwiftValidator/Core/Validator.swift @@ -20,9 +20,9 @@ public class Validator { /// Dictionary to hold fields by their object identifiers private var fields = ValidatorDictionary() /// 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) } ) } } diff --git a/SwiftValidator/Rules/CharacterSetRule.swift b/SwiftValidator/Rules/CharacterSetRule.swift index 01ec8b0..d897132 100644 --- a/SwiftValidator/Rules/CharacterSetRule.swift +++ b/SwiftValidator/Rules/CharacterSetRule.swift @@ -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 } } diff --git a/SwiftValidator/Rules/ExactLengthRule.swift b/SwiftValidator/Rules/ExactLengthRule.swift index d5b2b33..c9aae6d 100644 --- a/SwiftValidator/Rules/ExactLengthRule.swift +++ b/SwiftValidator/Rules/ExactLengthRule.swift @@ -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) } /** diff --git a/SwiftValidator/Rules/ISBNRule.swift b/SwiftValidator/Rules/ISBNRule.swift index f715cdf..6f8654f 100644 --- a/SwiftValidator/Rules/ISBNRule.swift +++ b/SwiftValidator/Rules/ISBNRule.swift @@ -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 diff --git a/SwiftValidator/Rules/MaxLengthRule.swift b/SwiftValidator/Rules/MaxLengthRule.swift index 43aa535..57d9b7b 100644 --- a/SwiftValidator/Rules/MaxLengthRule.swift +++ b/SwiftValidator/Rules/MaxLengthRule.swift @@ -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) } /** diff --git a/SwiftValidator/Rules/MinLengthRule.swift b/SwiftValidator/Rules/MinLengthRule.swift index e13a330..d9e161c 100644 --- a/SwiftValidator/Rules/MinLengthRule.swift +++ b/SwiftValidator/Rules/MinLengthRule.swift @@ -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) } /** diff --git a/SwiftValidator/Rules/ValidationRule.swift b/SwiftValidator/Rules/ValidationRule.swift index 9bf2655..ef8d306 100644 --- a/SwiftValidator/Rules/ValidationRule.swift +++ b/SwiftValidator/Rules/ValidationRule.swift @@ -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 } -} \ No newline at end of file +} diff --git a/SwiftValidatorTests/SwiftValidatorTests.swift b/SwiftValidatorTests/SwiftValidatorTests.swift index 1b063e9..fab19bc 100644 --- a/SwiftValidatorTests/SwiftValidatorTests.swift +++ b/SwiftValidatorTests/SwiftValidatorTests.swift @@ -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'") } } diff --git a/Validator/AppDelegate.swift b/Validator/AppDelegate.swift index 46a16ba..a68462f 100644 --- a/Validator/AppDelegate.swift +++ b/Validator/AppDelegate.swift @@ -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 } From 68fdfbdac067680cdc290776e7c3977380f514b0 Mon Sep 17 00:00:00 2001 From: ed-mejia Date: Thu, 18 Aug 2016 09:16:16 +1000 Subject: [PATCH 3/7] Updated travis osx_image to xcode8 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4c71cce..98fe3be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode7.1 +osx_image: xcode8 before_install: From 8bf185d820b0ec0ea7b270a0634005d5523f6ed1 Mon Sep 17 00:00:00 2001 From: ed-mejia Date: Thu, 18 Aug 2016 09:34:20 +1000 Subject: [PATCH 4/7] Updated travis OS and Simulator --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 98fe3be..ce31c91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ before_install: script: - 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 + - xcodebuild clean build test -project Validator.xcodeproj -scheme Validator -sdk iphonesimulator10.0 -destination "OS=10.0,name=iPhone 6" -enableCodeCoverage YES | xcpretty after_success: From 55f282fe923659ac70fd246537ec851dd518cf64 Mon Sep 17 00:00:00 2001 From: ed-mejia Date: Thu, 18 Aug 2016 10:43:40 +1000 Subject: [PATCH 5/7] Updated travis file config --- .travis.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ce31c91..173ea9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,15 +1,16 @@ language: objective-c osx_image: xcode8 +xcode_sdk: iphonesimulator10.0 +xcode_project: Validator.xcodeproj +xcode_scheme: Validator before_install: - gem install xcpretty --no-rdoc --no-ri --no-document --quiet script: - + - xcodebuild clean build test -project Validator.xcodeproj -scheme Validator -sdk iphonesimulator -enableCodeCoverage YES | xcpretty - pod lib lint - - xcodebuild clean build test -project Validator.xcodeproj -scheme Validator -sdk iphonesimulator10.0 -destination "OS=10.0,name=iPhone 6" -enableCodeCoverage YES | xcpretty - after_success: - bash <(curl -s https://codecov.io/bash) \ No newline at end of file From 4f6e77c0aad54c90958085bfbf28c1d600aa4c3d Mon Sep 17 00:00:00 2001 From: ed-mejia Date: Thu, 18 Aug 2016 11:24:56 +1000 Subject: [PATCH 6/7] Updated travis file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 173ea9d..dad16da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ before_install: - gem install xcpretty --no-rdoc --no-ri --no-document --quiet script: - - xcodebuild clean build test -project Validator.xcodeproj -scheme Validator -sdk iphonesimulator -enableCodeCoverage YES | xcpretty + - 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 after_success: From 2c68d3db95861af8afab5ae806d41144f1a6f499 Mon Sep 17 00:00:00 2001 From: David Patterson Date: Wed, 5 Oct 2016 00:41:18 -0500 Subject: [PATCH 7/7] updated cocoapods to 0.32.1 on travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index dad16da..761d5a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ 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: