Contents

qrCodeGenerator()

Generates a quick response (QR) code image.

Declaration

class func qrCodeGenerator() -> any CIFilter & CIQRCodeGenerator

Return Value

The generated image.

Discussion

This method generates a QR code as an image. QR codes are a high-density matrix barcode format defined in the ISO/IEC 18004:2006 standard.

The QR code generator filter uses the following properties:

message

A string representing the data to be encoded as a QR Code as NSData.

correctionLevel

A single letter string representing the error-correction format as an NSString. L is 7 percent correction, M is 15 percent correction, Q is 25 percent correction, and H is 30 percent correction.

The following code creates a filter that generates a QR code:

func qrCode(inputMessage: String) -> CIImage {
    let qrCodeGenerator = CIFilter.qrCodeGenerator()
    qrCodeGenerator.message = inputMessage.data(using: .ascii)!
    qrCodeGenerator.correctionLevel = "H"
    return qrCodeGenerator.outputImage!
}

[Image]

See Also

Filters