Post Username and Caption
Instagram Firebase
With our Posts now being rendered in our list, we'll need to include some more information regarding our post objects. For example, we'll need to set up the username, user profile image, and caption text to properly display inside our cells. This will be an interesting episode as we examine how to include our User struct inside of our Post struct.

Comments (14)
GeminixClown
6 years ago
Hai Brian, just curious why you just use self.posts.reversed, instead insert at index? Is the reversed it take more memory than insert at index?
Brian Voong
6 years ago
GeminixClown
6 years ago
Owww, yeah i forgot that observasion is running multiple time, thank u Brian
Casey West
6 years ago
I think an "error handling" video would be very helpful. For example if there isn't any internet what displays, etc. Lovin the class!
Игорь Магурян
6 years ago
Hi Brian, when you jump between controller in the tabBar and finally you open User Profile controller. Once all the photos fetched from the firebase db, they are appearing straight away which is not beautiful at all, may be there is a way to animate them when image is loaded? Question is: Where should we apply this animation? Thanks
Brian Voong
6 years ago
Игорь Магурян
6 years ago
Perfect answer thank you :)
fahad
6 years ago
Hello Brian, say you wanted to fetch posts in the feed, but with a condition... Only users that have for ex: "FirebaseUser" as a username. How can iterate and set a condition to post only users with the above username? i tried if loop, it wokred but fetched repeated posts and for loop i got no luck with it. Thanks alot, brian.
Brian Voong
6 years ago
fahad
6 years ago
Thank you
fahad
6 years ago
Sorry, i forgot to mention what if I have multiple feeds..similar to your Youtube app and watned to filter the posts based on index ..Do i go along with one controller and 4 and uicollectionViewCell or do i create separates controller for ever cell? Thank you!
Brian Voong
6 years ago
Tokyojogo
5 years ago
Hi brian, I have a question on AttributedString. Is SF Pro Display the systemFont? If not, how do I use it? Do I still need to add it considering its apple's font? How do change the font and weight in the NSAttributedStringKey declaration (say SF Pro Display using semibold). I tried looking for it online but all I'm getting are old versions and couldn't get it to work when I try it. Thank you.
Brian Voong
5 years ago
Aurélien Haie
5 years ago
Hi Brian! There is an error occurring on my app that apparently doesn't occur on yours and i don't understand why. As i have two UICollectionViews in my app, one in the homeController and one in the UserProfileController, when i scroll down the first collectionview and during the scroll i tap on the userProfileController tab, there is a confusion happening between the two collectionViews and they mix up their cells.. I don't know how to explain it well, but the UI of the two collectionViews are mixing up badly and that destroys the UI, maybe it's because of the reuse feature of the collectionView, so when i switch to the userProfile, the second collectionView reuse the cell from the first collectionView or something like that. So i tried to set different cellIdentifier for the two collectionViews but it still happens Do you have any idea of the origin of this problem? Did this ever happened to you? Thanks for your consideration, and keep up doing your work, you're the best teacher i've ever had in my swift developer life, the videos are super easy to follow and i really feel improving my development skills in each video :)
Brian Voong
5 years ago
Aurélien Haie
5 years ago
Ahhh exactly! i used the same variable layout for both of my controllers, i didn't think about this possible issue Thanks a lot
tetraprism95
5 years ago
Hi Brian, after implementing the user inside of the Post(user: User, dictionary: [String: Any]) constructor and after replacing the Post(dictionary: dictionary) to Post(user: User, dictionary: [String: Any]) inside each fetch function, I happen to get a bug where I can't see my UserProfileController's grid images anymore. Everything else is fine, but that. So i tried going back a step and deleting the Post(user: User, dictionary: [String: Any]) back to Post(dictionary: dictionary) and I can see the grid images again. I don't know why it's doing this.
Brian Voong
5 years ago
tetraprism95
5 years ago
Hmm.. Thats weird, I just logged out of the currentUser and logged back in then all the grid pictures started to show again. Any reason why this is?
tetraprism95
5 years ago
Edit: And then it disappear again one i re-run the simulator again. What the.
tetraprism95
5 years ago
Yeah I checked and dictionary isn't nil.
turtle0001
5 years ago
Try to put breakpoints to fetchUser and fetchPost when passing values to var user and observe how its executing.
ducward
4 years ago
hey tetraprism95, did you ever find the fix to this bug? I am having the same issue.
Luciano Martins
5 years ago
i'm in episode 22 and it worths each dollar i've paid
Govind K Kara
5 years ago
When going to user profile,collection view reload inside fetch ordered post method not triggering.But if you put breakpoint on method reload happening and cells are displayed.Pretty strange
edison1
5 years ago
How do you fetch each post that has been posted in the database?
Brian Voong
5 years ago
edison1
5 years ago
fileprivate func retrieveallPosts() { guard let uid = user?.uid else {return} let ref = Database.database().reference().child("posts").child(uid) ref.observe(.value) { (snapshot) in // print(snapshot.value) guard let dictionaries = snapshot.value as? [String: Any] else {return} dictionaries.forEach({ (key, value) in guard let dictionary = value as? [String: Any] else {return} guard let user = self.user else {return} var post = Post(user: user, dictionary: dictionary) post.id = key self.posts.append(post) self.collectionView?.reloadData() }) } } Hey Brian, Not sure what I"m doing wrong, can you please help :)
edison1
5 years ago
nevermind, got it to work.. it was so simple... ugh
Daniel Peach
4 years ago
dude what was it.
petar7
5 years ago
Hi Brian, the function fetchPosts() in HomeFeedController doesn't seem to work , photos are not in right order and it uploads not immediately after user select photo also after dissmising viewcontroller , I tried childAdded it works great but as you sad later on it causes us a bug. What should I do to fix that can you please answer ?
ducward
4 years ago
Does anyone know why the fetchOrderedPosts() function doesn't show the posts once you change the initialization from Post(dictionary: dictionary) to Post(user: User, dictionary: [String: Any])? I believe the problem has something to do with the previous line "guard let user = self.user else { return }", but I can't seem to figure out why since the navigationTitle is showing an username. Any help would be greatly appreciated.
Brian Voong
4 years ago
ducward
4 years ago
By putting breakpoints in the fetchUser() and fetchOrderedPosts() functions, I noticed that it's calling the fetchOrderedPosts() before the fetchUser() function. I think this is the problem since the user property is nil before fetchUser() is called. Do you know why this is happening? Thank you.
Brian Voong
4 years ago
ducward
4 years ago
fetchOrderedPosts() is called after fetchUser() in viewDidLoad()
johnsoa7
4 years ago
Hi Brian, My UserProfileController no longer seems to be displaying when I select it. But, my HomeController and PhotoSelector tabs work, and after checking your source code, I am struggling to figure out what the cause could be. Could you please suggest what the issue could be, or how to resolve this? Thanks
johnsoa7
4 years ago
I've fixed it, don't worry. Your source code worked a charm!
HELP & SUPPORT