CoreStore
CoreStore copied to clipboard
Upgrading from v5.x to v6.x
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 {
// ...
}
Fetches are now throw
ing 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!
.
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.