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

# makeUntitledDocument(ofType:)

Instantiates a new untitled document of the specified type and returns it if successful.

```
func makeUntitledDocument(ofType typeName: String) throws -> NSDocument
```

## Parameters

`typeName`

The type of the document.

## Discussion

The document type is specified by `typeName`. If not successful, the method returns `nil` after setting `outError` to point to an `NSError` object that encapsulates the reason why a new untitled document could not be instantiated. The default implementation of this method calls [`documentClass(forType:)`](/documentation/AppKit/NSDocumentController/documentClass(forType:)) to find out the class of document to instantiate, then allocates and initializes a document by sending it [`init(type:)`](/documentation/AppKit/NSDocument/init(type:)).

> 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)