iOS 16 ShareLink — native share sheet in SwiftUI
Credit: Unknown

iOS 16 ShareLink — native share sheet in SwiftUI

By Atikur Rehman, Senior iOS Developer at Evangelist Apps Limited.

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.

No alt text provided for this image

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.

No alt text provided for this image

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

No alt text provided for this image

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

No alt text provided for this image

Which will render the following share button.

No alt text provided for this image

Please share your thoughts and suggestions on this article.

Keep up with us on social media:

Medium: https://medium.com/evangelist-apps

Twitter: https://twitter.com/EvangelistSW/

#swiftui #ios #iosdeveloper #xcode #iosappdevelopment #swift #iosappdevelopment #iosdevelopers #iosdevelopment #ios16

To view or add a comment, sign in

Insights from the community

Others also viewed

Explore topics