Introduction
In SwiftUI, you can now use the new ShareLink
1 view to share links and images using Apple’s ‘sharesheet’ option in only a few lines of swift code.
This features pairs well with SharePreview
2 that allows the user to view the image preview while the share-sheet is in action.
Code Snippet
import SwiftUI
struct ContentView: View {
@State var image = Image("Image")
var body: some View {
VStack {
Spacer()
image.resizable().aspectRatio(contentMode: .fit)
Spacer()
ShareLink(
item: image,
preview: SharePreview(
"Share Preview",
image: image
)
)
Spacer()
}
}
}