im trying to generate a QR code in my app. The problem is that whenever I do the picture is just an empty square. I stripped down the code to the basics to try and show my problem.
struct ContentView: View {
@State var image: Image = Image(systemName: "circle.fill")
var body: some View {
VStack {
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 200, height: 200)
.background(Color.green)
}.onAppear {
let myString = "Hello There"
let data = myString.data(using: String.Encoding.ascii)
guard let qrFilter = CIFilter(name: "CIQRCodeGenerator") else { return }
qrFilter.setValue(data, forKey: "inputMessage")
guard let qrImage = qrFilter.outputImage else { return }
let transform = CGAffineTransform(scaleX: 10, y: 10)
let scaledQrImage = qrImage.transformed(by: transform)
self.image = Image(uiImage: UIImage(ciImage: scaledQrImage))
}
}
}