Upgrading from v5.x to v6.x #268

Open
opened 2025-12-29 15:28:00 +01:00 by adam · 2 comments
Owner

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

// Before
if let object = CoreStore.fetchOne(...) {
    // ...
}
else {
    // ...
}

New Code

// Before
if let object = try? CoreStore.fetchOne(...) {
    // ...
}
else {
    // ...
}
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
Author
Owner

@JohnEstropia commented on GitHub (Apr 26, 2019):

Fetches are now throwing 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!.

@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!`.
Author
Owner

@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.

@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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#268