on master help sign in
Got data flowing though system
317137eilyakooo0
Melk.xcodeproj/project.pbxproj+31−7
@@ -117,6 +117,34 @@
117/* End PBXFrameworksBuildPhase section */
117/* End PBXFrameworksBuildPhase section */
118
118
119/* Begin PBXGroup section */
119/* 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+ };
120 09A456341F0ED98800BAC32D /* Public */ = {
148 09A456341F0ED98800BAC32D /* Public */ = {
121 isa = PBXGroup;
149 isa = PBXGroup;
122 children = (
150 children = (
@@ -145,18 +173,14 @@
145 09BF41ED1F07F71F00AFAD57 /* Melk */ = {
173 09BF41ED1F07F71F00AFAD57 /* Melk */ = {
146 isa = PBXGroup;
174 isa = PBXGroup;
147 children = (
175 children = (
176+ 098397F71F1E887F008C88DD /* Main */,
177+ 098397F81F1E888F008C88DD /* Secondary */,
178+ 098397F91F1E88A3008C88DD /* Streaming */,
148 09BF41EE1F07F71F00AFAD57 /* AppDelegate.swift */,
179 09BF41EE1F07F71F00AFAD57 /* AppDelegate.swift */,
149 09BF42111F08341B00AFAD57 /* MyWeirdness.swift */,
180 09BF42111F08341B00AFAD57 /* MyWeirdness.swift */,
150 09BF42121F08341B00AFAD57 /* PublicCrap.swift */,
181 09BF42121F08341B00AFAD57 /* PublicCrap.swift */,
151− 09F0D79D1F129DCB00A13751 /* Streaming.swift */,
152− 09AFAB031F159C9200EBD200 /* StreamingService.swift */,
153− 09F03F221F164E7E000CE916 /* StreamingParser.swift */,
154 09F03F351F1674ED000CE916 /* VKServer.swift */,
182 09F03F351F1674ED000CE916 /* VKServer.swift */,
155− 09BF420F1F0833C100AFAD57 /* MainCoordinator.swift */,
156− 09BF42311F08388100AFAD57 /* SecondaryCoordinator.swift */,
157 0919AEA81F0D459600894FFA /* CardView.swift */,
183 0919AEA81F0D459600894FFA /* CardView.swift */,
158− 0919AEA61F0D3D9D00894FFA /* SecondaryViewController.swift */,
159− 09BF42551F08413000AFAD57 /* MainViewController.swift */,
160 09939A551F097DA90014719D /* TableViewCells.swift */,
184 09939A551F097DA90014719D /* TableViewCells.swift */,
161 09BF420D1F0833A700AFAD57 /* LocalVKDataTypes.swift */,
185 09BF420D1F0833A700AFAD57 /* LocalVKDataTypes.swift */,
162 09BF42151F0834D400AFAD57 /* VKPublicCrap.swift */,
186 09BF42151F0834D400AFAD57 /* VKPublicCrap.swift */,
Melk/CardView.swift+1
@@ -12,6 +12,7 @@ class CardView: UIView {
12
12
13 var post: WallPost? {
13 var post: WallPost? {
14 didSet {
14 didSet {
15+ print(post?.owner)
15 update()
16 update()
16 }
17 }
17 }
18 }
Melk/MainCoordinator.swift+1
@@ -29,6 +29,7 @@ class MainCoordinator {
29 navC = UINavigationController(rootViewController: mainVC)
29 navC = UINavigationController(rootViewController: mainVC)
30 updateScreens()
30 updateScreens()
31 stream.handleResult = { result in
31 stream.handleResult = { result in
32+ self.secondaryCoord.add(result: result)
32// switch result {
33// switch result {
33// case .post(let post):
34// case .post(let post):
34//
35//
Melk/SecondaryCoordinator.swift+12−1
@@ -12,18 +12,29 @@ class SecondaryCoordinator {
12
12
13 var windows: [UIWindow] = []
13 var windows: [UIWindow] = []
14
14
15+ func add(result: StreamingServiceResult) {
16+ for vc in VCs {
17+ vc.add(result: result)
18+ }
19+ }
20+
15 init() {
21 init() {
16
22
17 }
23 }
18
24
25+ private var VCs: [SecondaryViewController] = []
26+
19 func updateScreens() {
27 func updateScreens() {
20 windows.removeAll()
28 windows.removeAll()
29+ VCs.removeAll()
21 for screen in UIScreen.screens.dropFirst() {
30 for screen in UIScreen.screens.dropFirst() {
22 let window = UIWindow(frame: screen.bounds)
31 let window = UIWindow(frame: screen.bounds)
23 window.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
32 window.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
24 window.screen = screen
33 window.screen = screen
25 window.isHidden = false
34 window.isHidden = false
35+ let VC = SecondaryViewController()
36+ VCs.append(VC)
26− window.rootViewController = SecondaryViewController()
37+ window.rootViewController = VC
27 windows.append(window)
38 windows.append(window)
28 }
39 }
29 }
40 }
Melk/SecondaryViewController.swift+17−10
@@ -9,29 +9,36 @@
9import UIKit
9import UIKit
10
10
11class SecondaryViewController: UIViewController {
11class SecondaryViewController: UIViewController {
12+
12 init() {
13 init() {
13 super.init(nibName: nil, bundle: nil)
14 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)
15 }
20 }
16
21
17 required init?(coder aDecoder: NSCoder) {
22 required init?(coder aDecoder: NSCoder) {
18 fatalError("init(coder:) has not been implemented")
23 fatalError("init(coder:) has not been implemented")
19 }
24 }
25+
26+ private let sView = SecondaryView()
20}
27}
21
28
22class SecondaryView: UIView {
29class 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+
23 override init(frame: CGRect) {
39 override init(frame: CGRect) {
24 super.init(frame: frame)
40 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
33 addSubview(card)
41 addSubview(card)
34−
35 }
42 }
36
43
37 required init?(coder aDecoder: NSCoder) {
44 required init?(coder aDecoder: NSCoder) {
Melk/StreamingParser.swift+24−21
@@ -21,28 +21,23 @@ class StreamingParser {
21 let postID: WallPostID = try eventID => "post_id"
21 let postID: WallPostID = try eventID => "post_id"
22 let ownerID: UserID = try eventID => "post_owner_id"
22 let ownerID: UserID = try eventID => "post_owner_id"
23 // let
23 // let
24+ var post: WallPost!
25+ var comp = 2
24 realmWrite { _ in
26 realmWrite { _ in
25− let post = WallPost.by(id: postID)
27+ post = WallPost.by(id: postID)
26 post.owner = User.by(id: ownerID)
28 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− }
34 switch eventType {
29 switch eventType {
35 case "post":
30 case "post":
36 break
31 break
37 case "comment":
32 case "comment":
38 /*
33 /*
39− if let id: Int = try? eventID => "comment_id" {
34+ if let id: Int = try? eventID => "comment_id" {
40− let comment = WallPostReply.by(id: id)
35+ let comment = WallPostReply.by(id: id)
41− comment.wallPost = post
36+ comment.wallPost = post
42− comp += 1
37+ comp += 1
43− comment // TODO: get comment
38+ comment // TODO: get comment
44− }
39+ }
45− */
40+ */
46 print("comment not implemented")
41 print("comment not implemented")
47
42
48 case "share":
43 case "share":
@@ -50,13 +45,21 @@ class StreamingParser {
50 default:
45 default:
51 print("error:\n\(json)")
46 print("error:\n\(json)")
52 }
47 }
53− post.owner?.get(completion: { (_) in
54− complete()
55− })
56− post.get(completion: { (_) in
57− complete()
58− })
59 }
48 }
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+ })
60 break // handle event
63 break // handle event
61 case 300:
64 case 300:
62 break // handle service message
65 break // handle service message
Melk/VKData.swift+1−1
@@ -430,7 +430,7 @@ class VKData {
430 var post: WallPost!
430 var post: WallPost!
431 realmWrite { _ in
431 realmWrite { _ in
432 post = WallPost.by(id: id)
432 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)}
434 post.creator = json["from_id"].int >>> {User.by(id: $0)}
434 post.creator = json["from_id"].int >>> {User.by(id: $0)}
435 post.date = json["date"].int >>> {Date.init(timeIntervalSince1970: TimeInterval($0))}
435 post.date = json["date"].int >>> {Date.init(timeIntervalSince1970: TimeInterval($0))}
436 post.body = json["text"].string
436 post.body = json["text"].string
Melk/VKServer.swift+2−1
@@ -80,7 +80,8 @@ class VKServer {
80 static func get(user: User, completion: @escaping ((Data) -> ())) {
80 static func get(user: User, completion: @escaping ((Data) -> ())) {
81 let id = user.id
81 let id = user.id
82 let params: Parameters = [
82 let params: Parameters = [
83− "user_ids": id
83+ "user_ids": id,
84+ "fields": "photo_max"
84 ]
85 ]
85 Alamofire.request(url(for: "users.get"), parameters: params)
86 Alamofire.request(url(for: "users.get"), parameters: params)
86 .validate().responseData { (response) in
87 .validate().responseData { (response) in