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

# openUntitledDocumentAndDisplay(_:)

Creates a new untitled document, presents its user interface if `displayDocument` is `true`, and returns the document if successful.

```
func openUntitledDocumentAndDisplay(_ displayDocument: Bool) throws -> NSDocument
```

## Parameters

`displayDocument`

<doc://com.apple.documentation/documentation/Swift/true> if the user interface for the document should be shown, otherwise <doc://com.apple.documentation/documentation/Swift/false>.

## Return Value

Returns the new [`NSDocument`](/documentation/AppKit/NSDocument) object, or `nil` if a new untitled document could not be created. If this method returns `nil`, it also sets the address referenced by `outError` to an `NSError` object that tell why the document could not be created.

## Discussion

The default implementation of this method calls [`defaultType`](/documentation/AppKit/NSDocumentController/defaultType) to determine the type of new document to create, calls [`makeUntitledDocument(ofType:)`](/documentation/AppKit/NSDocumentController/makeUntitledDocument(ofType:)) to create it, then calls [`addDocument(_:)`](/documentation/AppKit/NSDocumentController/addDocument(_:)) to record its opening.

When `displayDocument` is <doc://com.apple.documentation/documentation/Swift/true>, this method sends the new document [`makeWindowControllers()`](/documentation/AppKit/NSDocument/makeWindowControllers()) and [`showWindows()`](/documentation/AppKit/NSDocument/showWindows()) messages. In this scenario, [`showWindows()`](/documentation/AppKit/NSDocument/showWindows()) shows only the window controllers that have been assigned to the document.

> Handling Errors in Swift:
> In Swift, this method returns a nonoptional result and is marked with the `throws` keyword to indicate that it throws an error in cases of failure.
> 
> You call this method in a `try` expression and handle any errors in the `catch` clauses of a `do` statement, as described in [Error Handling](https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html) in [The Swift Programming Language](https://docs.swift.org/swift-book/) and `About Imported Cocoa Error Parameters`.

---

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)