I'm trying to either show or not show my "NoPostsView" depending on my firebase database.
That's my function for finding out if there are posts:
func checkIfPostsExists(YES: @escaping () -> Void, NO: @escaping () -> Void)
{
REF_POSTS.observeSingleEvent(of: .value, with:
{
(snapshot) in
if snapshot.exists()
{
YES()
}
else
{
NO()
}
})
}
And that's how I use it:
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
checkIfPostsExists(YES:
{
if self.posts.count <= 0
{
return 7 // ERROR IS IN THIS LINE
}
else if self.posts.count != 0
{
self.noPostsView.isHidden = true
}
})
{
self.noPostsView.isHidden = false
}
return posts.count
}
The error I'm getting is:
Unexpected non-void return value in void function
I'm pretty sure it's caused due to me returning 7 in that function but I can't seem to get my head around fixing the error.