Entity classes not found from frameworks #112

Closed
opened 2025-12-29 15:24:48 +01:00 by adam · 4 comments
Owner

Originally created by @deanWombourne on GitHub (Dec 21, 2016).

Hi,

If I make a framework which uses CoreStore, then the entity classes aren't being found.The exception is being thrown from DataStack.swift:484 on the swift3_develop branch (commit 23df460c35 according to my pod file.lock)

Playing around in the debugger, I get this:

(lldb) po managedObjectClassName
"TaskTimerModel.ClientEntity"

(lldb) po NSClassFromString(managedObjectClassName)
nil

(lldb) po NSClassFromString("ClientEntity")
nil

However, I can get it to find the class if I go to my framework bundle directly, and remove the module prefix from the class.

(lldb) po Bundle.allFrameworks[29]
( this is my framework containing the entity classes)

(lldb) po Bundle.allFrameworks[29].classNamed("ClientEntity")
▿ Optional<AnyObject.Type>
  - some : TaskTimerModel.ClientEntity

(lldb) po Bundle.allFrameworks[29].classNamed("TaskTimerModel.ClientEntity")
nil

Not sure how to fix this reliably, or where else in the library this issue might become apparent, sorry!

Originally created by @deanWombourne on GitHub (Dec 21, 2016). Hi, If I make a framework which uses CoreStore, then the entity classes aren't being found.The exception is being thrown from `DataStack.swift:484` on the swift3_develop branch (commit 23df460c3587503b61dc608380a076195b7434bf according to my pod file.lock) Playing around in the debugger, I get this: ``` (lldb) po managedObjectClassName "TaskTimerModel.ClientEntity" (lldb) po NSClassFromString(managedObjectClassName) nil (lldb) po NSClassFromString("ClientEntity") nil ``` However, I can get it to find the class if I go to my framework bundle directly, and remove the module prefix from the class. ``` (lldb) po Bundle.allFrameworks[29] ( this is my framework containing the entity classes) (lldb) po Bundle.allFrameworks[29].classNamed("ClientEntity") ▿ Optional<AnyObject.Type> - some : TaskTimerModel.ClientEntity (lldb) po Bundle.allFrameworks[29].classNamed("TaskTimerModel.ClientEntity") nil ``` Not sure how to fix this reliably, or where else in the library this issue might become apparent, sorry!
adam closed this issue 2025-12-29 15:24:48 +01:00
Author
Owner

@deanWombourne commented on GitHub (Dec 21, 2016):

Hmmm, just to make this more interesting, I backed up one commit to where the classes were all in the same module, and I got exactly the same error.

I fixed it by getting Xcode to create the managed object subclasses automatically instead of manually. Then, the managedObjectClassName didn't contain the module prexfix, and NSClassFromString worked. I have absolutely no idea why.

@deanWombourne commented on GitHub (Dec 21, 2016): Hmmm, just to make this more interesting, I backed up one commit to where the classes were all in the same module, and I got exactly the same error. I fixed it by getting Xcode to create the managed object subclasses automatically instead of manually. Then, the managedObjectClassName didn't contain the module prexfix, and NSClassFromString worked. I have absolutely no idea why.
Author
Owner

@JohnEstropia commented on GitHub (Dec 26, 2016):

Hi, I am not sure you can get the same behavior from the llvm debugger as the modules loaded there are different from the ones in the swift file. Have you tried marking your classes as @objc or public open?

@JohnEstropia commented on GitHub (Dec 26, 2016): Hi, I am not sure you can get the same behavior from the llvm debugger as the modules loaded there are different from the ones in the swift file. Have you tried marking your classes as `@objc` or `public open`?
Author
Owner

@deanWombourne commented on GitHub (Dec 29, 2016):

They're already @objc public :(

However, it seems to work if I don't select anything in the Module dropdown in Xcode (i.e. use the default Global namespace) instead of choosing 'Current Product Module'. The sum total of the change to xcdatamodel/contents is this:

-    <entity name="ClientEntity" representedClassName="ClientEntity" syncable="YES">
+    <entity name="ClientEntity" representedClassName=".ClientEntity" syncable="YES">

First line works (i.e. class name is just ClientEntity) but the second one fails (class name becomes TaskTimer.ClientEntity, which isn't found).

I'm fine leaving them in the global namespace for this app and it's working great (ps I'm loving CoreStore ;) but it does mean that if I wanted to build a library with CoreStore I might run into trouble.

I'll keep playing around and see what other class I can find.

@deanWombourne commented on GitHub (Dec 29, 2016): They're already `@objc public` :( However, it seems to work if I don't select anything in the Module dropdown in Xcode (i.e. use the default Global namespace) instead of choosing 'Current Product Module'. The sum total of the change to xcdatamodel/contents is this: ``` - <entity name="ClientEntity" representedClassName="ClientEntity" syncable="YES"> + <entity name="ClientEntity" representedClassName=".ClientEntity" syncable="YES"> ``` First line works (i.e. class name is just `ClientEntity`) but the second one fails (class name becomes `TaskTimer.ClientEntity`, which isn't found). I'm fine leaving them in the global namespace for this app and it's working great (ps I'm loving CoreStore ;) but it does mean that if I wanted to build a library with CoreStore I might run into trouble. I'll keep playing around and see what other class I can find.
Author
Owner

@JohnEstropia commented on GitHub (Dec 31, 2016):

You can also try to declare the module name explicitly in your xcdatamodel instead of Current Product Module.

I'll close this issue as this seems to be more of a model configuration mismatch than a CoreStore problem. Thanks for the feedback!

@JohnEstropia commented on GitHub (Dec 31, 2016): You can also try to declare the module name explicitly in your xcdatamodel instead of `Current Product Module`. I'll close this issue as this seems to be more of a model configuration mismatch than a CoreStore problem. Thanks for the feedback!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#112