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

# performSynchronousFileAccess(_:)

Waits for any scheduled file access to complete, then invokes the passed-in block.

```
nonisolated func performSynchronousFileAccess(_ block: () -> Void)
```

## Parameters

`block`

A block that performs file access.

## Discussion

Given a block that will perform file access, this method waits for any file access scheduled by previous invocations of this method or [`performAsynchronousFileAccess(_:)`](/documentation/AppKit/NSDocument/performAsynchronousFileAccess(_:)) to complete, then invokes the passed-in block. When the block invocation returns, the method allows the next scheduled file access to to be performed, if any.

Like [`performActivity(withSynchronousWaiting:using:)`](/documentation/AppKit/NSDocument/performActivity(withSynchronousWaiting:using:)), this method’s primary use is to wait for asynchronous saving, but in contrast with that method it is only for the part of an asynchronous saving operation that actually touches the document’s file or values in memory that are relative to the document’s file.

In general, you should use this method or [`performAsynchronousFileAccess(_:)`](/documentation/AppKit/NSDocument/performAsynchronousFileAccess(_:)) around code that gets or sets values in memory that only make sense in the context of the document file’s current state. For example, `NSDocument` itself consistently uses this mechanism when using the following methods and properties:

- The [`fileType`](/documentation/AppKit/NSDocument/fileType), [`fileURL`](/documentation/AppKit/NSDocument/fileURL), [`fileModificationDate`](/documentation/AppKit/NSDocument/fileModificationDate), and [`autosavedContentsFileURL`](/documentation/AppKit/NSDocument/autosavedContentsFileURL) properties, because you can’t reliably make decisions based on a file’s location, type, or modification date when it is being asynchronously moved, renamed, or changed at that moment.
- The [`isDocumentEdited`](/documentation/AppKit/NSDocument/isDocumentEdited) and [`hasUnautosavedChanges`](/documentation/AppKit/NSDocument/hasUnautosavedChanges) properties, because you can’t reliably make decisions based on whether the document’s contents in memory have been saved to a file when it is being asynchronously saved at that moment.
- [`updateChangeCount(withToken:for:)`](/documentation/AppKit/NSDocument/updateChangeCount(withToken:for:)) and, sometimes, [`updateChangeCount(_:)`](/documentation/AppKit/NSDocument/updateChangeCount(_:)), to make using this mechanism when invoking [`isDocumentEdited`](/documentation/AppKit/NSDocument/isDocumentEdited) and [`hasUnautosavedChanges`](/documentation/AppKit/NSDocument/hasUnautosavedChanges) meaningful.

---

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)