0

Hey guys so I have posts which are generated from a JSON codable protocol into a SwiftUI view. In the SwiftUI view there is an share option. I've made it using the following code

    Button(action: shareButton){
                        Image(systemName: "square.and.arrow.up")
                            .font(.system(size: 22))
                            .foregroundColor(Color.gray)
                            .padding(.top, 15)
                            .padding(.bottom, 20)
                            .padding(.horizontal, 15)
                    }
                }

It is also linked to a function that does the following.

func shareButton()
    {
        isShareSheetShowing.toggle()
        let url = URL(string: "http://cdn.example.com/item/[id].html")
        let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)
        
        
        UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion:nil)
    }
}

The question I am asking you is as follows. Currently, when you click on share it just shares the link above e.g cdn.something. What I hope to achieve is to share the actual post which is being clicked on not the endpoint. I tried adding (post.id) into the URL but it doesent recognize it ( it doesent go green it just stays orange and considers it a part of the URL )

Help would be greatly appreciated. Thank you guys!

saxonsxexe
  • 97
  • 5
  • Are you trying to share the info of the post, or the URL to the specific post? If the URL, you are building it wrong. – Yrb May 17 '21 at 00:32
  • try to see this how to build a url with params https://stackoverflow.com/a/34061083/4668162 – Onix May 17 '21 at 10:00

0 Answers0