Can anyone tell me why the questionFetch predicate below is being ignored and the questionResults.count being returned is the number of rows in the entire data set? There are only 2 rows in the data set with a questionType equal to 0, which should be the only two rows returned. Instead all 88 rows of data are being returned.
let questionFetch: NSFetchRequest<Question> = Question.fetchRequest()
questionFetch.predicate = NSPredicate(format: "%K == %iā,
#keyPath(Question.questionType), currentQuestionType)
let questionResults = try
modelController.coreDataStack.managedContext.fetch(questionFetch)
print("questionResults.count: ", questionResults.count)
Note that I have also tried with the hard-coded value in the comparison to make sure that the problem is not due to an incorrect value in the currentQuestionType variable.
questionFetch.predicate = NSPredicate(format: "%K == 0ā,
#keyPath(Question.questionType))
Yet the choiceFetch predicate below, with nearly identical logic, is limiting the results appropriately.
let choiceFetch: NSFetchRequest<Choice> = Choice.fetchRequest()
choiceFetch.predicate = NSPredicate(format: "%K == %i",
#keyPath(Choice.questionID), currentQuestionID)
let choiceResults = try managedContext.fetch(choiceFetch)
print("choiceResults.count: ", choiceResults.count)
Any ideas would be appreciated.