diff --git a/Examples/Core/Content.playground/Contents.swift b/Examples/Core/Content.playground/Contents.swift index ccbd049..a563b38 100644 --- a/Examples/Core/Content.playground/Contents.swift +++ b/Examples/Core/Content.playground/Contents.swift @@ -5,7 +5,7 @@ import ValidatorCore -// 1. LengthValidationRule - validates string length +/// 1. LengthValidationRule - validates string length let lengthRule = LengthValidationRule(min: 3, max: 20, error: "Length must be 3-20 characters") let shortString = "ab" @@ -18,7 +18,7 @@ print("'\(validString)' is valid: \(lengthRule.validate(input: validString))") / print("'\(longString)' is valid: \(lengthRule.validate(input: longString))") // false print() -// 2. NonEmptyValidationRule - checks if string is not empty +/// 2. NonEmptyValidationRule - checks if string is not empty let nonEmptyRule = NonEmptyValidationRule(error: "Field is required") let emptyString = "" @@ -31,7 +31,7 @@ print("'\(whitespaceString)' is valid: \(nonEmptyRule.validate(input: whitespace print("'\(filledString)' is valid: \(nonEmptyRule.validate(input: filledString))") // true print() -// 3. PrefixValidationRule - validates string prefix +/// 3. PrefixValidationRule - validates string prefix let prefixRule = PrefixValidationRule(prefix: "https://", error: "URL must start with https://") let httpURL = "http://example.com" @@ -44,7 +44,7 @@ print("'\(httpsURL)' is valid: \(prefixRule.validate(input: httpsURL))") // true print("'\(noProtocol)' is valid: \(prefixRule.validate(input: noProtocol))") // false print() -// 4. SuffixValidationRule - validates string suffix +/// 4. SuffixValidationRule - validates string suffix let suffixRule = SuffixValidationRule(suffix: ".com", error: "Domain must end with .com") let comDomain = "example.com" @@ -57,7 +57,7 @@ print("'\(orgDomain)' is valid: \(suffixRule.validate(input: orgDomain))") // fa print("'\(noDomain)' is valid: \(suffixRule.validate(input: noDomain))") // false print() -// 5. RegexValidationRule - validates using regular expression +/// 5. RegexValidationRule - validates using regular expression let phoneRule = RegexValidationRule(pattern: "^\\d{3}-\\d{4}$", error: "Invalid phone format") let validPhone = "123-4567" @@ -70,7 +70,7 @@ print("'\(invalidPhone1)' is valid: \(phoneRule.validate(input: invalidPhone1))" print("'\(invalidPhone2)' is valid: \(phoneRule.validate(input: invalidPhone2))") // false print() -// 6. URLValidationRule - validates URL format +/// 6. URLValidationRule - validates URL format let urlRule = URLValidationRule(error: "Please enter a valid URL") let validURL = "https://www.apple.com" @@ -83,7 +83,7 @@ print("'\(invalidURL)' is valid: \(urlRule.validate(input: invalidURL))") // fal print("'\(localURL)' is valid: \(urlRule.validate(input: localURL))") // true print() -// 7. CreditCardValidationRule - validates credit card number (Luhn algorithm) +/// 7. CreditCardValidationRule - validates credit card number (Luhn algorithm) let cardRule = CreditCardValidationRule(error: "Invalid card number") let validCard = "4532015112830366" // Valid Visa test number @@ -96,7 +96,7 @@ print("'\(invalidCard)' is valid: \(cardRule.validate(input: invalidCard))") // print("'\(shortCard)' is valid: \(cardRule.validate(input: shortCard))") // false print() -// 8. EmailValidationRule - validates email format +/// 8. EmailValidationRule - validates email format let emailRule = EmailValidationRule(error: "Please enter a valid email") let validEmail = "user@example.com" @@ -109,7 +109,7 @@ print("'\(invalidEmail1)' is valid: \(emailRule.validate(input: invalidEmail1))" print("'\(invalidEmail2)' is valid: \(emailRule.validate(input: invalidEmail2))") // false print() -// 9. CharactersValidationRule - validates allowed characters +/// 9. CharactersValidationRule - validates allowed characters let lettersRule = CharactersValidationRule(characterSet: .letters, error: "Invalid characters") let onlyLetters = "HelloWorld" @@ -122,7 +122,7 @@ print("'\(withNumbers)' is valid: \(lettersRule.validate(input: withNumbers))") print("'\(withSpaces)' is valid: \(lettersRule.validate(input: withSpaces))") // false print() -// 10. NilValidationRule - validates that value is nil +/// 10. NilValidationRule - validates that value is nil let nilRule = NilValidationRule(error: "Value must be nil") let nilValue: String? = nil diff --git a/Examples/Core/PlaygroundDependencies/Tests/PlaygroundDependenciesTests/PlaygroundDependenciesTests.swift b/Examples/Core/PlaygroundDependencies/Tests/PlaygroundDependenciesTests/PlaygroundDependenciesTests.swift index df2b80e..21d5a0c 100644 --- a/Examples/Core/PlaygroundDependencies/Tests/PlaygroundDependenciesTests/PlaygroundDependenciesTests.swift +++ b/Examples/Core/PlaygroundDependencies/Tests/PlaygroundDependenciesTests/PlaygroundDependenciesTests.swift @@ -6,6 +6,6 @@ @testable import PlaygroundDependencies import Testing -@Test func example() async throws { +@Test func example() { // Write your test here and use APIs like `#expect(...)` to check expected conditions. } diff --git a/Examples/UIKit/UIKitExample/ViewControllers/LoginTextFieldExampleViewController.swift b/Examples/UIKit/UIKitExample/ViewControllers/LoginTextFieldExampleViewController.swift index 936913d..faec82f 100644 --- a/Examples/UIKit/UIKitExample/ViewControllers/LoginTextFieldExampleViewController.swift +++ b/Examples/UIKit/UIKitExample/ViewControllers/LoginTextFieldExampleViewController.swift @@ -10,7 +10,7 @@ import ValidatorUI final class LoginTextFieldExampleViewController: UIViewController { // MARK: - Properties - // UI + /// UI private let scrollView: UIScrollView = { let scrollView = UIScrollView() scrollView.translatesAutoresizingMaskIntoConstraints = false @@ -67,7 +67,7 @@ final class LoginTextFieldExampleViewController: UIViewController { return stackView }() - // Private properties + /// Private properties private var isValid: Bool { [firstNameTextField, lastNameTextField, emailTextField] .allSatisfy { $0.validationResult == .valid } diff --git a/Sources/ValidatorCore/Classes/Core/Interfaces/IValidationError.swift b/Sources/ValidatorCore/Classes/Core/Interfaces/IValidationError.swift index b3ad591..5213ebc 100644 --- a/Sources/ValidatorCore/Classes/Core/Interfaces/IValidationError.swift +++ b/Sources/ValidatorCore/Classes/Core/Interfaces/IValidationError.swift @@ -5,6 +5,8 @@ import Foundation +// MARK: - IValidationError + /// `IValidationError` is the protocol representing a validation error in `ValidatorCore`. /// Any type conforming to `IValidationError` can be returned when validation fails. /// @@ -14,7 +16,13 @@ import Foundation /// var message: String { "Invalid input" } /// } /// ``` -public protocol IValidationError: Error { +public protocol IValidationError: LocalizedError { /// A human-readable error message describing why validation failed. var message: String { get } } + +public extension IValidationError { + var errorDescription: String? { + message + } +} diff --git a/Sources/ValidatorCore/Classes/Extensions/String+IValidationError.swift b/Sources/ValidatorCore/Classes/Extensions/String+IValidationError.swift index 5822a16..6b44fca 100644 --- a/Sources/ValidatorCore/Classes/Extensions/String+IValidationError.swift +++ b/Sources/ValidatorCore/Classes/Extensions/String+IValidationError.swift @@ -22,5 +22,7 @@ import Foundation /// ``` extension String: IValidationError { /// Returns the string itself as the error message. - public var message: String { self } + public var message: String { + self + } } diff --git a/Sources/ValidatorCore/Classes/Rules/URLValidationRule.swift b/Sources/ValidatorCore/Classes/Rules/URLValidationRule.swift index 02dbee2..f44ebf6 100644 --- a/Sources/ValidatorCore/Classes/Rules/URLValidationRule.swift +++ b/Sources/ValidatorCore/Classes/Rules/URLValidationRule.swift @@ -5,14 +5,14 @@ import Foundation -/// Validates that a string represents a valid URL. -/// -/// # Example: -/// ```swift -/// let rule = URLValidationRule(error: "Invalid URL") -/// rule.validate(input: "https://example.com") // true -/// rule.validate(input: "not_a_url") // false -/// ``` +// Validates that a string represents a valid URL. +// +// # Example: +// ```swift +// let rule = URLValidationRule(error: "Invalid URL") +// rule.validate(input: "https://example.com") // true +// rule.validate(input: "not_a_url") // false +// ``` public struct URLValidationRule: IValidationRule { // MARK: Types diff --git a/Sources/ValidatorUI/Classes/AppKit/Extensions/NSTextField+Validation.swift b/Sources/ValidatorUI/Classes/AppKit/Extensions/NSTextField+Validation.swift index aacecf7..d5e1e67 100644 --- a/Sources/ValidatorUI/Classes/AppKit/Extensions/NSTextField+Validation.swift +++ b/Sources/ValidatorUI/Classes/AppKit/Extensions/NSTextField+Validation.swift @@ -9,7 +9,9 @@ extension NSTextField: IUIValidatable { /// The value of the text field to validate. /// Returns an empty string if `text` is nil. - public var inputValue: String { stringValue } + public var inputValue: String { + stringValue + } /// The type of input for validation. public typealias Input = String diff --git a/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextField+Validation.swift b/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextField+Validation.swift index 790b385..9aeff82 100644 --- a/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextField+Validation.swift +++ b/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextField+Validation.swift @@ -9,7 +9,9 @@ extension UITextField: IUIValidatable { /// The value of the text field to validate. /// Returns an empty string if `text` is nil. - public var inputValue: String { text ?? "" } + public var inputValue: String { + text ?? "" + } /// The type of input for validation. public typealias Input = String diff --git a/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextView+Validation.swift b/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextView+Validation.swift index deef938..a2f6d1b 100644 --- a/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextView+Validation.swift +++ b/Sources/ValidatorUI/Classes/UIKit/Extensions/UITextView+Validation.swift @@ -9,7 +9,9 @@ extension UITextView: IUIValidatable { /// The value of the text view to validate. /// Returns an empty string if `text` is nil. - public var inputValue: String { text ?? "" } + public var inputValue: String { + text ?? "" + } /// The type of input for validation. public typealias Input = String