<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIFilter-swift.class/code128BarcodeGenerator()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIFilter(cm)code128BarcodeGeneratorFilter"
  },
  "title" : "code128BarcodeGenerator()"
}
-->

# code128BarcodeGenerator()

Generates a high-density, linear barcode.

```
class func code128BarcodeGenerator() -> any CIFilter & CICode128BarcodeGenerator
```

## Return Value

The generated image.

## Discussion

This method generates a Code 128 barcode as an image. Code 128 is a high-density linear barcode defined in the ISO/IEC 15417:2007 standard. Use this filter to generate alphanumeric or numeric-only barcodes. The barcode can contain any of the 128 ASCII characters.

The Code 128 barcode filter uses the following properties:

- `message`: <doc://com.apple.documentation/documentation/Foundation/NSData> containing the message to encode in the Code 128 barcode.
- `quietSpace`: <doc://com.apple.documentation/documentation/Foundation/NSNumber> containing the number of empty white pixels that should surround the barcode.
- `barcodeHeight`: <doc://com.apple.documentation/documentation/Foundation/NSNumber> containing the height of the generated barcode in pixels.

The following code creates a filter that generates a Code 128 barcode:

```swift
func code128Barcode(barcode: String) -> CIImage {
    let code128Barcode = CIFilter.code128BarcodeGenerator()
    code128Barcode.message = barcode.data(using: .ascii)!
    code128Barcode.quietSpace = 5
    code128Barcode.barcodeHeight = 20
    return code128Barcode.outputImage!
}
```

![An image of a black and white barcode made of vertical lines of various widths representing the encoded data of: hello!](images/com.apple.coreimage/media-3546314@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)