In SwiftUI, a “share sheet” refers to a system-provided popup that allows users to share content from your app with other apps or services. This content can be various types of data, including:
Text
URLs
Images
Files
Custom data types that implement the Transferable protocol
SwiftUI offers several ways to create a share sheet, depending on your iOS version and the complexity of your needs:
ShareLink (iOS 16)
Introduced in iOS 16, ShareLink is the easiest and most declarative way to share content.
It requires the data you want to share to conform to the Transferable protocol.
You can optionally add a message and preview image.
let link = URL(string: "https://www.gurjit.co")! ShareLink(item: link, message: Text("Check out this website!")) { Image(systemName: "link.circle") .padding() Text("Share this website") }
ActivityView (iOS 13+)
More flexible but requires more code compared to ShareLink.
I’m Computer Science graduate and an iOS Engineer who writes about Swift and iOS development. Follow me on twitter @gurjitpt and for more articles www.gurjit.co