https://github.com/chris-huxtable/cbhwindowmanager
An easy-to-use singleton which manages `NSWindow` and `NSWindowController` objects
https://github.com/chris-huxtable/cbhwindowmanager
objective-c objective-c-library window-manager
Last synced: 10 months ago
JSON representation
An easy-to-use singleton which manages `NSWindow` and `NSWindowController` objects
- Host: GitHub
- URL: https://github.com/chris-huxtable/cbhwindowmanager
- Owner: chris-huxtable
- License: isc
- Created: 2019-08-14T03:26:52.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-27T21:52:52.000Z (over 6 years ago)
- Last Synced: 2025-03-11T06:50:32.859Z (over 1 year ago)
- Topics: objective-c, objective-c-library, window-manager
- Language: Objective-C
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CBHWindowManager
[](https://github.com/chris-huxtable/CBHWindowManager/releases)
[](https://cocoapods.org/pods/CBHWindowManager)
[](https://github.com/chris-huxtable/CBHWindowManager/blob/master/LICENSE)
[](https://github.com/chris-huxtable/CBHWindowManager)
An easy-to-use singleton which manages `NSWindow` and `NSWindowController` objects.
## Examples:
Adding a controller so that once the window is closed both the window and controller are released.
```objective-c
SomeWindowController *controller = [[[SomeWindowController class] alloc] initWithWindowNibName:@"SomeWindowNibName"];
[[CBHWindowManager sharedManager] manageController:controller];
```
Adding a controller with a key so that it may be found by name.
```objective-c
/// Create and adding the controller withe key.
SomeWindowController *controller = [[[SomeWindowController class] alloc] initWithWindowNibName:@"SomeWindowNibName"];
[[CBHWindowManager sharedManager] manageController:controller withKey:@"SomeWindowKey"];
// ...
/// Lookup the controller
SomeWindowController *controller = [[CBHWindowManager sharedManager] controllerForKey:@"SomeWindowKey"];
```
Finding a controller with a key and if not creating and adding one.
```objective-c
/// Lookup the controller in the manager. If it's found, return early.
SomeWindowController *controller = (SomeWindowController *)[[CBHWindowManager sharedManager] controllerForKey:@"SomeWindowKey"];
if ( controller ) { return controller; }
/// If the controller is not in the manager create it and add it to the manger.
controller = [[[SomeWindowController class] alloc] initWithWindowNibName:@"SomeWindowNibName"];
[[CBHWindowManager sharedManager] manageController:controller withKey:@"SomeWindowKey"];
return controller;
```
## Licence
CBHWindowManager is available under the [ISC license](https://github.com/chris-huxtable/CBHWindowManager/blob/master/LICENSE).