-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Move xcdatamodeld
into WordPressData
#24166
Conversation
Generated by 🚫 Danger |
<entity name="BloggingPrompt" representedClassName=".BloggingPrompt" syncable="YES"> | ||
<entity name="BloggingPrompt" representedClassName="WordPressData.BloggingPrompt" syncable="YES"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public let modelURL: URL = { | ||
guard let url = Bundle.module.url(forResource: "WordPress", withExtension: "momd") else { | ||
fatalError("Cannot find model file.") | ||
} | ||
return url | ||
}() | ||
|
||
public func urlForModel(name: String, in directory: String?) -> URL? { | ||
let bundle = Bundle(for: TemporaryDummyClassToPickUpModule.self) | ||
var url = bundle.url(forResource: name, withExtension: "mom", subdirectory: directory) | ||
|
||
if url != nil { | ||
return url | ||
} | ||
|
||
let momdPaths = bundle.paths(forResourcesOfType: "momd", inDirectory: directory) | ||
momdPaths.forEach { (path) in | ||
if url != nil { | ||
return | ||
} | ||
url = bundle.url(forResource: name, withExtension: "mom", subdirectory: URL(fileURLWithPath: path).lastPathComponent) | ||
} | ||
|
||
return url | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These free functions should go into an object at some point.
It was just simpler to chuck them in here at this stage while I figure things out.
Also, I'd like to think there will be no need to have them public
once all the types involved in setting up the Core Data stack have been moved.
|
App Name | ![]() |
|
Configuration | Release-Alpha | |
Build Number | pr24166-43bb76a | |
Version | 25.8 | |
Bundle ID | com.jetpack.alpha | |
Commit | 43bb76a | |
App Center Build | jetpack-installable-builds #10655 |
|
App Name | ![]() |
|
Configuration | Release-Alpha | |
Build Number | pr24166-43bb76a | |
Version | 25.8 | |
Bundle ID | org.wordpress.alpha | |
Commit | 43bb76a | |
App Center Build | WPiOS - One-Offs #11624 |
Have you tried overriding an Objective-C class name for the managed objects written in Swift?
|
81890b9
to
57a9e60
Compare
@kean yes I did try that. I removed it from the code pushed here because it did not make any difference |
b94d69d
to
e1eb0b3
Compare
This is so the diff is neater next when moving it to WordPressShared
Turned out there needed to be move access control changes than those done in the previous commit...
We'll obviously have to deal with this at some point, but doing it while moving the files from the app targets to the new module is not the right time.
Swift-ier + Saves making `sharedInstance()` public when migrating
Not the best approach, but fine because the property is for testing only.
Currently unused, but we'll use them soon when moving more of the Objective-C models.
58f69c3
to
b0517a3
Compare
…odeld-to-wordpressdata
All those Swift files compile without importing UIKit because `SFHFKeychainUtils.h` did that for them and they got access to it via the bridging header. Next, we'll move SFHFKeychainUtils into the modules, and UIKit will no longer be available through it. Side note: UIKit should not have been available via SFHFKeychainUtils in the first place. On top of that, SFHFKeychainUtils does not need UIKit either.
We need it in a dedicated package because the Objective-C implementation does not use ARC. Therefore, we need to use the `-fno-objc-arc` compiler setting. But such a setting should be applied sparingly so instead of blanket using it in an existing Objective-C package like WordPressSharedObjC, we use it surgically just for this file.
This is to decouple the Objective-C implementation from knowing about components (i.e. `ContextManager`) in the Swift layer.
To much Objective-C code using logic implemented elsewhere in Swift for us to be able to move the files in two separate Objective-C- and Swift- only packages. Refer to #24166 as an experiment for this that shows the various build failure that even a partial attempt at moving some files results in.
To much Objective-C code using logic implemented elsewhere in Swift for us to be able to move the files in two separate Objective-C- and Swift- only packages. Refer to #24166 as an experiment for this that shows the various build failure that even a partial attempt at moving some files results in.
To much Objective-C code using logic implemented elsewhere in Swift for us to be able to move the files in two separate Objective-C- and Swift- only packages. Refer to #24166 as an experiment for this that shows the various build failure that even a partial attempt at moving some files results in.
To much Objective-C code using logic implemented elsewhere in Swift for us to be able to move the files in two separate Objective-C- and Swift- only packages. Refer to #24166 as an experiment for this that shows the various build failure that even a partial attempt at moving some files results in.
To much Objective-C code using logic implemented elsewhere in Swift for us to be able to move the files in two separate Objective-C- and Swift- only packages. Refer to #24166 as an experiment for this that shows the various build failure that even a partial attempt at moving some files results in.
Closing in favor of #24242 |
To much Objective-C code using logic implemented elsewhere in Swift for us to be able to move the files in two separate Objective-C- and Swift- only packages. Refer to #24166 as an experiment for this that shows the various build failure that even a partial attempt at moving some files results in.
To much Objective-C code using logic implemented elsewhere in Swift for us to be able to move the files in two separate Objective-C- and Swift- only packages. Refer to #24166 as an experiment for this that shows the various build failure that even a partial attempt at moving some files results in.
Part of #24165
Note
As I try to move more model files, I keep pulling at the intricate dependencies that grew in the codebase.
I'll be leaving comments in the diff as starting point for code to extract in order to enable this PR.
Note
Work in Progress. So far:
xcdatamodeld
folder into the module and updated the code that referenced its URL to read it from the moduleBloggingPrompt
(apparently the first model to load at runtime). The error was withFatal error: NSArray element failed to match the Swift Array Element type . Expected BloggingPrompt got NSManagedObject
.BloggingPrompt
to WordPressDataFatal error: NSArray element failed to match the Swift Array Element type . Expected BloggingPrompt got NSManagedObject
I don't like this solution because it would require editing the schema for each model. Besides, the compiler (or whichever piece is involved in going from the schema to the binary) should be able to inject the correct module name without hardcoding.
Leaving this up as a draft so that others can look at it.
The next thing I'll try will be to move more of the components involved in making the Core Data fetch request, the
NSManagedObjectContext
in particular, and see if it gets the namespace resolution to work without hardcoding.Fixes #
To test:
Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
PR submission checklist:
RELEASE-NOTES.txt
if necessary.Testing checklist: