<!--
{
  "availability" : [
    "macOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSWindow/recalculateKeyViewLoop()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSWindow(im)recalculateKeyViewLoop"
  },
  "title" : "recalculateKeyViewLoop()"
}
-->

# recalculateKeyViewLoop()

Marks the key view loop as “dirty” and in need of recalculation.

```
func recalculateKeyViewLoop()
```

## Discussion

The key view loop is recalculated the next time someone requests the next or previous key view of the window. The recalculated loop is based on the geometric order of the views in the window.

If you don’t want to maintain the key view loop of your window manually, you can use this method to do it for you. When it’s first loaded, `NSWindow` calls this method automatically if your window doesn’t have a key view loop already established. If you add or remove views later, you can call this method manually to update the window’s key view loop. You can also set the [`autorecalculatesKeyViewLoop`](/documentation/AppKit/NSWindow/autorecalculatesKeyViewLoop) property to have the window recalculate the loop automatically.

---

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)