I have faced same kind of issue and I am sharing me experience.
Maybe it can help someone.
I did have "Message" NSManagedObject Class.
If we do have properties like:
@NSManaged public var buddyId: Int32
@NSManaged public var message: NSObject?
@NSManaged public var messageServerId: Int32
@NSManaged public var messageUnixTime: Double
@NSManaged public var sender: Int32
@NSManaged public var status: Int32
@NSManaged public var type: Int32
@NSManaged public var userId: Int32
@NSManaged public var buddyName: String?
@NSManaged public var chatroomId: Int32
@NSManaged public var messageSource: Int32
And your predicate is like:
fetchRequest.predicate = NSPredicate(format: "userId == %@ AND buddyId == %@ AND messageSource == %d", userId, buddyId, 10)
So in this case, we do have userId as Int32 but we are passing it as string in predicate. NSFetchedResultsController is on mainContext and all messages(data) processing is happening on privateConext(child context of mainContext).
So NSFetchedResultsController is gonna fetch all messages on performFetch() call but when we do any insert/update/delete operation of message on privateContext, these operations effect will not gonna reflect for NSFetchedResultsController.
The simple reason was because I was not providing proper predicate.
I do need to modify predicate like:
fetchRequest.predicate = NSPredicate(format: "userId == '%@' AND buddyId == '%@' AND messageSource == %d", userId, buddyId, 10)
or I do need to provide predicate like:
fetchRequest.predicate = NSPredicate(format: "userId == %d AND buddyId == %d AND messageSource == %d", userId, buddyId, 10)
Reason was "userId" and "buddyId" was of type Int32 but I was providing them as String in predicate. Hence NSFetchedResultsController was unable to detect message changes.
That's it.
Let me know if someone need a detail discussion about this.
Hope this will help someone.