In Core Data, can you create a predicate to fetch with a range of URI's

147 Views Asked by At

Given a entity name and I know the format of the URI I am searching for... is there a way I can create predicate to fetch a range of objects based on the key

Given URI Format: x-coredata:////p

I have the UUID and entity name, the key's start at p1, p2, p3, etc...

What I want is a predicate that can give me same p100 to p500, not sure if this is possible or not?

Thanks in advance!

1

There are 1 best solutions below

0
Jerry Krinock On

It looks like you want a predicate to filter based on the internal primary key, which is an implementation detail of Core Data.

There may be be a way to do this, but a much more future-safe and simpler technique would be to instead add your own attribute, serialNumber, or whatever you want to call it, to the desired entity. Set the class of this entity to a subclass of NSManagedObject. In your subclass, override awakeFromInsert() and assign the next serial number to this attribute whenever awakeFromInsert() runs. Note that awakeFromInsert() is only run once for each object, even if it persists in the store for months or years.