Originally created by @tosbaha on GitHub (Apr 24, 2019).
Hi,
I would like to upgrade the library in my project. I saw it has breaking changes. Is it safe to use `try?` it like below?
Old Code
======
```swift
// Before
if let object = CoreStore.fetchOne(...) {
// ...
}
else {
// ...
}
```
New Code
========
```swift
// Before
if let object = try? CoreStore.fetchOne(...) {
// ...
}
else {
// ...
}
```
adam
added the question label 2025-12-29 15:28:00 +01:00
Fetches are now throwing functions to separate these two cases:
nil return: When there is no result to return
thrown errors: When the fetch happened before addStorage() completed, or the entity fetched is not in the schema.
Wether try? in your code is ok depends on how you were using it before. If you wish to ignore cases where your DataStack is still setting up its storage, you can use try? and handle nil cases as you have before.
But if your code expects that this fetch happens after addStorage(), I would encourage you to handle the thrown error instead. Or if you are really, really sure, use try!.
@JohnEstropia commented on GitHub (Apr 26, 2019):
Fetches are now `throw`ing functions to separate these two cases:
1. `nil` return: When there is no result to return
2. thrown errors: When the fetch happened before `addStorage()` completed, or the entity fetched is not in the schema.
Wether `try?` in your code is ok depends on how you were using it before. If you wish to ignore cases where your DataStack is still setting up its storage, you can use `try?` and handle `nil` cases as you have before.
But if your code expects that this fetch happens after `addStorage()`, I would encourage you to handle the thrown error instead. Or if you are really, really sure, use `try!`.
Thanks for the answer. From your comments, it sounds like using try? is same way I was using in previous version. Because I was handling nil case. I don't need to handle DataStack being setup.
@tosbaha commented on GitHub (Apr 27, 2019):
Thanks for the answer. From your comments, it sounds like using try? is same way I was using in previous version. Because I was handling `nil` case. I don't need to handle DataStack being setup.
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 @tosbaha on GitHub (Apr 24, 2019).
Hi,
I would like to upgrade the library in my project. I saw it has breaking changes. Is it safe to use
try?it like below?Old Code
New Code
@JohnEstropia commented on GitHub (Apr 26, 2019):
Fetches are now
throwing functions to separate these two cases:nilreturn: When there is no result to returnaddStorage()completed, or the entity fetched is not in the schema.Wether
try?in your code is ok depends on how you were using it before. If you wish to ignore cases where your DataStack is still setting up its storage, you can usetry?and handlenilcases as you have before.But if your code expects that this fetch happens after
addStorage(), I would encourage you to handle the thrown error instead. Or if you are really, really sure, usetry!.@tosbaha commented on GitHub (Apr 27, 2019):
Thanks for the answer. From your comments, it sounds like using try? is same way I was using in previous version. Because I was handling
nilcase. I don't need to handle DataStack being setup.