-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathTextHelper.swift
More file actions
39 lines (35 loc) · 1.1 KB
/
TextHelper.swift
File metadata and controls
39 lines (35 loc) · 1.1 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
//
// TextHelper.swift
// PinCodeTextField
//
// Created by Alexander Tkachenko on 3/20/17.
// Copyright © 2017 organization. All rights reserved.
//
import Foundation
class TextHelper {
let text: String?
let placeholderText: String?
let isSecureTextEntry: Bool
init(text: String?, placeholder: String?, isSecure: Bool = false) {
self.text = text
self.placeholderText = placeholder
self.isSecureTextEntry = isSecure
}
func character(atIndex i: Int) -> Character? {
let inputTextCount = text?.length ?? 0
let placeholderTextLength = placeholderText?.length ?? 0
let character: Character?
if i < inputTextCount {
let string = text ?? ""
character = isSecureTextEntry ? "•" : 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
}
}