Milliways
Milliways

Reputation: 1275

No known instance method for selector 'myWindowController'

I have the following code in an app (which was written in 2011).

[[[[NSApp delegate] myWindowController] ...] ..];

Since upgrading to Xcode 6.1 This produces the following error:- ARC Semantic Issue No known instance method for selector 'myWindowController'

Replacing this by the following generates no error.

id ttt = [NSApp delegate];
[[[ttt myWindowController] ...] ...];

PS Xcode seems to think the type is 'id<NSFileManagerDelegate>'

What is going on here?

I admit to being very rusty with Cocoa and Xcode. I am sure I could fix it by an appropriate cast, but this seems unnecessary, and I am attempting to understand why.

Further information

My AppDelegate.h

IBOutlet MyWindowController *myWindowController;

And AppDelegate.m

@synthesize myWindowController;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    myWindowController = [[MyWindowController alloc] initWithWindowNibName:@"MainWindow"];

Upvotes: 1

Views: 572

Answers (2)

harrisg
harrisg

Reputation: 633

  1. Make sure you are importing the header containing the MyWindowController @interface definition.
  2. Cast your [NSApp delegate] with (MyWindowController *).

So your original line:

[[[[NSApp delegate] myWindowController] ...] ..];

should become:

[[[(MyAppDelegate *)[NSApp delegate] myWindowController] ...] ..];

You could also cast with (id), which is effectively what you are doing with the ttt variable, but that's cheating a little. Using the proper class when casting will give you better compiler checking as well as helping Xcode make accurate autocomplete suggestions (which is a good way to detect errors before they happen). Basically an object declared or cast as id means it can be an object of any class so any method that is defined in any class will be considered valid.

I'm having the same issue with Xcode 6.1 myself. I think the compiler changed somehow in Xcode 6.1. I wish I had an answer for why, myself. It doesn't instill a lot of confidence in Xcode 6.1.

Upvotes: 0

Milliways
Milliways

Reputation: 1275

I resolved this with a cast (MyAppDelegate *).

[[[(MyAppDelegate *)[NSApp delegate] myWindowController] currentTvc] saveTableColumns]; // Xcode 6.1 error

I have concluded this is an Xcode 6.1 error as it seems to think [NSApp delegate] returns type id<NSFileManagerDelegate>

Upvotes: 1

Related Questions