Skip to main content
ZipZapKit hasn’t been released yet. The API names on this page are provisional and may change.
In about five minutes you’ll have a text field that fills itself in when you scan a barcode with the iPhone’s camera.

Requirements

  • Xcode 16 or later
  • An app that targets iOS 17 or later
  • An iPhone to run it on. The Simulator has no camera.

Add a scan field

1

Add the package

In Xcode, choose File → Add Package Dependencies…, paste the package URL, and add ZipZapKit to your app target.
If you manage dependencies in Package.swift, add it there instead:
2

Say why you need the camera

iOS won’t open the camera unless your app explains why. In your target’s Info tab, add Privacy - Camera Usage Description (NSCameraUsageDescription) with a sentence your users will see, such as “Scan barcodes to look up products.”Without it, the app crashes the first time the camera opens.
3

Add a ScanField

Use ScanField anywhere you’d use a TextField:
That’s all the code. The field shows a camera button, opens the camera when it’s tapped, and writes what it scans into code.
4

Run it on your iPhone

Build and run on a device, tap the camera button in the field, and allow camera access when iOS asks.

Check it works

Point the camera at this barcode: The field should fill in with 9521234567899, and “Scanned: 9521234567899” should appear below it. If nothing happens:
  • The camera button is missing. You’re running in the Simulator. Run on a device, or type a number and press Return to test the rest of your screen.
  • The app crashes when the camera opens. The camera usage description is missing from the target that’s running.
  • The camera opens but doesn’t scan. Move back until the whole barcode is in view, and raise your screen brightness.

Make it specific

A field that accepts any barcode will also accept the wrong one. Tell it what you expect:
Now the field reads only the barcodes found on retail products and ignores everything else. See Barcode types for the other groups.

Next steps

Replace a TextField

Swap ScanField into a form you already have.

Validation

Reject scans that don’t match what you expect.

Scan sources

How a field gets its scans.

GS1 parsing

Pull the GTIN, expiry date and batch out of one barcode.