ShareLink API

Each platform has a standard interface for allowing people to share content from your apps.

With watchOS 9, you can now also present the share sheet from within your watch apps.

  • The new ShareLink view enables presenting that system share sheet from within your app.

  • You can simply provide it with the content to be shared and a preview to use in the share sheet, and it automatically creates a standard share icon button.

  • On tap, it presents the standard share sheet to send off the content.

in WinesTab

import Charts

import SwiftUI

struct Wines: Identifiable {

var name: String

var sales: Int

var id: String { name }

}

let sales: [Wines] = [

.init(name: "Margaux", sales: 500),

.init(name: "Médoc", sales: 460),

.init(name: "Blaye", sales: 300),

.init(name: "St Estèphe", sales: 290),

.init(name: "Sauternes", sales: 250),

.init(name: "Pessac-Léognan", sales: 20)

]

struct WinesTab: View {

@Environment(\.openWindow) var openWindow

var body: some View {

ZStack {

Chart(sales) { element in

BarMark (

x: .value("Sales", element.sales),

y: .value("Name", element.name)

)

}

}

.padding(20)

.toolbar {

Button {

openWindow(id: "Sales")

} label: {

Image(systemName: "dollarsign")

}

}

.toolbar {

ShareLink(item: URL(string: "https://frenchkit.fr/")!) {

Label("Share", image: "icon-fk")

}.padding()

}

}

}

struct WinesTab_Previews: PreviewProvider {

static var previews: some View {

WinesTab()

}

}

Last updated