CoreStore how to fetch or query object from unspecified dynamic object

209 Views Asked by At

enter code hereI read this guide which documented pretty good. I need to search through my database and get a record actually execute fetch or query.

Can I search through all records instead of specifying appropriate From clause.

For example

var undefinedObject = CoreStore.fetchAll(
    From(GoThroughAllMyDataBaseEntities),
    Where("%K == %@", "localId", "some string id")
)

print(undefinedObject.id) // as object will be undefined I need to figure out how to get id property from it.

Side note: all my entities are child objects of parent entity which has id property.

So let's say I have next entities in CoreData:

BaseEntity (which includes id)
Playlist
Song

in the code above I don't care which will be returned to me I just what to see one that matches this condition: Where("%K == %@", "localId", "some string id")

Also my localId property in each objects are very unique strings. They are extracted from NSManagedObjectID.

So there is no way have the same duplicated identifier localy in CoreData

If there is no way to do it, then I will need to loop all my Playlists and Songs records.

managedObjectContext.objectWithID(objectID) may not work thought in some cases as there is no guaranty that CoreData record has not been deleted and app recreated a copy of the same record, so physically a copy of record has another objectID address in CoreData, but still has localID property copied from other record.

0

There are 0 best solutions below