Sharing Made Easy: A Guide to SwiftUI Share Sheets
2 min readFeb 7, 2024
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.
- Uses the
UIActivityViewController
under the hood. - Allows customization of…