I'm trying to present an instance of UIImage, generated as a barcode from a string:
if let image = UIImage(barcode: "1234567890") {
Image(uiImage: image)
}
But it shows empty rectangle, though in debug the image
is populated with the real image:
I use a simple UIImage extension to generate an UIImage with barcode from a string:
extension UIImage {
convenience init?(barcode: String) {
let data = barcode.data(using: .ascii)
guard let filter = CIFilter(name: "CICode128BarcodeGenerator") else {
return nil
}
filter.setValue(data, forKey: "inputMessage")
guard let ciImage = filter.outputImage else {
return nil
}
self.init(ciImage: ciImage)
}
}
What's wrong? Any ideas?