<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSFileVersion",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileVersion"
  },
  "title" : "NSFileVersion"
}
-->

# NSFileVersion

A snapshot of a file at a specific point in time.

```
class NSFileVersion
```

## Overview

Use the methods of this class to access, create, and manage file revisions in your app.

Each file version instance contains metadata about a single revision, including the location of the associated file, the modification date of the revision, and whether the revision is discardable.

In Mac apps, you can use file version objects to track changes to a local file over time and to prevent the loss of data during editing. When managing local versions, the document architecture creates versions at specific points in the lifetime of your application. Your application can also create versions explicitly at times that your application designates as appropriate.

In addition to managing local files, the system also uses this class to manage cloud-based files. For files in the cloud, there is usually only one version of the file at any given time. However, additional file versions may be created in cases where two different computers attempt to save the file to the cloud at the same time. In that case, one file is chosen as the current version and any other versions are tagged as being in conflict with the original. Conflict versions are reported to the appropriate file presenter objects and should be resolved as soon as possible so that the corresponding files can be removed from the cloud.

## Topics

### Getting the Version of a File

[`class func currentVersionOfItem(at: URL) -> NSFileVersion?`](/documentation/Foundation/NSFileVersion/currentVersionOfItem(at:))

Returns the most recent version object for the file at the specified URL.

[`class func otherVersionsOfItem(at: URL) -> [NSFileVersion]?`](/documentation/Foundation/NSFileVersion/otherVersionsOfItem(at:))

Returns all versions of the specified file except the current version.

[`class func version(itemAt: URL, forPersistentIdentifier: Any) -> NSFileVersion?`](/documentation/Foundation/NSFileVersion/version(itemAt:forPersistentIdentifier:))

Returns the version of the file that has the specified persistent ID.

[`class func temporaryDirectoryURLForNewVersionOfItem(at: URL) -> URL`](/documentation/Foundation/NSFileVersion/temporaryDirectoryURLForNewVersionOfItem(at:))

Creates and returns a temporary directory to use for saving the contents of the file.

### Creating a New Version

[`class func addOfItem(at: URL, withContentsOf: URL, options: NSFileVersion.AddingOptions) throws -> NSFileVersion`](/documentation/Foundation/NSFileVersion/addOfItem(at:withContentsOf:options:))

Creates a version of the file at the specified location.

### Accessing the Version Information

[`var url: URL`](/documentation/Foundation/NSFileVersion/url)

The URL identifying the location of the file associated with the file version object.

[`var localizedName: String?`](/documentation/Foundation/NSFileVersion/localizedName)

The string containing the user-presentable name of the file version.

[`var localizedNameOfSavingComputer: String?`](/documentation/Foundation/NSFileVersion/localizedNameOfSavingComputer)

The user-presentable name of the computer on which the revision was saved.

[`var modificationDate: Date?`](/documentation/Foundation/NSFileVersion/modificationDate)

The modification date of the version.

[`var persistentIdentifier: any NSCoding`](/documentation/Foundation/NSFileVersion/persistentIdentifier)

The identifier for this version of the file.

[`var isDiscardable: Bool`](/documentation/Foundation/NSFileVersion/isDiscardable)

A Boolean value that specifies whether the system can delete the associated file at some future time.

### Handling Version Conflicts

[`var isConflict: Bool`](/documentation/Foundation/NSFileVersion/isConflict)

A Boolean value indicating whether the contents of the version are in conflict with the contents of another version.

[`var isResolved: Bool`](/documentation/Foundation/NSFileVersion/isResolved)

A Boolean value that indicates if the version object is in conflict or not.

[`class func unresolvedConflictVersionsOfItem(at: URL) -> [NSFileVersion]?`](/documentation/Foundation/NSFileVersion/unresolvedConflictVersionsOfItem(at:))

Returns an array of version objects that are currently in conflict for the specified URL.

### Replacing and Deleting Versions

[`func replaceItem(at: URL, options: NSFileVersion.ReplacingOptions) throws -> URL`](/documentation/Foundation/NSFileVersion/replaceItem(at:options:))

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

[`func remove() throws`](/documentation/Foundation/NSFileVersion/remove())

Remove this version object and its associated file from the version store.

[`class func removeOtherVersionsOfItem(at: URL) throws`](/documentation/Foundation/NSFileVersion/removeOtherVersionsOfItem(at:))

Removes all versions of a file, except the current one, from the version store.

### Constants

[`struct AddingOptions`](/documentation/Foundation/NSFileVersion/AddingOptions)

Options for adding a new file version.

[`struct ReplacingOptions`](/documentation/Foundation/NSFileVersion/ReplacingOptions)

Options for replacing a file version.

### Initializers

[`init?(ofItemAtURL: URL, forPersistentIdentifier: Any)`](/documentation/Foundation/NSFileVersion/init(ofItemAtURL:forPersistentIdentifier:))

### Instance Properties

[`var hasLocalContents: Bool`](/documentation/Foundation/NSFileVersion/hasLocalContents)

Whether the version has local contents. Versions that are returned by +getNonlocalVersionsOfItemAtURL:completionHandler: do not initially have local contents. You can only access their contents, either directly via the URL or by invoking -replaceItemAtURL:options:error:, from within a coordinated read on the NSFileVersion’s URL.

[`var hasThumbnail: Bool`](/documentation/Foundation/NSFileVersion/hasThumbnail)

Whether the version has a thumbnail image available. Thumbnails for versions from +getNonlocalVersionsOfItemAtURL:completionHandler: may not immediately be available. As soon as it becomes available, this property will change from NO to YES. You can use KVO to be notified of this change. If a thumbnail is available, you can access it using NSURLThumbnailKey or NSURLThumbnailDictionaryKey.

[`var originatorNameComponents: PersonNameComponents?`](/documentation/Foundation/NSFileVersion/originatorNameComponents)

The name components of the user who created this version of the file. Is nil if the file is not shared or if the current user is the originator.

### Type Methods

[`class func getNonlocalVersionsOfItem(at: URL, completionHandler: ([NSFileVersion]?, (any Error)?) -> Void)`](/documentation/Foundation/NSFileVersion/getNonlocalVersionsOfItem(at:completionHandler:))

Asynchronously returns an array of NSFileVersions associated with the file located by the given URL, or nil if there is no such file or another error occurs.

## Relationships

### Conforms To

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`Equatable`](/documentation/Swift/Equatable)

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)