Thanks for your quick reply. I agree that the shared application object is NSApplication, though I am still baffled as to why. Built application does have correct names in Info.plist. I found some code to “manually” go through the instantiation process, in the hope of getting a better understanding of what’s happening. Code as follows (I’ve added extra instrumentation):
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSString *pc = [infoDictionary objectForKey:@"NSPrincipalClass"]; printf("Principal class name from Info.plist: %s\n", pc.UTF8String);
Class principalClass = NSClassFromString([infoDictionary objectForKey:@"NSPrincipalClass"]); printf("Principal class name from Class object: %s\n", object_getClassName(principalClass));
printf("'Class' object responds to class method 'sharedApplication:' - %d\n", [principalClass respondsToSelector:@selector(sharedApplication)]); printf("'Class' object responds to class method 'test' - %d\n", [principalClass respondsToSelector:@selector(test)]); [principalClass test];
NSApplication *applicationObject = [principalClass sharedApplication]; printf("applicationObject class name %s\n", [applicationObject className].UTF8String); printf("applicationObject responds to class method 'test' - %d\n", [applicationObject respondsToSelector:@selector(test)]);
NSString *mainNibName = [infoDictionary objectForKey:@"NSMainNibFile"]; NSNib *mainNib = [[NSNib alloc] initWithNibNamed:mainNibName bundle:[NSBundle mainBundle]]; [mainNib instantiateNibWithOwner:applicationObject topLevelObjects:nil];
The class method ‘test’ is one that I have defined on SpimApplication.
When I run this code, output is: Principal class name from Info.plist: SpimApplication Principal class name from Class object: SpimApplication 'Class' object responds to class method 'sharedApplication:' - 1 'Class' object responds to class method 'test' - 1 'test' class method successfully called applicationObject class name NSApplication applicationObject responds to class method 'test' - 0
followed by exception on final call due to bindings failing to be set up.
So, it seems that the principal class is correct, but + sharedApplication is not instantiating my subclass for some reason. I don’t believe I do anything funny in SpimApplication, the only method I override from superclass is -(id)init, which is never being called in this case. Again, I haven’t changed anything in this class that I believe is relevant to the problem at hand. Any thoughts as to why +sharedApplication, called on the correct principalClass object, should be resulting in only the superclass being instantiated? The class is declared: @interface SpimApplication : NSApplication
[I know that we are strictly forbidden from overriding +sharedApplication, but just to see what happened I did try declaring it for SpimApplication, just calling through to super. My version *is* called, but unsurprisingly the returned object is of type NSApplication, so not sure that told me anything I didn’t already know]
Any thoughts?
On 16 Jul 2014, at 11:32, Ken Thomases < email@hidden> wrote:
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
|