mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-14 07:33:28 +01:00
Import Unique Object Question #209
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ASPetrov on GitHub (Apr 27, 2018).
Hello,
I'd like to kindly ask you could you suggest me any best practice(s) to avoid complex lines like in the following examples?
e.g.
let managedBeacon: CDBeacon! = try! transaction.importUniqueObject(Into(CDBeacon.self), source: beacon)or
let managedBeacon = (try? transaction.importUniqueObject(Into(CDBeacon.self), source: beacon)) as? CDBeaconI'm currently using helper function like the following:
Here is more clear example how I using it:
Thank you for your time!
@JohnEstropia commented on GitHub (May 5, 2018):
The current API is designed in such a way that it's simple without losing any important information, so "complex" here is subjective and it is up to you to decide on the tradeoff you are willing to compromise. To comment on your examples,
You are initializing
Intowith its dynamic initializer, which was made for types with complex inheritance. Instead, you can get rid of the casts by using the genericInto<T>:@ASPetrov commented on GitHub (May 7, 2018):
Thank you for your response!
By "complex" I meant that the line length easily exceeds 100 characters and when I'm using tools like SwiftLint I'm getting warnings. But you're right this is subjective.
The only reason I'm using the helper function above instead of:
and then
managedBeacon.content = managedBeaconContentIs to avoid compile errors like this
I really hate those
??. :)@JohnEstropia commented on GitHub (May 7, 2018):
Why not just call it normally with a plain
try? (no exclamation/question mark)Also, since you are working with arrays I recommend you use the array version instead of importing one-by-one:
@ASPetrov commented on GitHub (May 7, 2018):
Thank you! Both of those suggestions make perfect sense.
@JohnEstropia commented on GitHub (May 7, 2018):
I'll close this issue but feel free to reopen if you have further questions :)