9

I am trying to instantiate an NSWindowController from a storyboard in my OS X app:

NSWindowController *mainWindowController = [[NSStoryboard storyboardWithName:@"Main" bundle:nil] instantiateControllerWithIdentifier:@"MainWindow"];

But this is what I'm getting:

Storyboard (<NSStoryboard: 0x618000008500>) doesn't contain a controller with identifier 'MainWindow'.

But in the storyboard:

enter image description here

It is set. No, there are no other storyboards. Yes, I've tried cleaning the project and the build folder, but nothing changes.

Why would I get this error?

UPDATE: I am building my app, coming back to the storyboard, and I see that Storyboard ID is unset:

enter image description here

How can Storyboard ID get unset by itself?

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389

1 Answers1

19

It was definitely a bug with Xcode. Restarting Xcode solved the problem.

Can Poyrazoğlu
  • 33,241
  • 48
  • 191
  • 389
  • 9
    When it happened to me, I noticed that the storyboard ID of the window controller is gone every time I close the project and open it again. It must have been a bug related to the autosave feature. I manually saved the storyboard file and Clean - Build - Run. it worked.Your own answer helped me sir. – Kyle KIM Oct 26 '16 at 07:17
  • what more, this bug still exists in XCode 9.3 beta 4, nice job apple boys! – Hofi Mar 26 '18 at 10:44
  • 1
    And still a problem in Version 10.1 (10B61) – hocker Mar 11 '19 at 16:00
  • 1
    it resets the id to empty every relaunch. Version 10.2 – Ken Zira Apr 07 '19 at 03:13
  • @KenZira I've been having the same issue. Have you tried the steps listed above? – Jake3231 Apr 07 '19 at 21:15
  • This issue still exists in Version 10.3 (10G8) – MacDeveloper Jan 10 '20 at 13:00