git.iko.soy/dashared/GDproject
on master help sign in
On my way to autocompleted hashtags.
commitf24ae333b62fb34488aa883c8c1e663fee8f81e6 authorDarya Rednikina <rednikina.com@yandex.ru> dateWed 1 May 2019, 23:00 (7 years ago) parentb47de10
4 files changed+63−1
GDproject.xcodeproj/project.pbxproj+4 GDproject/Simple model/CompletionTree.swift+43 GDproject/Simple model/Model.swift+13−1 GDproject/Supporting files/AppDelegate.swift+3
GDproject.xcodeproj/project.pbxproj+4
@@ -23,6 +23,7 @@
2323 129320072279B5690035C7B3 /* MessagesCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320062279B5690035C7B3 /* MessagesCoordinator.swift */; };
2424 129320092279C3B50035C7B3 /* PeopleToWriteViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */; };
2525 1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1293200A2279D02D0035C7B3 /* DialogViewController.swift */; };
26+ 1293200D2279D7310035C7B3 /* CompletionTree.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1293200C2279D7310035C7B3 /* CompletionTree.swift */; };
2627 12BA4B9B224101A400DF93D7 /* ApplicationCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */; };
2728 12BA4B9D224101E700DF93D7 /* BaseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */; };
2829 12BA4B9F224102B700DF93D7 /* LogInCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */; };
@@ -109,6 +110,7 @@
109110 129320062279B5690035C7B3 /* MessagesCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesCoordinator.swift; sourceTree = "<group>"; };
110111 129320082279C3B50035C7B3 /* PeopleToWriteViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PeopleToWriteViewController.swift; path = GDproject/Controller/Messages/PeopleToWriteViewController.swift; sourceTree = SOURCE_ROOT; };
111112 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>"; };
112114 12BA4B9A224101A400DF93D7 /* ApplicationCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApplicationCoordinator.swift; sourceTree = "<group>"; };
113115 12BA4B9C224101E700DF93D7 /* BaseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseCoordinator.swift; sourceTree = "<group>"; };
114116 12BA4B9E224102B700DF93D7 /* LogInCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogInCoordinator.swift; sourceTree = "<group>"; };
@@ -263,6 +265,7 @@
263265 isa = PBXGroup;
264266 children = (
265267 124CC7022221C00C009DF531 /* Model.swift */,
268+ 1293200C2279D7310035C7B3 /* CompletionTree.swift */,
266269 12E36DB62214400A006FCDD7 /* Post.swift */,
267270 12D7D136221D78E800B35452 /* Channel.swift */,
268271 );
@@ -402,6 +405,7 @@
402405 12E36DB72214400A006FCDD7 /* Post.swift in Sources */,
403406 12DB7FDF221877160096878E /* InviteViewController.swift in Sources */,
404407 121A8972226B1EAC005EE599 /* AnonimousChannelController.swift in Sources */,
408+ 1293200D2279D7310035C7B3 /* CompletionTree.swift in Sources */,
405409 1293200B2279D02D0035C7B3 /* DialogViewController.swift in Sources */,
406410 12E36DCA22144635006FCDD7 /* NewPostViewController.swift in Sources */,
407411 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{
1414
1515 static let invalidTocken = 498
1616
17+ static var hashTagTree: CompletionTree?
18+
1719 private static var isValidTocken: ((Int)->())? = { responce in
1820 print(responce)
1921 if responce == invalidTocken {
@@ -38,6 +40,7 @@ class Model{
3840 static let channelsDeleteURL = URL(string: "\(baseUrl)/channels/delete")!
3941 static let channelsGetAnonURL = URL(string: "\(baseUrl)/channels/getAnonymous")!
4042 static let complexURL = URL(string: "\(baseUrl)/complex")!
43+ static let hashTagTreeURL = URL(string: "\(baseUrl)/tagCompletions")!
4144
4245 struct QueryPosts: Codable {
4346 var users: [Int: Users]
@@ -522,6 +525,15 @@ class Model{
522525 }
523526 }
524527
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+ }
526538
527539}
GDproject/Supporting files/AppDelegate.swift+3
@@ -22,6 +22,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2222 window?.makeKeyAndVisible()
2323
2424 // window?.rootViewController = UINavigationController()
25+ Model.getCompl { (complTree) in
26+ Model.hashTagTree = complTree
27+ }
2528
2629 appCoordinator = ApplicationCoordinator(window: window!)
2730 appCoordinator.start()