Help with a share button swiftUI

I'm trying to creat a share button in my app. I have a list and I want to swipe left any item and appear a button to share the content of the item (exactly like .onDelete but to do other action, share).

When I creat this swipeActions, an error appears saying "Result of 'ShareLink<Data ,PreviewImage, PrevieIcon, Label>' Initializer is unused.

Here is a print of the App with this code. The button/swipeactions appears there button nothing happens.

How can I use the result of this initializer.

I'm obviosly new to Swift and I will appreciate any help. I already tryied everething that I found online.

import SwiftUI
import FirebaseFirestore
import FirebaseFirestoreSwift

struct ContentView: View {
    
    @State private var showingEditPlaceView = false
    @EnvironmentObject var placeVM: PlaceViewModel
    
    @FirestoreQuery(collectionPath: "places", predicates: [.order(by: "name")]) var places: [Place]
    
    @State var search = ""
    @ObservedObject var data = getData()
    
    var body: some View {
        NavigationView {
            List{
                ForEach(places.filter{(self.search.isEmpty ? true :
                                 $0.name.localizedCaseInsensitiveContains(self.search))}, id: \.id) { place in
                 VStack(alignment: .leading) {
                      Link(place.name, destination: URL(string: place.link )!)
                          .font(.headline)
                    }

                    .swipeActions(edge: .leading){
                        Button{
                            ShareLink(item: place.link)
                        }
                    }

                    //ShareLink(item: place.link)
                }
Answered by Balmazo in 740050022

I think ShareLink dont work with swipeActions but I got a solution to this problem, here it is:

.swipeActions(){
Button(action: {
let url = URL(string: "your url here")
let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)

UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}) {
Label("", systemImage: "square.and.arrow.up")
}

Thaks for the help!

Remove the Button so only the ShareLink is in the swipeActions closure.

The swipeActions closure expects a View and the way it is now it’s getting the Button, not the ShareLink. Also the reason you’re getting that warning is because for a Button it’s closure is regular code. So a ShareLink is being instantiated there but that instance isn’t assigned or passed to anything. Hence, the result of ShareLink initializer (which is a ShareLink instance) isn’t being used. 

I already did it. But keeps not working.

The error disapear and the button still there (exactly like the pint) but when I click it, nothing happens... The card just come back to the left and only, nothing more.

Accepted Answer

I think ShareLink dont work with swipeActions but I got a solution to this problem, here it is:

.swipeActions(){
Button(action: {
let url = URL(string: "your url here")
let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)

UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}) {
Label("", systemImage: "square.and.arrow.up")
}

Thaks for the help!

Help with a share button swiftUI
 
 
Q