<!--
{
  "documentType" : "article",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/app-windows",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "App Windows"
}
-->

# App Windows

Show, hide, minimize, arrange, and update your app’s windows.

## Topics

### Managing App Windows

[`var keyWindow: NSWindow?`](/documentation/AppKit/NSApplication/keyWindow)

The window that currently receives keyboard events.

[`var mainWindow: NSWindow?`](/documentation/AppKit/NSApplication/mainWindow)

The app’s main window.

[`func window(withWindowNumber: Int) -> NSWindow?`](/documentation/AppKit/NSApplication/window(withWindowNumber:))

Returns the window corresponding to the specified window number.

[`var windows: [NSWindow]`](/documentation/AppKit/NSApplication/windows)

An array of the app’s window objects.

[`func makeWindowsPerform(Selector, inOrder: Bool) -> NSWindow?`](/documentation/AppKit/NSApplication/makeWindowsPerform(_:inOrder:))

Sends the specified message to each of the app’s window objects until one returns a non-`nil` value.

[`func enumerateWindows(options: NSApplication.WindowListOptions, using: (NSWindow, UnsafeMutablePointer<ObjCBool>) -> Void)`](/documentation/AppKit/NSApplication/enumerateWindows(options:using:))

Executes a block for each of the app’s windows.

[`struct WindowListOptions`](/documentation/AppKit/NSApplication/WindowListOptions)

This constant indicates a window ordering.

### Minimizing Windows

[`func miniaturizeAll(Any?)`](/documentation/AppKit/NSApplication/miniaturizeAll(_:))

Miniaturizes all the receiver’s windows.

### Hiding Windows

[`var isHidden: Bool`](/documentation/AppKit/NSApplication/isHidden)

A Boolean value indicating whether the app is hidden.

[`func hide(Any?)`](/documentation/AppKit/NSApplication/hide(_:))

Hides all the receiver’s windows, and the next app in line is activated.

[`func unhide(Any?)`](/documentation/AppKit/NSApplication/unhide(_:))

Restores hidden windows to the screen and makes the receiver active.

[`func unhideWithoutActivation()`](/documentation/AppKit/NSApplication/unhideWithoutActivation())

Restores hidden windows without activating their owner (the receiver).

### Updating Windows

[`func updateWindows()`](/documentation/AppKit/NSApplication/updateWindows())

Sends an [`update()`](/documentation/AppKit/NSWindow/update()) message to each onscreen window.

[`func setWindowsNeedUpdate(Bool)`](/documentation/AppKit/NSApplication/setWindowsNeedUpdate(_:))

Sets whether the receiver’s windows need updating when the receiver has finished processing the current event.

### Managing Window Layers

[`func preventWindowOrdering()`](/documentation/AppKit/NSApplication/preventWindowOrdering())

Suppresses the usual window ordering in handling the most recent mouse-down event.

[`func arrangeInFront(Any?)`](/documentation/AppKit/NSApplication/arrangeInFront(_:))

Arranges windows listed in the Window menu in front of all other windows.

### Drawing Windows

[`var context: NSGraphicsContext?`](/documentation/AppKit/NSApplication/context)

The graphics context associated with the app.

### Getting the Occlusion State

[`var occlusionState: NSApplication.OcclusionState`](/documentation/AppKit/NSApplication/occlusionState-swift.property)

The occlusion state of the app.

[`struct OcclusionState`](/documentation/AppKit/NSApplication/OcclusionState-swift.struct)

This constant indicates whether at least part of any window owned by this app is visible.

### Restoring App Windows at Launch

[`var isProtectedDataAvailable: Bool`](/documentation/AppKit/NSApplication/isProtectedDataAvailable)

[`func extendStateRestoration()`](/documentation/AppKit/NSApplication/extendStateRestoration())

Allows an app to extend its state restoration period.

[`func completeStateRestoration()`](/documentation/AppKit/NSApplication/completeStateRestoration())

Completes the extended state restoration.

[`func restoreWindow(withIdentifier: NSUserInterfaceItemIdentifier, state: NSCoder, completionHandler: (NSWindow?, (any Error)?) -> Void) -> Bool`](/documentation/AppKit/NSApplication/restoreWindow(withIdentifier:state:completionHandler:))

Invoked to request that a window be restored.

### Managing Run Loops

[`class var displayWindowRunLoopOrdering: Int`](/documentation/AppKit/NSApplication/displayWindowRunLoopOrdering)

The priority at which windows are displayed.

[`class var resetCursorRectsRunLoopOrdering: Int`](/documentation/AppKit/NSApplication/resetCursorRectsRunLoopOrdering)

The priority at which cursor rects are reset.

[`class var updateWindowsRunLoopOrdering: Int`](/documentation/AppKit/NSApplication/updateWindowsRunLoopOrdering)

Run-loop message priority for handling window updates.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)