Skip to content

Commit 0c26f4b

Browse files
committed
Setup classes and protocols
1 parent ae1ed26 commit 0c26f4b

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

CodeInputView.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
CE901F1E205AF28000C688DD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE901F1C205AF28000C688DD /* Main.storyboard */; };
1313
CE901F20205AF28000C688DD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CE901F1F205AF28000C688DD /* Assets.xcassets */; };
1414
CE901F23205AF28000C688DD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CE901F21205AF28000C688DD /* LaunchScreen.storyboard */; };
15+
CE901F2B205AF32600C688DD /* CodeInputView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE901F2A205AF32600C688DD /* CodeInputView.swift */; };
1516
/* End PBXBuildFile section */
1617

1718
/* Begin PBXFileReference section */
@@ -22,6 +23,7 @@
2223
CE901F1F205AF28000C688DD /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
2324
CE901F22205AF28000C688DD /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
2425
CE901F24205AF28000C688DD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
26+
CE901F2A205AF32600C688DD /* CodeInputView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeInputView.swift; sourceTree = "<group>"; };
2527
/* End PBXFileReference section */
2628

2729
/* Begin PBXFrameworksBuildPhase section */
@@ -60,6 +62,7 @@
6062
CE901F1F205AF28000C688DD /* Assets.xcassets */,
6163
CE901F21205AF28000C688DD /* LaunchScreen.storyboard */,
6264
CE901F24205AF28000C688DD /* Info.plist */,
65+
CE901F2A205AF32600C688DD /* CodeInputView.swift */,
6366
);
6467
path = CodeInputView;
6568
sourceTree = "<group>";
@@ -136,6 +139,7 @@
136139
isa = PBXSourcesBuildPhase;
137140
buildActionMask = 2147483647;
138141
files = (
142+
CE901F2B205AF32600C688DD /* CodeInputView.swift in Sources */,
139143
CE901F1B205AF28000C688DD /* ViewController.swift in Sources */,
140144
CE901F19205AF28000C688DD /* AppDelegate.swift in Sources */,
141145
);

CodeInputView/CodeInputView.swift

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// CodeInputView.swift
3+
// CodeInputView
4+
//
5+
// Created by Isa Aliev on 15.03.18.
6+
// Copyright © 2018 IA. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
protocol InputableField {
13+
func deleteValue()
14+
func setValue(_ newValue: String)
15+
func getValue() -> String
16+
func isEmpty() -> Bool
17+
}
18+
19+
class CodeInputField: UIView, InputableField {
20+
private var value: String?
21+
22+
func deleteValue() {
23+
value = ""
24+
}
25+
26+
func setValue(_ newValue: String) {
27+
value = newValue
28+
}
29+
30+
func getValue() -> String {
31+
return value ?? ""
32+
}
33+
34+
func isEmpty() -> Bool {
35+
return value == nil
36+
}
37+
}
38+
39+
class CodeInputView<T: InputableField&UIView>: UIView {
40+
var fields = [T]()
41+
var numberOfFields = 4
42+
43+
override func awakeFromNib() {
44+
super.awakeFromNib()
45+
46+
configure()
47+
}
48+
49+
override init(frame: CGRect) {
50+
super.init(frame: frame)
51+
52+
configure()
53+
}
54+
55+
required init?(coder aDecoder: NSCoder) {
56+
super.init(coder: aDecoder)
57+
58+
configure()
59+
}
60+
61+
override func layoutSubviews() {
62+
super.layoutSubviews()
63+
64+
layoutFields()
65+
}
66+
67+
private func configure() {
68+
guard fields.count != numberOfFields else { return }
69+
70+
for _ in 0..<numberOfFields {
71+
fields.append(T(frame: .zero))
72+
}
73+
}
74+
75+
private func layoutFields() {
76+
77+
}
78+
79+
var hasText: Bool {
80+
return false
81+
}
82+
83+
func insertText(_ text: String) {
84+
85+
}
86+
87+
func deleteBackward() {
88+
89+
}
90+
}
91+

0 commit comments

Comments
 (0)