ERROR: Attempted to fetch from a 'CoreStore.DataStack' outside the main thread #365

Closed
opened 2025-12-29 15:30:05 +01:00 by adam · 2 comments
Owner

Originally created by @bradleydworak on GitHub (Jul 9, 2021).

Hi,

I'm new to CoreStore and getting an error attempting to try fetching objects. I'm placing an assertion before the datastack execution to confirm I'm on the main thread. I'm attempting to execute the code from a Swift Button action as shown below:

Button(action: {
assert(Thread.isMainThread)
print(Thread.current)
dataStack.perform(
asynchronous: { (transaction) -> Void in
let myimgs = try dataStack.fetchAll(From())
},
completion: { (result) -> Void in
switch result {
case .success:
print("success!")
case .failure(let error): print(error)
}
}
)
})

The result is:
<NSThread: 0x6000009f04c0>{number = 1, name = main}
[CoreStore: Assertion Failure] DataStack+Querying.swift:146 fetchAll(::)
↪︎ Attempted to fetch from a 'CoreStore.DataStack' outside the main thread.

Can anyone assist? I'm using CoreStore 8.0.0, Xcode 12.4, Swift v5. I appreciate you help.

Thanks,

Brad

Originally created by @bradleydworak on GitHub (Jul 9, 2021). Hi, I'm new to CoreStore and getting an error attempting to try fetching objects. I'm placing an assertion before the datastack execution to confirm I'm on the main thread. I'm attempting to execute the code from a Swift Button action as shown below: Button(action: { assert(Thread.isMainThread) print(Thread.current) dataStack.perform( asynchronous: { (transaction) -> Void in let myimgs = try dataStack.fetchAll(From<MyImage>()) }, completion: { (result) -> Void in switch result { case .success: print("success!") case .failure(let error): print(error) } } ) }) The result is: <NSThread: 0x6000009f04c0>{number = 1, name = main} ❗ [CoreStore: Assertion Failure] DataStack+Querying.swift:146 fetchAll(_:_:) ↪︎ Attempted to fetch from a 'CoreStore.DataStack' outside the main thread. Can anyone assist? I'm using CoreStore 8.0.0, Xcode 12.4, Swift v5. I appreciate you help. Thanks, Brad
adam closed this issue 2025-12-29 15:30:05 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Jul 10, 2021):

You are just fetching objects so you shouldn't use dataDtack.perform()

Just call dataStack.fetchAll() and it should be fine

@JohnEstropia commented on GitHub (Jul 10, 2021): You are just fetching objects so you shouldn't use `dataDtack.perform()` Just call `dataStack.fetchAll()` and it should be fine
Author
Owner

@bradleydworak commented on GitHub (Jul 10, 2021):

Thanks John for your prompt reply, indeed that worked.

@bradleydworak commented on GitHub (Jul 10, 2021): Thanks John for your prompt reply, indeed that worked.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#365