I am loading data from firebase and outputting data to tableView. However, I find that from time to time duplicate content appears in my tableView. Initially, I thought I accidentally inserted the same content into my PostService.ps.posts array. However, after I set a breakpoint just before reloading the tableView, I typed the following command in the console, and the output was strange.
print PostService.ps.posts
As the output below, item [4] and item [6] have {...} which I don’t know what they mean (this is the first time I use the console command for debugging). And in my deskView. I see the data presented in the following sequence [1], [2], [3], [3], [5], [5], [6], [7], [8], [9] for rows from 0 to line 8). Thus, it seems that line 3 (start form 0) receives the same data as line 2, and line 5 receives the same data as line 4. Weird?
I am not sure why this is happening, and I have nothing to start with, because it does not happen every time. I hope that the output of this console will help me to correctly indicate
[1] = 0x000000012f4849b0 {
_postKey = "-KQTh_WDO2IS1rYfLgnU"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
}
[2] = 0x0000000130e61f40 {
_postKey = "-KQTHnE4IIeBR3tyDM3r"
_userId = "1isMS98ZmXYrpCmGb4o5voaAqXH2"
_image = "www.image2.com"
}
[3] = 0x0000000130192b40 {
_postKey = "-KQtN4YG51HOF19FrM8s"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
_image = "www.image3.com"
}
[4] = 0x0000000130192b40 {...}
[5] = 0x0000000130269560 {
_postKey = "-KR2On6u7dRy0GAvE1Gn"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
_image = "www.image4.com"
}
[6] = 0x0000000130269560 {...}
[7] = 0x000000013150f4c0 {
_postKey = "-KQThGLVA-MsviGMsXOS"
_userId = "1isMS98ZmXYrpCmGb4o5voaAqXH2"
_image = "www.image5.com"
}
[8] = 0x000000012fa88890 {
_postKey = "-KQt269uHGM99oFKuJRt"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
_image = "www.image6.com"
}
[9] = 0x000000012f9bcad0 {
_postKey = "-KQThdCAm-PlCsCnXcBZ"
_userId = "SpmZmYwD3Td04sQZxOYeALwuMp03"
}
PostService.ps.posts, [Post]
viewForHeaderInSection ( cellForRowAtIndexPath ),
if let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("TableSectionHeader") as? TableSectionHeader {
let post = PostService.ps.posts[section]
var image: UIImage?
if let url = post.imageUrl {
image = DiscoverVC.imageCache.objectForKey(url) as? UIImage
}
cell.configureCell(post, image: image)
cell.delegate = self
return cell
} else {
return TableSectionHeader()
}