An interface for providing an app entity that represents an on-disk file or file-based resource.
Provide an intent file entity implementation to describe data you store in a file on disk or in memory by providing its
associated name and uniform type identifier.
Requests an `IntentFile` representation as a file url.
If the file is not opened in place, the system removes it after the fileHandler closure returns.
```swift
let image = try await intentFile.withFile(contentType: .png) { url, _ in
let data = try Data(contentsOf: url)
return CGImage(pngData: data)
}
```
- Parameters:
- contentType: A content type of the returned data.
- allowOpenInPlace: Whether the file should be opened in place, if possible.
- fileHandler: A closure that accepts the file URL as a parameter.
The file is written to a temporary destination and removed
right after the closure returns.
get · iOS 16.0+
removedOnCompletion
TypeScript
get removedOnCompletion(): boolean
Swift declaration
var removedOnCompletion: Bool { get set }
Indicates whether the file should be automatically deleted from disk when the Shortcut is
done running. `false` by default.
set · iOS 16.0+
removedOnCompletion
TypeScript
set removedOnCompletion(value: boolean)
Swift declaration
var removedOnCompletion: Bool { get set }
Indicates whether the file should be automatically deleted from disk when the Shortcut is
done running. `false` by default.
get · iOS 18.0+
availableContentTypes
TypeScript
get availableContentTypes(): Array<_UniformTypeIdentifiers_UTType>
Swift declaration
var availableContentTypes: [UTType] { get }
Valid content types the `IntentFile` can possibly be converted to.
Use these content types to request an `IntentFile` representation as either a file url or data.
get · iOS 16.0+
displayRepresentation
TypeScript
get displayRepresentation(): DisplayRepresentation
Swift declaration
var displayRepresentation: DisplayRepresentation { get }
The visual elements to display when presenting an instance of the type.
get · iOS 16.0+
typeDisplayRepresentation
TypeScript
static get typeDisplayRepresentation(): TypeDisplayRepresentation
Swift declaration
static var typeDisplayRepresentation: TypeDisplayRepresentation { get }
A short, localized, human-readable name for the type.
get · iOS 16.0+
data
TypeScript
get data(): ArrayBuffer
Swift declaration
var data: Data { get }
The contents of the file.
If the file was created with a URL, accessing this property will memory map the file contents.
func data(contentType: UTType) async throws -> Data
Requests an `IntentFile` representation as binary data of the requested content type if possible.
If the `IntentFile` is backed by a file `URL`, this might cause loading the
entire file contents into memory.
- Parameters:
- contentType: A content type of the returned data.
Requests an `IntentFile` representation as a file url.
If a destination directory is not given the file is opened in place, falling back to a temporary directory if this fails.
If the file is not opened in place and a destination directory is used
it is the caller's responsibility to remove the file.
- Parameters:
- contentType: A content type of the returned data.
- destinationDirectory: The directory the file should be copied to,
if no directory is provided the file is opened in place.
get · iOS 16.0+
type
TypeScript
get type(): (_UniformTypeIdentifiers_UTType) | null
Swift declaration
var type: UTType? { get }
The uniform type identifier of the file. (i.e. "public.json", "public.png", or any custom type)
More information about uniform type identifiers can be found in <CoreServices/UTCoreTypes.h>
get · iOS 16.0+
fileURL
TypeScript
get fileURL(): (string) | null
Swift declaration
var fileURL: URL? { get }
URL to the file on disk, if any.
If the file isn't stored on disk, access the contents using the `data` property.
If the file was created elsewhere on the system, make sure to surround access to file contents
with `startAccessingSecurityScopedResource()` and `stopAccessingSecurityScopedResource()`.