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

# displayIfNeeded()

Displays the view and all its subviews if any part of the view has been marked as needing display.

```
func displayIfNeeded()
```

## Discussion

This method invokes the `NSView` methods [`lockFocus()`](/documentation/AppKit/NSView/lockFocus()), [`draw(_:)`](/documentation/AppKit/NSView/draw(_:)), and [`unlockFocus()`](/documentation/AppKit/NSView/unlockFocus()) as necessary. If the view isn’t opaque, this method backs up the view hierarchy to the first opaque ancestor, calculates the portion of the opaque ancestor covered by the view, and begins displaying from there.

---

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)