Weird Coredata error

Hi

I really don't understand. I have a record type on CloudKit where I store some data and a corresponding entity on core data that I sync with CloudKit with a very basic routine at some point I call this func:

func GetUserFromCoredata(userID:String)->UserEntity?
{
    var fetched:[UserEntity]?=nil
    let fetch = NSFetchRequest<UserEntity>(entityName:"UserEntity")
    let predicate = NSPredicate(format:"TRUEPREDICATE")
    fetch.predicate = predicate
    fetch.affectedStores = [DBGlobals.localStore, DBGlobals.cloudStore]
    do{
        print("RICHIESTA FETCH UTENTI IN COREDATA")
        fetched = try context.fetch(fetch)
    }
    catch{
        fatalError("errore nel recupero dell'elenco utenti")
    }

    if let found = fetched
    {
        for el in found
        {
            if el.userID == userID
            {
                return el
            }
        }
    }
    
    return nil
}

As you can see nothing special. it is only a fetch made on two stores. If I run the code 20 times 19 are good and 1 result in a fatal error with this text:

2023-06-28 17:56:49.684780+0200 xDeskApp[23313:2379150] -[__NSCFConstantString bytes]: unrecognized selector sent to instance 0x215632f50 2023-06-28 17:56:49.712724+0200 xDeskApp[23313:2379150] [error] error: SQLCore dispatchRequest: exception handling request: <NSSQLFetchRequestContext: 0x283d88000> , -[__NSCFConstantString bytes]: unrecognized selector sent to instance 0x215632f50 with userInfo of (null) 2023-06-28 17:56:49.974635+0200 xDeskApp[23313:2379150] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString bytes]: unrecognized selector sent to instance 0x215632f50' *** First throw call stack: (0x1bd4d4cb4 0x1b657c3d0 0x1bd649ab8 0x1bd4eb0e8 0x1bd551900 0x1c4c53594 0x1c4bdf848 0x1c4bdf4b0 0x1c4c81d80 0x1068fa038 0x10690b814 0x1c4c81c20 0x1c4bcef68 0x1c4bcee38 0x1c4bbe200 0x1c4bc9a78 0x1c4d3752c 0x1c4c02678 0x1c4bc86d8 0x1c4bbb9fc 0x1c4bb6b14 0x1c4cc97ec 0x104bf00b0 0x104bef860 0x104bee8f4 0x1c4f82ce8 0x1c4f82d8c 0x1c5068cac 0x1c4f1f3b0 0x1c4f11338 0x1c50689d4 0x1bd53dc04 0x1bd4ebcb4 0x1bd4eb6cc 0x1c4fcc800 0x10690b158 0x1068fa038 0x1069020b0 0x106902e28 0x10690fc74 0x21d250ddc 0x21d250b7c) libc++abi: terminating due to uncaught exception of type NSException (Recorded stack frame)

... and really, I can't understand. the predicate is absolutely basic, the entity exist, here I am not syncing anything, just fetching the records in the two stores... what am I doing wrong? why 19 su 20 are good and one is catching this error?

Replies

ps. forgot to tell: as you can see the predicate is "TRUEPREDICATE" while before it used the argument userID to fetch a particular user... and I remove it to try to understand this problem

  • ps2 the problem arise in the fetched = try context.fetch(fetch) line

Add a Comment

I also encountered this error. It is quite strange. Has anyone found a solution?