From 449e1beb017d5e23300c82be549513d4823ae97d Mon Sep 17 00:00:00 2001 From: Panayot Panayotov Date: Wed, 30 May 2018 12:04:06 +0100 Subject: [PATCH] Minor changes and adding some documentation --- InputValidation.xcodeproj/project.pbxproj | 28 +++--- .../xcschemes/InputValidation macOS.xcscheme | 4 +- .../xcschemes/InputValidation tvOS.xcscheme | 4 +- .../xcschemes/InputValidation.xcscheme | 4 +- InputValidation/InputValue.swift | 86 +++++++++++++++---- 5 files changed, 85 insertions(+), 41 deletions(-) diff --git a/InputValidation.xcodeproj/project.pbxproj b/InputValidation.xcodeproj/project.pbxproj index c20525b..78af98b 100644 --- a/InputValidation.xcodeproj/project.pbxproj +++ b/InputValidation.xcodeproj/project.pbxproj @@ -14,14 +14,13 @@ 5A043BEB1F753C460021149B /* InputValidation_macOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A043BE21F753C460021149B /* InputValidation_macOS.framework */; }; 5A043BF01F753C460021149B /* InputValidation_macOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BEF1F753C460021149B /* InputValidation_macOSTests.swift */; }; 5A043BF21F753C470021149B /* InputValidation_macOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A043BE41F753C460021149B /* InputValidation_macOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5A043BF91F753C700021149B /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BDB1F753B770021149B /* InputValue.swift */; }; - 5A043BFA1F753C730021149B /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BDB1F753B770021149B /* InputValue.swift */; }; - 5A043BFB1F753C740021149B /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BDB1F753B770021149B /* InputValue.swift */; }; 5A043C0B1F753DBA0021149B /* InputValidation_tvOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5A043C021F753DBA0021149B /* InputValidation_tvOS.framework */; }; 5A043C101F753DBA0021149B /* InputValidation_tvOSTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043C0F1F753DBA0021149B /* InputValidation_tvOSTests.swift */; }; 5A043C121F753DBA0021149B /* InputValidation_tvOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5A043C041F753DBA0021149B /* InputValidation_tvOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 5A043C1A1F753DC50021149B /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BDB1F753B770021149B /* InputValue.swift */; }; - 5A043C1B1F753DC50021149B /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BDB1F753B770021149B /* InputValue.swift */; }; + 5A7A02AC20BEBB0C00CCB76C /* InputValidationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043B891F7510880021149B /* InputValidationTests.swift */; }; + 5A7A02AD20BEBB0D00CCB76C /* InputValidationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043B891F7510880021149B /* InputValidationTests.swift */; }; + 5A7A02AE20BEBB1E00CCB76C /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BDB1F753B770021149B /* InputValue.swift */; }; + 5A7A02AF20BEBB1F00CCB76C /* InputValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5A043BDB1F753B770021149B /* InputValue.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -345,7 +344,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0900; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = "Panayot Panayotov"; TargetAttributes = { 5A043B7A1F7510880021149B = { @@ -455,7 +454,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5A043BFA1F753C730021149B /* InputValue.swift in Sources */, 5A043B8A1F7510880021149B /* InputValidationTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -464,7 +462,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5A043BF91F753C700021149B /* InputValue.swift in Sources */, + 5A7A02AE20BEBB1E00CCB76C /* InputValue.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -472,8 +470,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5A043BFB1F753C740021149B /* InputValue.swift in Sources */, 5A043BF01F753C460021149B /* InputValidation_macOSTests.swift in Sources */, + 5A7A02AC20BEBB0C00CCB76C /* InputValidationTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -481,7 +479,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5A043C1A1F753DC50021149B /* InputValue.swift in Sources */, + 5A7A02AF20BEBB1F00CCB76C /* InputValue.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -489,8 +487,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 5A043C1B1F753DC50021149B /* InputValue.swift in Sources */, 5A043C101F753DBA0021149B /* InputValidation_tvOSTests.swift in Sources */, + 5A7A02AD20BEBB0D00CCB76C /* InputValidationTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -529,6 +527,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -536,6 +535,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -589,6 +589,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -596,6 +597,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -708,7 +710,7 @@ 5A043BF41F753C470021149B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; @@ -732,7 +734,7 @@ 5A043BF51F753C470021149B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; diff --git a/InputValidation.xcodeproj/xcshareddata/xcschemes/InputValidation macOS.xcscheme b/InputValidation.xcodeproj/xcshareddata/xcschemes/InputValidation macOS.xcscheme index e9f0826..69e660a 100644 --- a/InputValidation.xcodeproj/xcshareddata/xcschemes/InputValidation macOS.xcscheme +++ b/InputValidation.xcodeproj/xcshareddata/xcschemes/InputValidation macOS.xcscheme @@ -1,6 +1,6 @@ = min && <= max' func isBetween(min: T, max: T) -> Bool + + /// Logical comparison to check if this InputValue is + /// less than the reference value passed as an argument + /// + /// - Parameter test: Reference value used for comparison + /// - Returns: True if this InputValue is less than the reference. Example 'result = this < reference' func isLessThan(test: T) -> Bool + + /// Logical comparison to check if this InputValue is + /// less than or equal to the reference value passed as an argument + /// + /// - Parameter test: Reference value used for comparison + /// - Returns: True if this InputValue is less than or equal to the reference. Example 'result = this <= reference' func isLessThanOrEqualTo(test: T) -> Bool + + /// Logical comparison to check if this InputValue is + /// greater than the reference value passed as an argument + /// + /// - Parameter test: Reference value used for comparison + /// - Returns: True if this InputValue is greater than the reference. Example 'result = this > reference' func isGreaterThan(test: T) -> Bool + + /// Logical comparison to check if this InputValue is + /// greater than or equal to the reference value passed as an argument + /// + /// - Parameter test: Reference value used for comparison + /// - Returns: True if this InputValue is greater than or equal to the reference. Example 'result = this >= reference' func isGreaterThanOrEqualTo(test: T) -> Bool - + + /// Performs a RegEx evaluation on the current InputValue + /// + /// - Parameter regex: RegEx value. Example '^[\d]+$' will match only numbers + /// - Returns: True if RexEx evaluation was successfull func matches(regex: String) -> Bool } -public extension InputValue { - +extension InputValue { + public var isFloat: Bool { return self.type == .float } public var isBool: Bool { return self.type == .bool } public var isDouble: Bool { return self.type == .double } public var isNumber: Bool { return self.type == .number } public var isInt: Bool { return self.type == .int } public var isString: Bool { return self.type == .string } - public var toInt: Int? { return NumberFormatter().number(from: self.description)?.intValue } - public var toFloat: Float? { return NumberFormatter().number(from: self.description)?.floatValue } - public var toDouble: Double? { return NumberFormatter().number(from: self.description)?.doubleValue } + public var toInt: Int? { return NumberFormatter().number(from: self.toString)?.intValue } + public var toFloat: Float? { return NumberFormatter().number(from: self.toString)?.floatValue } + public var toDouble: Double? { return NumberFormatter().number(from: self.toString)?.doubleValue } public var toBool: Bool? { return nil } - public var toString: String { return self.description } - public var isEmpty: Bool { return self.description.replacingOccurrences(of: " ", with: "").characters.count == 0 } - + public var toString: String { return String(describing: self) } + public var isEmpty: Bool { return self.toString.replacingOccurrences(of: " ", with: "").count == 0 } + public func isBetween(min: T, max: X) -> Bool { guard let thisFloat = self.toFloat, let minFloat = min.toFloat, @@ -65,7 +113,7 @@ public extension InputValue { } return minFloat ... maxFloat ~= thisFloat } - + public func isLessThan(test: T) -> Bool { guard let thisFloat = self.toFloat, let testFloat = test.toFloat, @@ -76,7 +124,7 @@ public extension InputValue { } return thisFloat < testFloat } - + public func isLessThanOrEqualTo(test: T) -> Bool { guard let thisFloat = self.toFloat, let testFloat = test.toFloat, @@ -87,7 +135,7 @@ public extension InputValue { } return thisFloat <= testFloat } - + public func isGreaterThan(test: T) -> Bool { guard let thisFloat = self.toFloat, let testFloat = test.toFloat, @@ -98,7 +146,7 @@ public extension InputValue { } return thisFloat > testFloat } - + public func isGreaterThanOrEqualTo(test: T) -> Bool { guard let thisFloat = self.toFloat, let testFloat = test.toFloat, @@ -109,9 +157,9 @@ public extension InputValue { } return thisFloat >= testFloat } - + public func matches(regex: String) -> Bool { - return self.description.range(of: regex, options: .regularExpression, range: nil, locale: nil) != nil + return self.toString.range(of: regex, options: .regularExpression, range: nil, locale: nil) != nil } }