-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Extract Blog core data properties to an extension #4762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Seems like they're always set, but I'm not sure if that's guaranteed. |
|
Actually, I checked the generated classes, and it's all optionals, which makes a lot of sense. You don't pass the attributes on initialization, so they all can be However, I tested on a newly created Blog and it seems Core Data is "smart" about this: This means no crashing, but I wonder if this brings any surprising side effects. |
|
Excellent work! |
|
I don't think this is ready to merge yet. I've been writing some tests, and this is a bit unexpected: I'm tempted to use the implicitly unwrapped optional version, but I'm collecting my thoughts and considering that this is just a symptom of a bigger issue, and we should just stop passing |
These tests verify what I've found so far about mapping core data attributes to Swift types.
Yup. This. We really need to put Core Data down as low as possible and use a separate data model (transfer object?) for what we use in the UI. The problem comes with fetched results controllers so we'd need to solve those performance issues if we wanted to not mix UI with CD. |
|
Regarding Sets and relationships - sorry I missed that piece. NSSet to Set I believe is okay. Relationships (and pretty much all accessors) seem to be optional when generated by Xcode regardless of the optionality of the attribute in the Core Data model. This makes Core Data validation more important to handle - which we don't really do anywhere since it sucks. |
|
@koke Let me know when you want to take a look at this one again! |
|
I'm tempted to close this for now as I don't really know how to handle the optionals, short of implementing an immutable non-managed version of |
|
We can close the PR for now - easy enough to reopen when we want to figure something out better. |
It all starts when I try to add
nullabletoplanIDso I can properly use it in Swift. If you add nullability for one attribute, you have to do the whole file. Since I had to go through every attribute onBlogand figure out if it was nullable or not, I thought I might as well extract them all, convert them to Swift, and add documentation.I'm going to test and investigate this for a bit, but @astralbodies maybe you already know the answers to these questions:
Setinstead ofNSSetfor core data relationships?NSSet?, or it will always be an instance ofNSSet(that might be empty)?I've tried to change as little as possible on this PR, but already found some interesting next steps:
blog.settingsbeingnil. I hate to commit asettings!, but it's no different than what was there before.Blog.optionsis a mess. We should at least stop using the legacy structure. Ideally we'd move everything intoBlogSettings, or turn some things intoBlogproperties.blogIDtodotComID.blogIDcan either be the wp.com ID ornil, so we should rename it to avoid confusion.account/jetpackAccount. As I was writing the documentation I felt the urge to stop and refactor that. It's just terribly confusing, and there should be justBlog.accountNeeds Review: @astralbodies