swiftnsbundle

Why does my Swift bundle get the wrong principal class?


I made a bundle target, and its Info.plist file specifies that a very specific class (let's call it PrincipalClass) should be its principal class. This class was written in Swift and has the @objc attribute. The Info.plist file is correctly copied over to the bundle, and I have cleaned and rebuilt the project multiple times already.

However, when I load the bundle from my Swift framework, its principal class is a different class (let's call it NotPrincipalClass). It was not marked @objc, and in fact, it should be internal to the bundle. I checked bundle.bundleURL in the debugger, and the Info.plist file in the bundle does say that it should be PrincipalClass; but when I check bundle.infoDictionary, the NSPrincipalClass attribute reads NotPrincipalClass as a string! (The info dictionary also contains several keys that were not specified by the Info.plist file, like DTCompiler and such.)

If I entirely remove NotPrincipalClass, I get another internal class instead, which is still totally not my principal class.

I checked the build logs thoroughly and I saw no mention of NotPrincipalClass, except when it got compiled.

What could cause this? What can I do to solve it?


Solution

  • Somehow, using its qualified name instead ("PlugInNamespace.PrincipalClass") solved the problem, but this has me very skeptical because I have another plugin that does not requires this.