Question: My app have Preferences window. I open it using this code

```
- (IBAction)openPreferences:(id)sender {

    NSWindowController *windowController = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"];
    [windowController window];
}

```

If press **command,** again-again and again new Preferences window will be opened again-again and again...

How open only one window? Thanks!

Answer: 
Make windowController a instance variable of your AppDelegate and change your open preferences to

```
- (IBAction)openPreferences:(id)sender
{
    if( windowController == nil )
        windowController = [[NSWindowController alloc] initWithWindowNibName:@"Preferences"];
    [windowController showWindow:sender];
}

```
So this is how I solved it...
I have a class "MyPreferencesWindowController" which has a method called `getInstance`. This method is what is called when you want to get the preferences window. This solution takes advantage of singleton technology.

```
/**
Method in my MyPreferencesWindowController.m file
with a corresponding method in the .h file.
*/
+(id) getInstance {

    static PreferencesWindowController *instance = nil;
    static dispatch_once_t onceToken;

    dispatch_once(&onceToken, ^{
        instance = [[self alloc] init];
    });
    return instance;
}

```

Now in the Document class, when you want to show the preferences window, do the following:

```
-(IBAction) showPreferences:(id)sender {
    if (preferencesWc  == nil)
        preferencesWc = [MyPreferencesWindowController getInstance];

    [ preferencesWc showWindow:self ];
}

```

This will ensure the preferences window is only created once. And then each call to `getInstance` will return the same instance of the window.