Attachment
Attachment is the UI component used for displaying a single attachment within an AttachmentGroup.
It presents attachment details including a thumbnail or preview image, title, subtitle, and footnote.
The component handles various states of attachments:
- Display of uploaded attachments with thumbnail previews
- Support for custom content through the default content view builder
- Interaction events for preview and deletion
Usage
Use the Attachment component to display a file or image attachment with its metadata:
// Display an attachment with a thumbnail generated from a file URL
Attachment(attachmentInfo: myAttachmentInfo) {
AttachmentThumbnail(url: myAttachmentInfo.primaryURL)
} attachmentTitle: {
Text(myAttachmentInfo.attachmentName)
} attachmentSubtitle: {
Text("15MB")
} attachmentFootnote: {
Text("Oct 20, 2025")
}
// Display an attachment with a custom image
Attachment(attachmentInfo: myAttachmentInfo) {
Image(systemName: "doc.text")
.resizable()
.aspectRatio(contentMode: .fit)
} attachmentTitle: {
Text(myAttachmentInfo.attachmentName)
} attachmentSubtitle: {
Text("PDF Document")
} attachmentFootnote: {
Text("Recently modified")
}
Use with AttachmentGroup to manage collections of attachments:
AttachmentGroup(attachments: $myAttachments) {
// Custom attachment rendering
ForEach(myAttachments, id: \.id) { attachment in
Attachment(attachmentInfo: attachment) {
AttachmentThumbnail(url: attachment.primaryURL)
} attachmentTitle: {
Text(attachment.attachmentName)
}
}
}
-
init(attachmentTitle:attachmentSubtitle: attachmentFootnote: attachmentInfo: controlState: onExtraInfoChange: onPreview: onDelete: componentIdentifier: ) Undocumented
Declaration
Swift
public init(@ViewBuilder attachmentTitle: () -> any View, @ViewBuilder attachmentSubtitle: () -> any View, @ViewBuilder attachmentFootnote: () -> any View, attachmentInfo: AttachmentInfo, controlState: ControlState = .normal, onExtraInfoChange: ((AnyHashable) -> Void)? = nil, onPreview: ((AttachmentInfo) -> Void)? = nil, onDelete: ((AttachmentInfo) -> Void)? = nil, componentIdentifier: String? = Attachment.identifier) -
Undocumented
Declaration
Swift
static let identifier: String -
init(attachmentTitle:attachmentSubtitle: attachmentFootnote: attachmentInfo: controlState: onExtraInfoChange: onPreview: onDelete: ) Undocumented
Declaration
Swift
init(attachmentTitle: AttributedString, attachmentSubtitle: AttributedString, attachmentFootnote: AttributedString, attachmentInfo: AttachmentInfo, controlState: ControlState = .normal, onExtraInfoChange: ((AnyHashable) -> Void)? = nil, onPreview: ((AttachmentInfo) -> Void)? = nil, onDelete: ((AttachmentInfo) -> Void)? = nil) -
Undocumented
Declaration
Swift
init(_ configuration: AttachmentConfiguration) -
Declaration
Swift
@MainActor public var body: some View { get } -
Undocumented
Declaration
Swift
public var isEmpty: Bool { get }