Show Comments and Hide Posts Protocol
Fullstack Social iOS NodeJS REST
Now that we can show comments from the Home screen, I'd like to cover the topic of implement similar behavior for our Profile pages as well. Whenever you want shared behavior between very different classes, you'll most likely want to create a Protocol that implements a few functions. Doing so will allow other objects to interact with these classes more generally through this Protocol contract. Once we have comments showing in the Profile page, let's move onto enable a "Hide Post" feature on the home page and "Delete Post" option in the profile screen.

Comments (3)
romulusc
4 years ago
Hi Brian. I'm getting 200 on the server for DELETE post and postItem, so server-side ok, but the ios app its some kind of bug for me...it crashes after hitting 'delete' or 'remove post'. Only if I restart the app I see that the post was removed or deleted...and I've gone again as far as using your app from the download project and no change. I've been trying to solve this, don't know if its a bug that's only me experiencing, at the moment I don't fully understand the error. StackOverflow mentions something about an updateData to update the data source...but in the video it works, so I don't know what I'm missing here yet... ...on HomeController removing from feed... fullstacksocial_ios_lbta[1331:34116] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete item 0 from section 0 which only contains 0 items before the update'
Brian Voong
4 years ago
romulusc
4 years ago
Yep, I called that self.items.remove(at: index). I even use now the downloaded app from the project, with pod updated and all, and behaves the same, I'm puzzeled. The bug is here when running on my mac because you get no bugs i see. Hopefully, other students could confirm that is working on their machine maybe. the error i'm getting is acctually this: fullstacksocial_ios_lbta[2300:98770] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (1) must be equal to the number of items contained in that section before the update (1), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
romulusc
4 years ago
Found a fix, app not crashing anymore, all working as it should. My app used to crash when heating this line collectionView.deleteItems([indexPath]) in showOptions(post: Post) - when removing a post from 'feed' or deleting a post in 'profile', very very very very strange I know since its working for Brian. I looked into what "items" is and saw "items" is the [U]() in the LBTAListCell<U> so in my case is <Post> I think, and "items" does also a collectionView.reloadData() in there. So I thought what if self.items.remove(index) removes the post and also reloads data? Removing the line "collectionView.deleteItems([indexPath])" makes my app work, the post gets 200 on delete on the ​server and the Home or Profile controllers refreshes ok, post disappears. Does this make any sense I wonder?
gerkov77
2 years ago
Hey Brian! Did you secretly implement /feeditem route in the server project ? :) For me deleting from feed does not work, I get 404 from server. This is due to the fact that showOptions func in HomeController is hitting baseUrl/feeditem, which route does not exist. Should we hit baseUrly/post instead? But then feeditem is removed for every users including the original poster, so not the best solution.
gerkov77
2 years ago
Yes, looks like that I missed something, or feeditem.js was created off camera. Thankfully we have the download projects! :)
gerkov77
2 years ago
i mean api/feeditem/delee.js
gerkov77
2 years ago
Ah yes, I I had to watch a bit further to see this actually :)) sorry.
gerkov77
2 years ago
Hey there, I have a few bugs: post pictures are loading only here and there, many of them don't load in the Home or even in the Profile feed. Also, when logging in with a new user, I have to manually refresh, to see the new user's stuff, and even their profile. (the latter is maybe normal at this stage)And this time also only some pictures are loading. Also after deleting the feed items collection view does not refresh, and Alamofire gives an error of " responseSerializationFailed(reason: Alamofire.AFError.ResponseSerializationFailureReason.inputDataNilOrZeroLength) " Server gives 200, and is deleting properly though. Strange because I have copied and pasted everything from the downloaded project lately.
HELP & SUPPORT