-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathTextHelper.swift
More file actions
44 lines (38 loc) · 1.29 KB
/
TextHelper.swift
File metadata and controls
44 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// TextHelper.swift
// PinCodeTextField
//
// Created by Alexander Tkachenko on 3/20/17.
// Copyright © 2017 organization. All rights reserved.
//
import Foundation
class TextHelper {
static let defaultSecureSymbol: Character = "•"
let text: String?
let placeholderText: String?
let isSecureTextEntry: Bool
let secureSymbol: Character
init(text: String?, placeholder: String?, isSecure: Bool, secureSymbol: String) {
self.text = text
self.placeholderText = placeholder
self.isSecureTextEntry = isSecure
self.secureSymbol = secureSymbol.first ?? TextHelper.defaultSecureSymbol
}
func character(atIndex i: Int) -> Character? {
let inputTextCount = text?.count ?? 0
let placeholderTextLength = placeholderText?.count ?? 0
let character: Character?
if i < inputTextCount {
let string = text ?? ""
character = isSecureTextEntry ? secureSymbol : string[string.index(string.startIndex, offsetBy: i)]
}
else if i < placeholderTextLength {
let string = placeholderText ?? ""
character = string[string.index(string.startIndex, offsetBy: i)]
}
else {
character = nil
}
return character
}
}