git.iko.soy/dashared/GDproject
on master help sign in
On my way to autocompleted hashtags.
f24ae33Darya Rednikina
GDproject.xcodeproj/project.pbxproj+4
@@ -23,6 +23,7 @@
23 129320072279B5690035C7B3 /* MessagesCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320062279B5690035C7B3 /* MessagesCoordinator.swift */; };
23 129320072279B5690035C7B3 /* MessagesCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320062279B5690035C7B3 /* MessagesCoordinator.swift */; };
24 129320092279C3B50035C7B3 /* PeopleToWriteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */; };
24 129320092279C3B50035C7B3 /* PeopleToWriteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */; };
25 1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1293200A2279D02D0035C7B3 /* DialogViewController.swift */; };
25 1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1293200A2279D02D0035C7B3 /* DialogViewController.swift */; };
26+ 1293200D2279D7310035C7B3 /* CompletionTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1293200C2279D7310035C7B3 /* CompletionTree.swift */; };
26 12BA4B9B224101A400DF93D7 /* ApplicationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */; };
27 12BA4B9B224101A400DF93D7 /* ApplicationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */; };
27 12BA4B9D224101E700DF93D7 /* BaseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */; };
28 12BA4B9D224101E700DF93D7 /* BaseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */; };
28 12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */; };
29 12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */; };
@@ -109,6 +110,7 @@
109 129320062279B5690035C7B3 /* MessagesCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesCoordinator.swift; sourceTree = "<group>"; };
110 129320062279B5690035C7B3 /* MessagesCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesCoordinator.swift; sourceTree = "<group>"; };
110 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PeopleToWriteViewController.swift; path = GDproject/Controller/Messages/PeopleToWriteViewController.swift; sourceTree = SOURCE_ROOT; };
111 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PeopleToWriteViewController.swift; path = GDproject/Controller/Messages/PeopleToWriteViewController.swift; sourceTree = SOURCE_ROOT; };
111 1293200A2279D02D0035C7B3 /* DialogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DialogViewController.swift; path = GDproject/Controller/Messages/DialogViewController.swift; sourceTree = SOURCE_ROOT; };
112 1293200A2279D02D0035C7B3 /* DialogViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = DialogViewController.swift; path = GDproject/Controller/Messages/DialogViewController.swift; sourceTree = SOURCE_ROOT; };
113+ 1293200C2279D7310035C7B3 /* CompletionTree.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CompletionTree.swift; sourceTree = "<group>"; };
112 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationCoordinator.swift; sourceTree = "<group>"; };
114 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationCoordinator.swift; sourceTree = "<group>"; };
113 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCoordinator.swift; sourceTree = "<group>"; };
115 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCoordinator.swift; sourceTree = "<group>"; };
114 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInCoordinator.swift; sourceTree = "<group>"; };
116 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInCoordinator.swift; sourceTree = "<group>"; };
@@ -263,6 +265,7 @@
263 isa = PBXGroup;
265 isa = PBXGroup;
264 children = (
266 children = (
265 124CC7022221C00C009DF531 /* Model.swift */,
267 124CC7022221C00C009DF531 /* Model.swift */,
268+ 1293200C2279D7310035C7B3 /* CompletionTree.swift */,
266 12E36DB62214400A006FCDD7 /* Post.swift */,
269 12E36DB62214400A006FCDD7 /* Post.swift */,
267 12D7D136221D78E800B35452 /* Channel.swift */,
270 12D7D136221D78E800B35452 /* Channel.swift */,
268 );
271 );
@@ -402,6 +405,7 @@
402 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
405 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
403 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
406 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
404 121A8972226B1EAC005EE599 /* AnonimousChannelController.swift in Sources */,
407 121A8972226B1EAC005EE599 /* AnonimousChannelController.swift in Sources */,
408+ 1293200D2279D7310035C7B3 /* CompletionTree.swift in Sources */,
405 1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */,
409 1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */,
406 12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */,
410 12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */,
407 12E36D9E221424EA006FCDD7 /* NewsController.swift in Sources */,
411 12E36D9E221424EA006FCDD7 /* NewsController.swift in Sources */,
GDproject/Simple model/CompletionTree.swiftnew file+43
@@ -0,0 +1,43 @@
1+//
2+// CompletionTree.swift
3+// GDproject
4+//
5+// Created by cstore on 01/05/2019.
6+// Copyright © 2019 drHSE. All rights reserved.
7+//
8+
9+import Foundation
10+
11+
12+struct CompletionTree: Codable {
13+ var value: String?
14+ var subtree: [String : CompletionTree]
15+
16+ static func getCompletion(tree: CompletionTree, word: String) -> [String] {
17+ if word == "" {
18+ return getValues(tree: tree)
19+ }
20+
21+ let character = String(word.first!)
22+
23+ if tree.subtree[character] == nil {
24+ return []
25+ } else {
26+ return getCompletion(tree: tree.subtree[character]!, word: String(word.dropFirst()))
27+ }
28+ }
29+
30+ static func getValues(tree: CompletionTree) -> [String] {
31+ var out = [String]()
32+
33+ if let treeVal = tree.value {
34+ out.append(treeVal)
35+ }
36+
37+ for (_, subtree) in tree.subtree {
38+ out += getValues(tree: subtree)
39+ }
40+
41+ return out
42+ }
43+}
GDproject/Simple model/Model.swift+13−1
@@ -14,6 +14,8 @@ class Model{
14
14
15 static let invalidTocken = 498
15 static let invalidTocken = 498
16
16
17+ static var hashTagTree: CompletionTree?
18+
17 private static var isValidTocken: ((Int)->())? = { responce in
19 private static var isValidTocken: ((Int)->())? = { responce in
18 print(responce)
20 print(responce)
19 if responce == invalidTocken {
21 if responce == invalidTocken {
@@ -38,6 +40,7 @@ class Model{
38 static let channelsDeleteURL = URL(string: "\(baseUrl)/channels/delete")!
40 static let channelsDeleteURL = URL(string: "\(baseUrl)/channels/delete")!
39 static let channelsGetAnonURL = URL(string: "\(baseUrl)/channels/getAnonymous")!
41 static let channelsGetAnonURL = URL(string: "\(baseUrl)/channels/getAnonymous")!
40 static let complexURL = URL(string: "\(baseUrl)/complex")!
42 static let complexURL = URL(string: "\(baseUrl)/complex")!
43+ static let hashTagTreeURL = URL(string: "\(baseUrl)/tagCompletions")!
41
44
42 struct QueryPosts: Codable {
45 struct QueryPosts: Codable {
43 var users: [Int: Users]
46 var users: [Int: Users]
@@ -522,6 +525,15 @@ class Model{
522 }
525 }
523 }
526 }
524
527
525−
528+ static func getCompl(completion: @escaping ((CompletionTree)->())) {
529+
530+ AF.request(URLRequest(url: hashTagTreeURL)).responseJSON {
531+ (response) in
532+
533+ guard let json = response.data else { return }
534+ guard let tree = try? decoder.decode(CompletionTree.self, from: json) else { return }
535+ completion(tree)
536+ }
537+ }
526
538
527}
539}
GDproject/Supporting files/AppDelegate.swift+3
@@ -22,6 +22,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
22 window?.makeKeyAndVisible()
22 window?.makeKeyAndVisible()
23
23
24 // window?.rootViewController = UINavigationController()
24 // window?.rootViewController = UINavigationController()
25+ Model.getCompl { (complTree) in
26+ Model.hashTagTree = complTree
27+ }
25
28
26 appCoordinator = ApplicationCoordinator(window: window!)
29 appCoordinator = ApplicationCoordinator(window: window!)
27 appCoordinator.start()
30 appCoordinator.start()