---
title: "typeForContents(of:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsdocumentcontroller/typeforcontents(of:)"
---

# typeForContents(of:)

Returns, for a specified URL, the document type identifier to use when opening the document at that location, if successful.

## Declaration

```swift
func typeForContents(of url: URL) throws -> String
```

## Parameters

- `url`: The URL to use for locating the type identifier.

## Discussion

Discussion The URL is represented by url. If not successful, the method returns nil after setting outError to point to an NSError object that encapsulates the reason why the document type could not be determined, or the fact that the document type is unrecognized. You can override this method to customize type determination for documents being opened. 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

### Managing Document Types

- [documentClassNames](appkit/nsdocumentcontroller/documentclassnames.md)
- [defaultType](appkit/nsdocumentcontroller/defaulttype.md)
- [documentClass(forType:)](appkit/nsdocumentcontroller/documentclass(fortype:).md)
- [displayName(forType:)](appkit/nsdocumentcontroller/displayname(fortype:).md)
