Originally created by @sidlatau on GitHub (Jun 7, 2017).
I am trying to fetch data in background, and use fetched data in main thread, but when I try to access managed objects properties app crashes. Problem for this I think is that background context is destroyed when transaction finishes. Is it possible to change managed objects context to main somehow (simmilar to transaction.edit(object) functionality)?
DataStack.beginAsynchronous { transaction in
let data = transaction.fetchAll(
From<Object>(),
Where(...)
) ?? []
transaction.commit { _ in
callback(data)
}
}
Originally created by @sidlatau on GitHub (Jun 7, 2017).
I am trying to fetch data in background, and use fetched data in main thread, but when I try to access managed objects properties app crashes. Problem for this I think is that background context is destroyed when transaction finishes. Is it possible to change managed objects context to main somehow (simmilar to ```transaction.edit(object)``` functionality)?
```
DataStack.beginAsynchronous { transaction in
let data = transaction.fetchAll(
From<Object>(),
Where(...)
) ?? []
transaction.commit { _ in
callback(data)
}
}
```
adam
added the question label 2025-12-29 18:23:34 +01:00
Yes, you need to fetch it again from your datastack:
callback(DataStack.fetchExisting(data)!)
@JohnEstropia commented on GitHub (Jun 7, 2017):
Yes, you need to fetch it again from your datastack:
```swift
callback(DataStack.fetchExisting(data)!)
```
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 @sidlatau on GitHub (Jun 7, 2017).
I am trying to fetch data in background, and use fetched data in main thread, but when I try to access managed objects properties app crashes. Problem for this I think is that background context is destroyed when transaction finishes. Is it possible to change managed objects context to main somehow (simmilar to
transaction.edit(object)functionality)?@JohnEstropia commented on GitHub (Jun 7, 2017):
Yes, you need to fetch it again from your datastack:
@sidlatau commented on GitHub (Jun 7, 2017):
That's exactly what I needed. Thanks for quick response.