---
title: "openUntitledDocumentAndDisplay(_:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocumentcontroller/openuntitleddocumentanddisplay(_:)"
---

# openUntitledDocumentAndDisplay(_:)

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

## Declaration

```swift
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

Return Value Returns the new 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

Discussion The default implementation of this method calls defaultType to determine the type of new document to create, calls makeUntitledDocument(ofType:) to create it, then calls addDocument(_:) to record its opening. When displayDocument is true, this method sends the new document makeWindowControllers() and showWindows() messages. In this scenario, showWindows() shows only the window controllers that have been assigned to the document. note: 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 in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Creating and Opening Documents

- [document(for:)](appkit/nsdocumentcontroller/document(for:)-i5zi.md)
- [duplicateDocument(withContentsOf:copying:displayName:)](appkit/nsdocumentcontroller/duplicatedocument(withcontentsof:copying:displayname:).md)
- [openDocument(withContentsOf:display:completionHandler:)](appkit/nsdocumentcontroller/opendocument(withcontentsof:display:completionhandler:).md)
- [makeDocument(for:withContentsOf:ofType:)](appkit/nsdocumentcontroller/makedocument(for:withcontentsof:oftype:).md)
- [makeDocument(withContentsOf:ofType:)](appkit/nsdocumentcontroller/makedocument(withcontentsof:oftype:).md)
- [makeUntitledDocument(ofType:)](appkit/nsdocumentcontroller/makeuntitleddocument(oftype:).md)
- [reopenDocument(for:withContentsOf:display:completionHandler:)](appkit/nsdocumentcontroller/reopendocument(for:withcontentsof:display:completionhandler:).md)
