I ran into a really simple CoreData issue but it seems hard to solve. Writing a simple chat app where every user has many messages.
class CoreUser: NSManaged
A fetch request always returns the objects from the managed object context. You cannot fetch "modified" objects, e.g. CoreUser
objects with a "restricted" relationship to CoreMessage
.
But what you can do instead is fetch the CoreMessage
objects related
to the given user:
let fetchRequest = NSFetchRequest(entityName: "CoreMessage")
fetchRequest.predicate = NSPredicate(format: "owner.id == %@", nodeId)
and now you can add a fetch limit to restrict the number of retrieved messages:
fetchRequest.fetchLimit = 20
together with a suitable sort descriptor.