-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Improvement] Minor Updates For Usability
- Loading branch information
Showing
30 changed files
with
707 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
macaroon/Classes/Form/Utils/Validator/FixedCharacterCountValidator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright © 2019 hipolabs. All rights reserved. | ||
|
||
import Foundation | ||
|
||
public struct FixedCharacterCountValidator: Validator { | ||
public let count: Int | ||
public let failureReason: String | ||
|
||
public init( | ||
_ count: Int, | ||
_ failureReason: String = "" | ||
) { | ||
self.count = count | ||
self.failureReason = failureReason | ||
} | ||
|
||
public func validate( | ||
_ inputFieldView: FormInputFieldView | ||
) -> Validation { | ||
guard let textInputFieldView = inputFieldView as? FormTextInputFieldView else { | ||
return .failure(failureReason) | ||
} | ||
|
||
return validate( | ||
textInputFieldView.text | ||
) | ||
} | ||
|
||
public func validate( | ||
_ text: String? | ||
) -> Validation { | ||
guard | ||
let text = text, | ||
text.count == count | ||
else { | ||
return .failure(failureReason) | ||
} | ||
|
||
return .success | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
macaroon/Classes/Form/Utils/Validator/RegexValidator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright © 2019 hipolabs. All rights reserved. | ||
|
||
import Foundation | ||
|
||
public struct RegexValidator: Validator { | ||
public let regex: String | ||
public let failureReason: String | ||
|
||
public init( | ||
_ regex: String, | ||
_ failureReason: String = "" | ||
) { | ||
self.regex = regex | ||
self.failureReason = failureReason | ||
} | ||
|
||
public func validate( | ||
_ inputFieldView: FormInputFieldView | ||
) -> Validation { | ||
guard let textInputFieldView = inputFieldView as? FormTextInputFieldView else { | ||
return .failure(failureReason) | ||
} | ||
|
||
return validate( | ||
textInputFieldView.text | ||
) | ||
} | ||
|
||
public func validate( | ||
_ text: String? | ||
) -> Validation { | ||
guard | ||
let text = text, | ||
!text.isEmpty | ||
else { | ||
return .failure(failureReason) | ||
} | ||
|
||
guard let regexExpr = try? NSRegularExpression(pattern: regex) else { | ||
return .success | ||
} | ||
|
||
let range = NSRange(text.startIndex..<text.endIndex, in: text) | ||
let matches = regexExpr.matches(in: text, options: [.anchored], range: range) | ||
|
||
switch matches.count { | ||
case 1: return .success | ||
default: return .failure(failureReason) | ||
} | ||
} | ||
} |
Oops, something went wrong.