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.
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.
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