mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-12 04:10:36 +01:00
keypath objectID not found in entity on iOS 10 or Later #214
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @sohilspaceo on GitHub (Jun 1, 2018).
I have a class name
Historyin which I store history of users. I want to get top 30 recent items store in the DB and here is my query.The above code is working on iOS 11 or later but on iOS 10 or later I am getting crash which says:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath objectID not found in entity '
Can anybody tell me what I am missing and same thing happens when I need to fetch last inserted item.
@JohnEstropia commented on GitHub (Jun 10, 2018):
Hi, sorry for the late response. I'm not sure what is going on with iOS 10, but have you tried to use
#keyPath(History.objectID)instead of"objectID"? It's possible they evaluate differently.In the first place, I'm not sure why you would want to sort by object ID. Nothing in
NSManagedObjectIDpertains to anything about "recentness" as CoreData's primary keys are UUID type. It's likely you are sorting items arbitrarily, and may be better off removing theOrderByclause.@sohilspaceo commented on GitHub (Jun 11, 2018):
Thank for the feedback. But I changed the entire logic. Well, still I can try it out. I was sorting based on objectID as we seen that it's increasing while entering new values, so I think better to go with and I din't know earlier about this functionality, but right now I added a timeStamp as a value in Database and based on that I am fetching recent Items.
@JohnEstropia commented on GitHub (Jun 11, 2018):
While it may be true that
objectIDgets higher with new records, this is most likely just an implementation artifact. ObjectIDs change across migrations, for example. If you have a timeStamp property now I definitely recommend to use that instead. Let me know if you find further issues.