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
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
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
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.