Skip to content

Commit af8271c

Browse files
Parsed Data from Firebase to InterestVC -> Model InterestFIR +
1 parent c8b223b commit af8271c

File tree

10 files changed

+355
-27
lines changed

10 files changed

+355
-27
lines changed

CompassIO.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
6E9123E51E42A6A600AA3687 /* NewPostViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E9123E41E42A6A600AA3687 /* NewPostViewController.swift */; };
6060
6E946ED51E4B47EB003CE1CA /* SlideRightTransitionAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E946ED41E4B47EB003CE1CA /* SlideRightTransitionAnimator.swift */; };
6161
6E946F351E4E1718003CE1CA /* PopTransitionAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E946F341E4E1718003CE1CA /* PopTransitionAnimator.swift */; };
62+
6E97BECF1E5C61B800A9E00F /* InterestFIR.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E97BECE1E5C61B800A9E00F /* InterestFIR.swift */; };
6263
6EB61ABA1E41F31300F6AB19 /* InterestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EB61AB91E41F31300F6AB19 /* InterestViewController.swift */; };
6364
6EB61ABC1E41F4AE00F6AB19 /* InterestHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EB61ABB1E41F4AE00F6AB19 /* InterestHeaderView.swift */; };
6465
6EC7BD261E56536700DD0927 /* SignInViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EC7BD251E56536700DD0927 /* SignInViewController.swift */; };
@@ -150,6 +151,7 @@
150151
6E9123E41E42A6A600AA3687 /* NewPostViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NewPostViewController.swift; sourceTree = "<group>"; };
151152
6E946ED41E4B47EB003CE1CA /* SlideRightTransitionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlideRightTransitionAnimator.swift; sourceTree = "<group>"; };
152153
6E946F341E4E1718003CE1CA /* PopTransitionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopTransitionAnimator.swift; sourceTree = "<group>"; };
154+
6E97BECE1E5C61B800A9E00F /* InterestFIR.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterestFIR.swift; sourceTree = "<group>"; };
153155
6EB61AB91E41F31300F6AB19 /* InterestViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterestViewController.swift; sourceTree = "<group>"; };
154156
6EB61ABB1E41F4AE00F6AB19 /* InterestHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InterestHeaderView.swift; sourceTree = "<group>"; };
155157
6EC7BD251E56536700DD0927 /* SignInViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignInViewController.swift; sourceTree = "<group>"; };
@@ -411,6 +413,7 @@
411413
6E9123D61E420A5900AA3687 /* Post.swift */,
412414
6E9123D71E420A5900AA3687 /* User.swift */,
413415
F55772701B2C6A5400DF2649 /* Interest.swift */,
416+
6E97BECE1E5C61B800A9E00F /* InterestFIR.swift */,
414417
);
415418
name = Model;
416419
sourceTree = "<group>";
@@ -717,6 +720,7 @@
717720
6E2E10891E49FC440027311F /* AsyncButton.swift in Sources */,
718721
6E946F351E4E1718003CE1CA /* PopTransitionAnimator.swift in Sources */,
719722
6E2E10A51E49FC440027311F /* UnwindSegue.swift in Sources */,
723+
6E97BECF1E5C61B800A9E00F /* InterestFIR.swift in Sources */,
720724
6E9123D91E420A5900AA3687 /* User.swift in Sources */,
721725
6E1341431E545C8E0040A59B /* CardView.swift in Sources */,
722726
6E2E102D1E48B2D60027311F /* CommentTableViewCell.swift in Sources */,

InterestViewController.swift

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ class InterestViewController: UIViewController {
1515
//MARK: - Public API
1616
var interest: Interest! = Interest.createInterests()[0]
1717

18+
var aInterest = [InterestFIR]()
19+
1820

1921
//MARK: - Private
2022
@IBOutlet weak var tableView: UITableView!
@@ -67,11 +69,19 @@ class InterestViewController: UIViewController {
6769

6870
fetchPosts()
6971

70-
//Firebase Data Posts
71-
DataService.ds.REF_POSTS.observe(.value, with: { (snapshot) in
72-
print(snapshot.value)
73-
})
74-
72+
//Firebase Data InterestFIR Fetch
73+
DataService.ds.REF_INTERESTS.observe(.value, with: { (snapshot) in
74+
if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
75+
for snap in snapshot {
76+
print("SNAP Interest: \(snap)")
77+
if let postDict = snap.value as? Dictionary<String, AnyObject> {
78+
let key = snap.key
79+
let interest = InterestFIR(postKey: key, postData: postDict)
80+
self.aInterest.append(interest)
81+
}
82+
}
83+
}
84+
})
7585

7686
}
7787

@@ -120,9 +130,6 @@ class InterestViewController: UIViewController {
120130

121131
}
122132

123-
124-
125-
126133
func fetchPosts() {
127134
posts = Post.allPosts
128135
tableView.reloadData()
@@ -163,11 +170,15 @@ extension InterestViewController: UITableViewDataSource{
163170

164171
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
165172
// Return the number of rows in the section.
173+
174+
166175
return posts.count
167176
}
168177

169178
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
170179

180+
181+
171182
let post = posts[indexPath.row]
172183

173184
if post.postImage != nil {
@@ -186,8 +197,44 @@ extension InterestViewController: UITableViewDataSource{
186197

187198
}
188199

189-
}
190-
200+
201+
202+
203+
/*
204+
func numberOfSections(in tableView: UITableView) -> Int {
205+
//Returns nr of sections
206+
return 1
207+
}
208+
209+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
210+
// Return the number of rows in the section.
211+
return posts.count
212+
}
213+
214+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
215+
216+
let post = posts[indexPath.row]
217+
218+
if post.postImage != nil {
219+
let cell = tableView.dequeueReusableCell(withIdentifier: "PostCellWithImage", for: indexPath) as! PostTableViewCell
220+
cell.post = post
221+
222+
return cell
223+
224+
}else {
225+
let cell = tableView.dequeueReusableCell(withIdentifier: "PostCellWithoutImage", for: indexPath) as! PostTableViewCell
226+
cell.post = post
227+
228+
return cell
229+
230+
}
231+
232+
}
233+
*/
234+
235+
236+
237+
}
191238

192239

193240

Interests/AppDelegate.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import UIKit
1010
import Firebase
1111
import FBSDKLoginKit
1212

13-
1413
@UIApplicationMain
1514
class AppDelegate: UIResponder, UIApplicationDelegate {
1615

@@ -38,8 +37,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3837
//Push Noti Reg
3938
NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification(notification:)), name: NSNotification.Name.firInstanceIDTokenRefresh, object: nil)
4039

41-
42-
4340
FIRApp.configure()
4441
FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
4542

Interests/Base.lproj/Main.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@
11951195
<rect key="frame" x="0.0" y="22" width="600" height="300"/>
11961196
<autoresizingMask key="autoresizingMask"/>
11971197
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hIA-8f-PEM" id="cH8-Gb-SGU">
1198-
<frame key="frameInset" width="600" height="299.5"/>
1198+
<frame key="frameInset" width="600" height="299.66666666666669"/>
11991199
<autoresizingMask key="autoresizingMask"/>
12001200
<subviews>
12011201
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="eNC-vn-TYz" customClass="CardView" customModule="CompassIO" customModuleProvider="target">

Interests/DataService.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class DataService {
1818
private var _REF_BASE = DB_BASE
1919
private var _REF_POSTS = DB_BASE.child("posts")
2020
private var _REF_USERS = DB_BASE.child("users")
21+
private var _REF_INTERESTS = DB_BASE.child("Interest")
2122

2223
var REEF_BASE: FIRDatabaseReference {
2324
return _REF_BASE
@@ -31,6 +32,10 @@ class DataService {
3132
return _REF_USERS
3233
}
3334

35+
var REF_INTERESTS: FIRDatabaseReference {
36+
return _REF_INTERESTS
37+
}
38+
3439
func createFirbaseUser(uid: String, userData: Dictionary<String, String>) {
3540
REF_USERS.child(uid).updateChildValues(userData)
3641
}

Interests/FeedVC.swift

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//
2+
// FeedVC.swift
3+
// CompassIO
4+
//
5+
// Created by LogicAppSourceIO on 21/02/17.
6+
// Copyright © 2017 LogicAppSourceIO. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import Firebase
11+
12+
13+
class FeedVC: UIViewController, UITableViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate , UITableViewDataSource {
14+
15+
16+
var posts = [Post]()
17+
18+
static var imageCache: NSCache<NSString, UIImage> = NSCache()
19+
20+
@IBOutlet weak var tableView: UITableView!
21+
@IBOutlet weak var imageAdd: UIImageView!
22+
@IBOutlet weak var captionField: UITextField!
23+
24+
25+
26+
override func viewDidLoad() {
27+
super.viewDidLoad()
28+
29+
// Do any additional setup after loading the view.
30+
31+
tableView.delegate = self
32+
33+
34+
35+
36+
// ACCES DATA -> FORM THIS POITN OT FIREBASE
37+
DataService.ds.REF_INTERESTS.observe(.value, with: { (snapshot) in
38+
39+
self.posts = [] // THIS IS THE NEW LINE
40+
41+
if let snapshot = snapshot.children.allObjects as? [FIRDataSnapshot] {
42+
for snap in snapshot {
43+
print("SNAP: \(snap)")
44+
if let postDict = snap.value as? Dictionary<String, AnyObject> {
45+
let key = snap.key
46+
let post = Post(postKey: key, postData: postDict)
47+
self.posts.append(post)
48+
}
49+
}
50+
}
51+
self.tableView.reloadData()
52+
})
53+
54+
55+
56+
57+
}
58+
59+
60+
61+
62+
63+
64+
65+
func numberOfSections(in tableView: UITableView) -> Int {
66+
return 1
67+
}
68+
69+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
70+
return posts.count
71+
}
72+
73+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
74+
75+
let post = posts[indexPath.row]
76+
77+
if let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell") as? PostCell {
78+
79+
if let img = FeedVC.imageCache.object(forKey: post.imageUrl as NSString) {
80+
cell.configureCell(post: post, img: img)
81+
} else {
82+
cell.configureCell(post: post)
83+
}
84+
return cell
85+
} else {
86+
return PostCell()
87+
}
88+
}
89+
90+
91+
}

Interests/Interest.swift

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
//
2-
// Interest.swift
3-
// compassIO
4-
//
5-
// Created by LogicAppSourceIO on 27/01/17.
6-
// Copyright © 2017 Logicappsource. All rights reserved.
7-
//
8-
9-
101

112
import UIKit
123

13-
class Interest
14-
{
4+
class Interest {
5+
6+
7+
158
// MARK: - Public API
169
var title = ""
1710
var description = ""
1811
var numberOfMembers = 0
1912
var numberOfPosts = 0
2013
var featuredImage: UIImage!
2114

15+
16+
2217
init(title: String, description: String, featuredImage: UIImage!)
2318
{
2419
self.title = title
@@ -42,3 +37,4 @@ class Interest
4237
]
4338
}
4439
}
40+

0 commit comments

Comments
 (0)