ScanCodes is a Swift library with scan code-related features for SwiftUI, like a ScanCode and CodeScannerView that can scan QR and barcodes directly into your app.
ScanCodes can be installed with the Swift Package Manager:
https://github.com/danielsaidi/ScanCodes.git
ScanCodes supports iOS 15, iPadOS 15, macOS 12, tvOS 15, and visionOS 1.
To render a scan code in SwiftUI, just add a ScanCode with the value and type to render:
struct ContentView: View {
var body: some View {
ScanCode(
value: "123456789",
type: .qr,
scale: 5,
rotation: .pi/4
)
}
}To add a QR and barcode scanner to your app, that looks for codes to scan, just use the CodeScanner view:
struct ContentView: View {
@State var code: String?
var body: some View {
CodeScannerView(
code: $code,
viewfinder: {
CodeScannerViewfinder()
}
)
}
}The code scanner and its viewfinder can be customized to great extent. See the documentation for more details.
The online documentation has more information, articles, code examples, etc.
The Demo folder has a demo app that lets you explore the library.
You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.
Feel free to reach out if you have questions, or want to contribute in any way:
- Website: danielsaidi.com
- E-mail: daniel.saidi@gmail.com
- Bluesky: @danielsaidi@bsky.social
- Mastodon: @danielsaidi@mastodon.social
ScanCodes is available under the MIT license. See the LICENSE file for more info.
