One Logo Pool Ball
AppIntents · IOS API REFERENCE

IntentFile

struct · iOS 16.0+ · SDK 27.1

struct IntentFile

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.

Members (14)

method · iOS 18.0+

withFile

TypeScript
withFile(contentType: _UniformTypeIdentifiers_UTType, allowOpenInPlace: boolean, fileHandler: ((arg0: string, arg1: boolean) => Promise<unknown>)): Promise<unknown>
Swift declaration
func withFile<Result>(contentType: UTType, allowOpenInPlace: Bool = false, fileHandler: @escaping (URL, Bool) async throws -> Result) async throws -> Result

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.

method · iOS 18.0+

data

TypeScript
dataContentType(contentType: _UniformTypeIdentifiers_UTType): Promise<ArrayBuffer>
Swift declaration
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.

init · iOS 16.0+

init

TypeScript
static initDataFilenameType(data: ArrayBuffer, filename: string, type?: (_UniformTypeIdentifiers_UTType) | null): IntentFile
Swift declaration
init(data: Data, filename: String, type: UTType? = nil)
method · iOS 18.0+

file

TypeScript
file(contentType: _UniformTypeIdentifiers_UTType, destinationDirectory?: (string) | null): Promise<{ "fileURL": string; "openedInPlace": boolean }>
Swift declaration
func file(contentType: UTType, destinationDirectory: URL? = nil) async throws -> (fileURL: URL, openedInPlace: Bool)

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()`.

init · iOS 16.0+

init

TypeScript
static initFileURLFilenameType(fileURL: string, filename?: (string) | null, type?: (_UniformTypeIdentifiers_UTType) | null): IntentFile
Swift declaration
init(fileURL: URL, filename: String? = nil, type: UTType? = nil)
get · iOS 16.0+

filename

TypeScript
get filename(): string
Swift declaration
var filename: String { get }

The human-readable name of the file, which will be displayed to the user.

Skipped declarations

1 declarations were excluded from these bindings. Each reason comes from the generator or the iOS SDK compiler.

IntentFile.defaultResolverSpecification

This protocol needs associated types that cannot yet cross the bridge.

All AppIntents types →