yeahdongcn / RSBarcodes_Swift

1D and 2D barcodes reader and generators for iOS 8 with delightful controls. Now Swift.
MIT License
708 stars 185 forks source link

Swift 4.0 #100

Open zeusent opened 7 years ago

zeusent commented 7 years ago

Is there a branch for Swift 4.0? Are there plans for such a branch soon?

VFUC commented 7 years ago

see #101

VFUC commented 7 years ago

There seem to be some Swift 4 updates on the master branch already - has this been handled already? If so, I'll close my merge request. If not, I'll update it and resolve the conflicts.

lotfyahmed commented 7 years ago

Please help me, I upgrade to Swift 4 and Xcode 9. But I couldn't run the code screen shot 2017-10-10 at 12 53 47 pm screen shot 2017-10-10 at 12 53 40 pm

How can we fix that?

malcommac commented 7 years ago

Have you tried using the master branch directly? Seems it was not released yet thought cocoapods:

pod 'RSBarcodes_Swift', :git => 'https://github.com/yeahdongcn/RSBarcodes_Swift', :branch => 'master'
kubajakowski commented 7 years ago

I've tried - it's crashing

skeletom commented 6 years ago

you can just change swift language version param from this pod build settings back to 3.2 and it will work just fine until the new release with swift 4 support is available

zeusent commented 6 years ago

Any news on this? I still see version 3.0.3 as being the latest. Can someone push a new Podspec file?

ravenshore commented 6 years ago

Just wanted to let you know, that there are only several items that need to be corrected for Swift 4, not a big deal. I am just going to paste some of the items here:

here the .rawValue needed to be added ( including a few other places ... )

 open func generateCode(_ contents: String, inputCorrectionLevel: InputCorrectionLevel, machineReadableCodeObjectType: String) -> UIImage? {
        var codeGenerator: RSCodeGenerator?
        switch machineReadableCodeObjectType {

        case AVMetadataObject.ObjectType.qr.rawValue, AVMetadataObject.ObjectType.pdf417.rawValue, AVMetadataObject.ObjectType.aztec.rawValue:
            return RSAbstractCodeGenerator.generateCode(contents, inputCorrectionLevel: inputCorrectionLevel, filterName: RSAbstractCodeGenerator.filterName(machineReadableCodeObjectType))
        case AVMetadataObject.ObjectType.code39.rawValue:
            codeGenerator = RSCode39Generator()
        case AVMetadataObject.ObjectType.code39Mod43.rawValue:
            codeGenerator = RSCode39Mod43Generator()
        case AVMetadataObject.ObjectType.ean8.rawValue:
            codeGenerator = RSEAN8Generator()
        case AVMetadataObject.ObjectType.ean13.rawValue:
            codeGenerator = RSEAN13Generator()
        case AVMetadataObject.ObjectType.interleaved2of5.rawValue:
            codeGenerator = RSITFGenerator()
        case AVMetadataObject.ObjectType.itf14.rawValue:
            codeGenerator = RSITF14Generator()
        case AVMetadataObject.ObjectType.upce.rawValue:
            codeGenerator = RSUPCEGenerator()
        case AVMetadataObject.ObjectType.code93.rawValue:
            codeGenerator = RSCode93Generator()
            // iOS 8 included, but my implementation's performance is better :)
        case AVMetadataObject.ObjectType.code128.rawValue:
            if self.isBuiltInCode128GeneratorSelected {
                return RSAbstractCodeGenerator.generateCode(contents, inputCorrectionLevel: inputCorrectionLevel, filterName: RSAbstractCodeGenerator.filterName(machineReadableCodeObjectType))
            } else {
                codeGenerator = RSCode128Generator()
            }
        case AVMetadataObject.ObjectType.dataMatrix.rawValue:
            codeGenerator = RSCodeDataMatrixGenerator()
        case RSBarcodesTypeISBN13Code:
            codeGenerator = RSISBN13Generator()
        case RSBarcodesTypeISSN13Code:
            codeGenerator = RSISSN13Generator()
        case RSBarcodesTypeExtendedCode39Code:
            codeGenerator = RSExtendedCode39Generator()
        default:
            print("No code generator selected.")
        }

        if codeGenerator != nil {
            codeGenerator!.fillColor = self.fillColor
            codeGenerator!.strokeColor = self.strokeColor
            return codeGenerator!.generateCode(contents, inputCorrectionLevel: inputCorrectionLevel, machineReadableCodeObjectType: machineReadableCodeObjectType)
        } else {
            return nil
        }
    }

The last row in the barHandler also:

func barHandler() {

        self.barcodesHandler = { barcodes in
            for barcode in barcodes {
                self.session.stopRunning()
                print("Barcode found: type=" + barcode.type.rawValue + " value=" + barcode.stringValue!)
                DispatchQueue.main.async(execute: { () -> Void in
                    //                        // MARK: NOTE: Perform UI related actions here.
                    if let barcode_discovered = barcode.stringValue {
                    discoveredBarcode = barcode_discovered
                    self.dismiss(animated: true, completion: nil)

                    }

                })
            }
        }

        let types = NSMutableArray(array: self.output.availableMetadataObjectTypes)
        types.remove(AVMetadataObject.ObjectType.qr)
        self.output.metadataObjectTypes = NSMutableArray(array: types) as? [AVMetadataObject.ObjectType]
    }