Group Group Group Group Group Group Group Group Group

[Chapter 14] Creating more rooms

#1

Hi and thanks for an awesome book

I’m reading chapter 14, and I finished “Creating more rooms” topic (end at page number 271). Everything is working well but a small problem. That is when I try to comment out the below code snippet, I see the check mask on the tableview after creating a new room.

self.roomsSubscription = realm.objects(ChatRoom.self).observe { _         
    self.tableView.reloadData()
}

Could you please explain it?

#2

@cuong1112035 You can read more about reloadData() over here:

https://developer.apple.com/documentation/uikit/uitableview/1614862-reloaddata

Please let me know if you have any other questions or issues about the whole thing.

Thank you!

#3

@shogunkaramazov I know what reloadData() do. I commented out the snippet code because when I create a new room and store it in to realm, that means I also update the Chat object.

self.roomNamesSubscription = self.roomNames?.observe { changes in
self.tableView.applyRealmChanges(changes)
}

By using the above code, I observed and synchronized the Chat object. So that the above code snippet is enough to update the table view when a new room appears.
I removed the below code because it is redundant, but an unexpected issue happened

self.roomsSubscription = realm.objects(ChatRoom.self).observe { _
self.tableView.reloadData()
}

#4

@cuong1112035 What error do you get exactly when you remove the above snippet of code?

#5

@shogunkaramazov I see a check mask after creating a room like this