I have an entity Exams
, with a one-to-many relationship with another entity, Topics
.
When the user clicks an exam on a table view, they go through to a page showing the topics associated with that exam. The topics page table view is in two sections, “To do” and “Completed”. Topics are organised into section by a Boolean attribute topicIsCompleted
. As expected, when the user clicks the checkbox on the row, it toggles the Boolean and therefore the moves the topic into the other section.
What I want to be able to do is establish the number of topics complete and the number incomplete.
I can’t count the number of rows in each sections because if there are only incomplete topics or only complete topics, there will only be one section in the table view and I won’t know what type of topic (complete or incomplete) it contains.
I think I need to count the number of topics with a topicIsCompleted Boolean value of false and true….but this is what I can’t work out how to do.
Doing a loop of the topics associated with the particular exam, and using valueForKey topicIsCompleted
doesn’t seem to work with a Boolean.
I’m using NSFetchedResultsController
My plan B is to create another fetch request with a predicate to only give me topics with topicIsCompleted == TRUE and count that.
Will there be issues creating a second fetch request?
Can I make it so my table view always draws two sections but one of them may be empty? I don’t mind there being sectionHeader in the view with no rows under it. That way I know the first section relates to incomplete and the second section relates to complete.
Are there any suggestions for an alternate solution?
Many thanks