CoreStore icon indicating copy to clipboard operation
CoreStore copied to clipboard

Upgrading from v5.x to v6.x

Open tosbaha opened this issue 5 years ago • 2 comments

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 {
    // ...
}

tosbaha avatar Apr 24 '19 12:04 tosbaha

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 avatar Apr 26 '19 06:04 JohnEstropia

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 avatar Apr 27 '19 15:04 tosbaha