[REFACTORING] Rename completionBlock of QRCodeReader to codeDidFoundBlock

This commit is contained in:
Yannick Loriot 2016-01-24 12:15:57 +01:00
parent 5975bc938b
commit fe54455e66
3 changed files with 16 additions and 7 deletions

View File

@ -1,10 +1,15 @@
# Change log
## [Version 5.4.0](https://github.com/yannickl/QRCodeReader.swift/releases/tag/5.4.0)
Released on 2016-01-24.
- [REFACTORING] Rename `completionBlock` of `QRCodeReader` to `codeDidFoundBlock`.
## [Version 5.3.1](https://github.com/yannickl/QRCodeReader.swift/releases/tag/5.3.1)
Released on 2016-01-12.
- [FIX] `value` and `type` of `QRCodeReaderResult` are not optional.
- [REFACTORING] rename `type` to `metadataType` in `QRCodeReaderResult`.
- [REFACTORING] Rename `type` to `metadataType` in `QRCodeReaderResult`.
## [Version 5.3.0](https://github.com/yannickl/QRCodeReader.swift/releases/tag/5.3.0)
Released on 2016-01-11.

View File

@ -29,7 +29,7 @@ import AVFoundation
/// Reader object base on the `AVCaptureDevice` to read / scan 1D and 2D codes.
public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegate {
var defaultDevice: AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
var defaultDevice: AVCaptureDevice = .defaultDeviceWithMediaType(AVMediaTypeVideo)
var frontDevice: AVCaptureDevice? = {
for device in AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) {
if let _device = device as? AVCaptureDevice where _device.position == AVCaptureDevicePosition.Front {
@ -58,15 +58,19 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
// MARK: - Managing the Properties
/// CALayer that you use to display video as it is being captured by an input device.
public lazy var previewLayer: AVCaptureVideoPreviewLayer = { return AVCaptureVideoPreviewLayer(session: self.session) }()
public lazy var previewLayer: AVCaptureVideoPreviewLayer = {
return AVCaptureVideoPreviewLayer(session: self.session)
}()
/// An array of strings identifying the types of metadata objects to process.
public let metadataObjectTypes: [String]
// MARK: - Managing the Completion Block
// MARK: - Managing the Code Discovery
//public var stopScanningWhenCodeIsFound: Bool = true
/// Block is executing when a QRCode or when the user did stopped the scan.
public var completionBlock: (QRCodeReaderResult -> Void)?
public var codeDidFoundBlock: (QRCodeReaderResult -> Void)?
// MARK: - Creating the Code Reader
@ -272,7 +276,7 @@ public final class QRCodeReader: NSObject, AVCaptureMetadataOutputObjectsDelegat
let scannedResult = QRCodeReaderResult(value: _readableCodeObject.stringValue, metadataType:_readableCodeObject.type)
dispatch_async(dispatch_get_main_queue(), { [weak self] in
self?.completionBlock?(scannedResult)
self?.codeDidFoundBlock?(scannedResult)
})
}
}

View File

@ -128,7 +128,7 @@ public class QRCodeReaderViewController: UIViewController {
view.backgroundColor = .blackColor()
codeReader.completionBlock = { [weak self] resultAsObject in
codeReader.codeDidFoundBlock = { [weak self] resultAsObject in
if let weakSelf = self {
weakSelf.completionBlock?(resultAsObject)
weakSelf.delegate?.reader(weakSelf, didScanResult: resultAsObject)