How to import Zbar Framework into Swift Project

I have a project and am currently trying to convert to a Swift project, but I couldn't figure out how to imagine a Zbar barcode reader that scans from the camera feed. In my current project, I named this

- (IBAction)scanButton:(id)sender {

    // ADD: present a barcode reader that scans from the camera feed
    ZBarReaderViewController *reader = [ZBarReaderViewController new];
    reader.readerDelegate = self;
    reader.supportedOrientationsMask = ZBarOrientationMaskAll;

    ZBarImageScanner *scanner = reader.scanner;
    // TODO: (optional) additional reader configuration here

    // EXAMPLE: disable rarely used I2/5 to improve performance
    [scanner setSymbology: ZBAR_I25
                   config: ZBAR_CFG_ENABLE
                       to: 0];

    // present and release the controller
    [self presentViewController:reader animated:YES completion:nil];}


Note: What I have done so far

  • Copy structure to swift
  • Added path to the path to the headers search path (section "Objectives"> "Build Settings")

    • $ (project_dir) / Test / ZBarSDK / Headers / ZBarSDK
    • Created by Projectname-Bridging-Header.h for Bridging (added all h files from zbar)
    • Added Projectname-Bridging-Header.h to the header search path

After that either if I write "import ZBarSDK" or ZBarReaderDelegate it still gives me an error!


source to share

3 answers

Here is the solution

the following link helped me / ...

But after that I had NSEnumeration problem, so here's the second solution to the problem

func imagePickerController(picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [NSObject : AnyObject]){
var results: NSFastEnumeration = info[ZBarReaderControllerResults] as NSFastEnumeration


Don't forget to expand

extension ZBarSymbolSet: SequenceType { public func generate() -> NSFastGenerator { return NSFastGenerator(self) } 




for Swift 3:

extension ZBarSymbolSet: Sequence {
    public func makeIterator() -> NSFastEnumerationIterator {
        return NSFastEnumerationIterator(self)

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        // ADD: get the decode results
        let results: NSFastEnumeration = info[ZBarReaderControllerResults] as! NSFastEnumeration

        var symbolFound : ZBarSymbol?

        for symbol in results as! ZBarSymbolSet {
            symbolFound = symbol as? ZBarSymbol
        let resultString = symbolFound!.data




I have a project

Using cocoapods to import ZBarSDK project into Swift 2.0.



All Articles