mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
ERROR: Attempted to fetch from a 'CoreStore.DataStack' outside the main thread #365
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 @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
@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@bradleydworak commented on GitHub (Jul 10, 2021):
Thanks John for your prompt reply, indeed that worked.