How to generate QR Code in SwiftUI?

DevTechie
DevTechie
Published in
3 min readSep 22, 2022

--

CoreImage is a feature rich framework with many high efficiency capabilities hidden inside. One such feature is the ability to generate QR code on demand with the help of CIQRCodeGenerator Core Image Filter.

In this article, we will use CIQRCodeGenerator to generate QR code in SwiftUI.

Let’s create a view first. We will have a VStack with a TextField and an Image View. TextField will take the user’s input and Image View will display the generated QR Code.

import SwiftUIstruct QRGenerator: View {

@State private var text = ""

var body: some View {
NavigationStack {
VStack {
TextField("Enter code", text: $text)
.textFieldStyle(.roundedBorder)
.padding()

Image("")
.resizable()
.frame(width: 200, height: 200)
}
.navigationTitle("DevTechie.com")
}
}
}

Next we will import the CoreImage framework.

import CoreImage

Let’s also import CoreImage’s type-safe API to access all the CoreImage filters.

import CoreImage.CIFilterBuiltins

--

--