Unable to integrate ZXingObjC in a iOS Swift Project Unable to integrate ZXingObjC in a iOS Swift Project xcode xcode

Unable to integrate ZXingObjC in a iOS Swift Project


Actually it is an easy issue:

Podfile

source 'https://github.com/CocoaPods/Specs.git'platform :ios, '8.0'use_frameworks!pod 'ZXingObjC', '~> 3.1'

So, on terminal:

cd workspacepod install

Then, once opened project on Xcode, you have to edit bridging-header adding ZXingObj:

#import <ZXingObjC/ZXingObjC.h>

Finally, in your swift classes that uses ZXingObjC, you have to import ZXingObjC.

import ZXingObjCclass ZXingObjCWrapper {    func encode() {       let writer = ZXMultiFormatWriter.writer()               ....    }}


The rest of the code for when you need to set an UIImage with this bar code:

func generateDataMatrixQRCode(from string: String) -> UIImage? {    do {        let writer = ZXMultiFormatWriter()        let hints = ZXEncodeHints() as ZXEncodeHints        let result = try writer.encode(string, format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints)        if let imageRef = ZXImage.init(matrix: result) {            if let image = imageRef.cgimage {                return UIImage.init(cgImage: image)            }        }    }    catch {        print(error)    }    return nil}


The header search path was not correct in my project. The right values are:

$(inherited)"${PODS_ROOT}/Headers/Public""${PODS_ROOT}/Headers/Public/ZXingObjC"

The second and third lines were not added by installation with CocoaPods.

EDIT: The installed framework have to be added to "Embedded Binaries" in General tab of the project.