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

# lockFocusIfCanDraw()

Locks the focus to the view atomically if the `canDraw` method returns `true` and returns the value of `canDraw`.

```
func lockFocusIfCanDraw() -> Bool
```

## Discussion

Your thread will not be preempted by other threads between the `canDraw` method and the lock. This method fails to lock focus and returns <doc://com.apple.documentation/documentation/Swift/false>, when the view is hidden and the current context is drawing to the screen (as opposed to a printing context).

---

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)