Hello
I created a QR (view) code generator with a "favourites" button and I want to be able to save the String that the user inputs in the favourites view. How can I do it? (And I'm not good at Core Data, so i don't know how to save it)
Thank you
I created a QR (view) code generator with a "favourites" button and I want to be able to save the String that the user inputs in the favourites view. How can I do it? (And I'm not good at Core Data, so i don't know how to save it)
Code Block import SwiftUI import CoreImage.CIFilterBuiltins struct QRView: View { let context = CIContext() var filter = CIFilter.qrCodeGenerator() @State var url: String = "" @Binding var isPresentedQR: Bool var body: some View { NavigationView{ Form{ Section(header: Text("Enter your Input value")){ TextField("Input",text: $url) .autocapitalization(.none) } Section(header: Text("QR Code")){ Image(uiImage: generatedQRCodeImage(url: url)) .resizable() .interpolation(.none) .frame(width: 250, height: 250, alignment: .center) } Section{ HStack{ Button(action: { //What to put here }) { HStack{ Text("Add to Favorites") Spacer() Image(systemName: "bookmark") .frame(width: 25, height: 25) .clipShape(Circle()) } } } } } .navigationTitle("QR") .navigationBarItems(trailing: Button(action: { isPresentedQR = false }) { Text("Back") } ) } } func generatedQRCodeImage(url: String) -> UIImage { let data = Data(url.utf8) filter.setValue(data, forKey: "inputMessage") if let qrCodeImage = filter.outputImage{ if let qrCodeCGImage = context.createCGImage(qrCodeImage, from: qrCodeImage.extent){ return UIImage(cgImage: qrCodeCGImage) } } return UIImage(systemName: "xmark") ?? UIImage() } }
Code Block struct Favorites: View { var body: some View { ScrollView(.vertical, showsIndicators: false) { VStack(alignment: .center, spacing: 20) { } .navigationBarTitle("Favorites") } } }
Thank you