on master help sign in
Got data flowing though system
commit317137e9b8b47cb7df02e1b3b39debeff134a2a5 authorilyakooo0 <ilyakooo0@gmail.com> dateWed 19 Jul 2017, 00:37 (9 years ago) parente5e2465
8 files changed+89−41
Melk.xcodeproj/project.pbxproj+31−7 Melk/CardView.swift+1 Melk/MainCoordinator.swift+1 Melk/SecondaryCoordinator.swift+12−1 Melk/SecondaryViewController.swift+17−10 Melk/StreamingParser.swift+24−21 Melk/VKData.swift+1−1 Melk/VKServer.swift+2−1
Melk.xcodeproj/project.pbxproj+31−7
@@ -117,6 +117,34 @@
117117/* End PBXFrameworksBuildPhase section */
118118
119119/* Begin PBXGroup section */
120+ 098397F71F1E887F008C88DD /* Main */ = {
121+ isa = PBXGroup;
122+ children = (
123+ 09BF420F1F0833C100AFAD57 /* MainCoordinator.swift */,
124+ 09BF42551F08413000AFAD57 /* MainViewController.swift */,
125+ );
126+ name = Main;
127+ sourceTree = "<group>";
128+ };
129+ 098397F81F1E888F008C88DD /* Secondary */ = {
130+ isa = PBXGroup;
131+ children = (
132+ 09BF42311F08388100AFAD57 /* SecondaryCoordinator.swift */,
133+ 0919AEA61F0D3D9D00894FFA /* SecondaryViewController.swift */,
134+ );
135+ name = Secondary;
136+ sourceTree = "<group>";
137+ };
138+ 098397F91F1E88A3008C88DD /* Streaming */ = {
139+ isa = PBXGroup;
140+ children = (
141+ 09AFAB031F159C9200EBD200 /* StreamingService.swift */,
142+ 09F03F221F164E7E000CE916 /* StreamingParser.swift */,
143+ 09F0D79D1F129DCB00A13751 /* Streaming.swift */,
144+ );
145+ name = Streaming;
146+ sourceTree = "<group>";
147+ };
120148 09A456341F0ED98800BAC32D /* Public */ = {
121149 isa = PBXGroup;
122150 children = (
@@ -145,18 +173,14 @@
145173 09BF41ED1F07F71F00AFAD57 /* Melk */ = {
146174 isa = PBXGroup;
147175 children = (
176+ 098397F71F1E887F008C88DD /* Main */,
177+ 098397F81F1E888F008C88DD /* Secondary */,
178+ 098397F91F1E88A3008C88DD /* Streaming */,
148179 09BF41EE1F07F71F00AFAD57 /* AppDelegate.swift */,
149180 09BF42111F08341B00AFAD57 /* MyWeirdness.swift */,
150181 09BF42121F08341B00AFAD57 /* PublicCrap.swift */,
151− 09F0D79D1F129DCB00A13751 /* Streaming.swift */,
152− 09AFAB031F159C9200EBD200 /* StreamingService.swift */,
153− 09F03F221F164E7E000CE916 /* StreamingParser.swift */,
154182 09F03F351F1674ED000CE916 /* VKServer.swift */,
155− 09BF420F1F0833C100AFAD57 /* MainCoordinator.swift */,
156− 09BF42311F08388100AFAD57 /* SecondaryCoordinator.swift */,
157183 0919AEA81F0D459600894FFA /* CardView.swift */,
158− 0919AEA61F0D3D9D00894FFA /* SecondaryViewController.swift */,
159− 09BF42551F08413000AFAD57 /* MainViewController.swift */,
160184 09939A551F097DA90014719D /* TableViewCells.swift */,
161185 09BF420D1F0833A700AFAD57 /* LocalVKDataTypes.swift */,
162186 09BF42151F0834D400AFAD57 /* VKPublicCrap.swift */,
Melk/CardView.swift+1
@@ -12,6 +12,7 @@ class CardView: UIView {
1212
1313 var post: WallPost? {
1414 didSet {
15+ print(post?.owner)
1516 update()
1617 }
1718 }
Melk/MainCoordinator.swift+1
@@ -29,6 +29,7 @@ class MainCoordinator {
2929 navC = UINavigationController(rootViewController: mainVC)
3030 updateScreens()
3131 stream.handleResult = { result in
32+ self.secondaryCoord.add(result: result)
3233// switch result {
3334// case .post(let post):
3435//
Melk/SecondaryCoordinator.swift+12−1
@@ -12,18 +12,29 @@ class SecondaryCoordinator {
1212
1313 var windows: [UIWindow] = []
1414
15+ func add(result: StreamingServiceResult) {
16+ for vc in VCs {
17+ vc.add(result: result)
18+ }
19+ }
20+
1521 init() {
1622
1723 }
1824
25+ private var VCs: [SecondaryViewController] = []
26+
1927 func updateScreens() {
2028 windows.removeAll()
29+ VCs.removeAll()
2130 for screen in UIScreen.screens.dropFirst() {
2231 let window = UIWindow(frame: screen.bounds)
2332 window.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
2433 window.screen = screen
2534 window.isHidden = false
26− window.rootViewController = SecondaryViewController()
35+ let VC = SecondaryViewController()
36+ VCs.append(VC)
37+ window.rootViewController = VC
2738 windows.append(window)
2839 }
2940 }
Melk/SecondaryViewController.swift+17−10
@@ -9,29 +9,36 @@
99import UIKit
1010
1111class SecondaryViewController: UIViewController {
12+
1213 init() {
1314 super.init(nibName: nil, bundle: nil)
14− self.view = SecondaryView(frame: view.bounds)
15+ self.view = sView
16+ }
17+
18+ func add(result: StreamingServiceResult) {
19+ sView.add(result: result)
1520 }
1621
1722 required init?(coder aDecoder: NSCoder) {
1823 fatalError("init(coder:) has not been implemented")
1924 }
25+
26+ private let sView = SecondaryView()
2027}
2128
2229class SecondaryView: UIView {
30+ func add(result: StreamingServiceResult) {
31+ switch result {
32+ case .post(let post):
33+ card.post = post
34+ }
35+ }
36+
37+ let card = CardView(frame: CGRect(x: 20, y: 20, width: 600, height: 300))
38+
2339 override init(frame: CGRect) {
2440 super.init(frame: frame)
25−
26− let card = CardView(frame: CGRect(x: 20, y: 20, width: 600, height: 300))
27− let post = WallPost()
28− post.owner = User()
29− post.owner?.firstName = "David"
30− post.owner?.avatar = RealmPhoto()
31− post.owner?.avatar?.imageSURL = "https://static.independent.co.uk/s3fs-public/styles/article_small/public/thumbnails/image/2017/04/01/17/twitter-egg.jpg"
32− card.post = post
3341 addSubview(card)
34−
3542 }
3643
3744 required init?(coder aDecoder: NSCoder) {
Melk/StreamingParser.swift+24−21
@@ -21,28 +21,23 @@ class StreamingParser {
2121 let postID: WallPostID = try eventID => "post_id"
2222 let ownerID: UserID = try eventID => "post_owner_id"
2323 // let
24+ var post: WallPost!
25+ var comp = 2
2426 realmWrite { _ in
25− let post = WallPost.by(id: postID)
27+ post = WallPost.by(id: postID)
2628 post.owner = User.by(id: ownerID)
27− var comp = 2
28− let complete = {
29− comp -= 1
30− if comp == 0 {
31− completion(.post(post))
32− }
33− }
3429 switch eventType {
3530 case "post":
3631 break
3732 case "comment":
3833 /*
39− if let id: Int = try? eventID => "comment_id" {
40− let comment = WallPostReply.by(id: id)
41− comment.wallPost = post
42− comp += 1
43− comment // TODO: get comment
44− }
45− */
34+ if let id: Int = try? eventID => "comment_id" {
35+ let comment = WallPostReply.by(id: id)
36+ comment.wallPost = post
37+ comp += 1
38+ comment // TODO: get comment
39+ }
40+ */
4641 print("comment not implemented")
4742
4843 case "share":
@@ -50,13 +45,21 @@ class StreamingParser {
5045 default:
5146 print("error:\n\(json)")
5247 }
53− post.owner?.get(completion: { (_) in
54− complete()
55− })
56− post.get(completion: { (_) in
57− complete()
58− })
5948 }
49+// print(post.owner)
50+ let complete = {
51+ comp -= 1
52+ if comp == 0 {
53+ print(post.owner)
54+ completion(.post(post))
55+ }
56+ }
57+ post.owner?.get(completion: { (_) in
58+ complete()
59+ })
60+ post.get(completion: { (_) in
61+ complete()
62+ })
6063 break // handle event
6164 case 300:
6265 break // handle service message
Melk/VKData.swift+1−1
@@ -430,7 +430,7 @@ class VKData {
430430 var post: WallPost!
431431 realmWrite { _ in
432432 post = WallPost.by(id: id)
433− post.owner = json["to_id"].int >>> {User.by(id: $0)}
433+ post.owner = json["owner_id"].int >>> {User.by(id: $0)}
434434 post.creator = json["from_id"].int >>> {User.by(id: $0)}
435435 post.date = json["date"].int >>> {Date.init(timeIntervalSince1970: TimeInterval($0))}
436436 post.body = json["text"].string
Melk/VKServer.swift+2−1
@@ -80,7 +80,8 @@ class VKServer {
8080 static func get(user: User, completion: @escaping ((Data) -> ())) {
8181 let id = user.id
8282 let params: Parameters = [
83− "user_ids": id
83+ "user_ids": id,
84+ "fields": "photo_max"
8485 ]
8586 Alamofire.request(url(for: "users.get"), parameters: params)
8687 .validate().responseData { (response) in