WordPress-iOS
WordPress-iOS copied to clipboard
Abstract `ContextManager` usages behind `CoreDataStack`
Part of #24165
Problem I can't move AbstractPost and other Objective-C models in WordPressDataObj because they access ContextManager which is defined in the Swift WordPressData.
Solution Decouple from knowing about a specific type (ContextManager) and use a protocol instead (CoreDataStack). This came with a few compromises (see inline comments) but I think it got the job done relatively clean.
I tested this by running Jetpack on my iPhone and doing a smoke test checking the various tabs.
An alternative solution if we run into more Swift leakages into Objective-C would be to backtrack and create a framework target where we can have mixed languages. I might set aside some time today to search for #import "WordPress-Swift.h" usages and see how much extra steps like this would be needed if we kept the packages setup.
| 1 Message | |
|---|---|
| :book: | This PR is still a Draft: some checks will be skipped. |
Generated by :no_entry_sign: Danger
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr24191-cb9162d | |
| Version | 25.8 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | cb9162dc14cc2da950d3eedfc845368cb88a6a3c | |
| App Center Build | WPiOS - One-Offs #11635 |
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr24191-cb9162d | |
| Version | 25.8 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | cb9162dc14cc2da950d3eedfc845368cb88a6a3c | |
| App Center Build | jetpack-installable-builds #10666 |
@crazytonyli
Sorry if I missed the discussion, but any reason not moving ContextManager into WordPressData too?
ContextManager will eventually go into WordPressData, yes. (Current broken WIP PR that reveals all these issues https://github.com/wordpress-mobile/WordPress-iOS/pull/24166)
I wonder whether moving ContextManager first would be easier for moving the managed objects. Like, this decoupling refactor would not be necessary if ContextManager is already in WordPressData.
this decoupling refactor would not be necessary if ContextManager is already in WordPressData.
I think it would still be necessary if we have WordPressData the Swift package + WordPressDataObjC the Swift package with only Objective-C files. Because WordPressData depends on WordPressDataObjC, and therefore WordPressDataObjC cannot depend on WordPressData. But ContextManager is in WordPressData and the AbstractPost in WordPressDataObjc.
@crazytonyli your question actually made me realize that some of the models are Objective-C and others are Swift. I'll need to quickly verify whether they can work sparse between the two packages, or if I should just call it quits on the package and use a framework instead :/
Looks like it's obsolete now.