swift+cocoa+bundle mystifying issue

my app, which loads plugins, has just stopped loading my test plugin.


I am dumbfounded by this issue. I will tell you what is going wrong. and I will tell you what was the very last thing I did. They are related but there is no reason to think that I have done anythign to cause this problem.


what is not going right:

I find my plugin, which is a bundle, and I try to load the principle class:

let aBundle = Bundle(url: anItem)
                if let cls = aBundle?.principalClass as? CNPluginController.Type {
                    let plugin = cls.init()
                    plugins += [plugin]
                }


until about 20 minutes ago, for nearly a year, this code has worked.

the if let line, is now failing. So the bundle is found (I can see that in the debugger) but the principle class is not a CNPluginController class.


now, as I said, I have just about an entire year of this code working. I wasn't mucking around in it. But... CNPluginController is defined in a framework, that is imported in both my app and the plugin. the framework is embedded as necessary, and it too hasn't seen any changes in months.


what was I doing when my app just failed to load plugins?

I created 2 new Swift files, in that plugin, and moved the code for 2 classes from a pre-existing file into those new files.

these files are part of the plugin's target, they do not under any circumstances conflict with the principle class, and yes... they are literally code that we already know: works just fine in the plugin.


I am mystified. I cannot account for this issue. My best guess is that the plugin has lost track of it's principle class type. But... it's clearly set in the info.plist, and I've cleaned the build folder now a half a dozen times.


any ideas welcome.

Accepted Reply

I commented out nearly all of the code in the class in the offending file.

no change.


so i copied ALL of the text content of the file, deleted the file, made a new file with the exact same name, and pasted the same text into the file.


this fixed my plugin.


in english: Xcode made a file that jacknifed it's compile.

and then 2 hours later, it made a new file with teh same name name... that didn't jacknife compilation.

Houston we have a bug in Xcode. who would have guessed.

Replies

I have identified the file out of the two, that is "causing" this issue.

I have been over the code with a fine tooth comb.


I have for instance: copied the code out of the file, and put the exact same code into a file that already has a class in it. Then I exclude the offending file from the target. Building and running that works without issues. Put it all back together, and it doesn't load.


so: my code is fine.


I've checked for namespace collisions. I changed the name of the file and the class. no dice.

So: it's clearly not a namespace collision.


This is a nightmare of a bug. one i do not need.

I commented out nearly all of the code in the class in the offending file.

no change.


so i copied ALL of the text content of the file, deleted the file, made a new file with the exact same name, and pasted the same text into the file.


this fixed my plugin.


in english: Xcode made a file that jacknifed it's compile.

and then 2 hours later, it made a new file with teh same name name... that didn't jacknife compilation.

Houston we have a bug in Xcode. who would have guessed.