swiftxcodeswiftuiios-sharesheet

SwiftUI | How to use share sheet to copy localized strings?


I added share sheet button and it works great for my English texts (copying ,sharing) BUT for the localized texts the app hung and crash when I add LocalizedStringKeys() , and when I don't add it the text is showing English.

 func shareSheet(){
    isShareSheetShowing.toggle()
    let av = UIActivityViewController(activityItems: [LocalizedStringKey(quote)], applicationActivities: nil)
    UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)

}

Solution

  • You can use directly NSLocalizedString

    func shareSheet(){
       isShareSheetShowing.toggle()
       let av = UIActivityViewController(activityItems: [NSLocalizedString(quote, comment: "")], applicationActivities: nil) //<--Here
       UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
    }