Cocoa: Finding the window that your sheet is attached to

I recently had a situation where I needed to chain together two modal sheets off the same window. When the first sheet was presented, I obviously had the NSWindow object for the window I wanted to attach to. Since my sheet had its own controller object, I could have simply stored this NSWindow object and used it later for the next sheet.

However, I decided – largely as a matter of taste – that I’d rather figure out the sheet’s “parent” window programmatically in the didEndSelector when the first sheet is dismissed. That way I don’t need to store the parent window anywhere in my controller.

Continue reading