WordPress-iOS icon indicating copy to clipboard operation
WordPress-iOS copied to clipboard

Abstract `ContextManager` usages behind `CoreDataStack`

Open mokagio opened this issue 9 months ago • 7 comments

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.

mokagio avatar Mar 11 '25 22:03 mokagio

1 Message
:book: This PR is still a Draft: some checks will be skipped.

Generated by :no_entry_sign: Danger

dangermattic avatar Mar 11 '25 22:03 dangermattic

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr24191-cb9162d
Version25.8
Bundle IDorg.wordpress.alpha
Commitcb9162dc14cc2da950d3eedfc845368cb88a6a3c
App Center BuildWPiOS - One-Offs #11635
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

wpmobilebot avatar Mar 11 '25 22:03 wpmobilebot

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr24191-cb9162d
Version25.8
Bundle IDcom.jetpack.alpha
Commitcb9162dc14cc2da950d3eedfc845368cb88a6a3c
App Center Buildjetpack-installable-builds #10666
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

wpmobilebot avatar Mar 11 '25 22:03 wpmobilebot

@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)

mokagio avatar Mar 12 '25 01:03 mokagio

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.

crazytonyli avatar Mar 12 '25 01:03 crazytonyli

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.

mokagio avatar Mar 12 '25 03:03 mokagio

@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 :/

mokagio avatar Mar 12 '25 03:03 mokagio

Looks like it's obsolete now.

kean avatar Aug 29 '25 18:08 kean