---
title: "replaceItem(at:options:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsfileversion/replaceitem(at:options:)"
---

# replaceItem(at:options:)

Replace the contents of the specified file with the contents of the current version’s file.

## Declaration

```swift
func replaceItem(at url: URL, options: NSFileVersion.ReplacingOptions = []) throws -> URL
```

## Parameters

- `url`: The file whose contents you want to replace. If the file at this URL does not exist, a new file is created at the location.
- `options`: Specify 0 to overwrite the file in place; otherwise, specify one of the constants described in doc://com.apple.foundation/documentation/Foundation/NSFileVersion/ReplacingOptions.

## Return Value

Return Value The URL of the file that was written, which may be different than the one specified in the url parameter.

## Discussion

Discussion When replacing the contents of the file, this method does not normally replace the display name associated with the file. The only exception is when the file at url is of a different type than the file associated with this version object. In such a case, the file name remains the same but its filename extension changes to match the type of the new contents. (Of course, if filename extension hiding is enabled, this change is not noticeable to users.) 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

### Replacing and Deleting Versions

- [remove()](foundation/nsfileversion/remove().md)
- [removeOtherVersionsOfItem(at:)](foundation/nsfileversion/removeotherversionsofitem(at:).md)
