iOS 16 ShareLink — native share sheet in SwiftUI

In earlier versions of SwiftUI, there was no native support to show share sheets. We had to wrap UIActivityController to UIViewRepresentable in order to show a share sheet. But in iOS 16, SwiftUI comes with a new view called ShareLink, which allows us to create a native share sheet with ease.

Using ShareLink, you can share any kind of data from your app. Let’s take a look at few examples.

First, we will see how to share text.

As you can see, you simply pass a string to the item parameter. This will render a Share button with a small icon. When you tap the Share button, a share sheet will popup.

To share an URL, we can pass the url to the item parameter.

You can easily customize the appearance of the Share button. You simply need to provide a view content in the closure as follows -

Which will render the following share button.

pic credit: Unknown

Please share your thoughts and suggestions on this article.

Keep up with us on social media:





Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store