# Class MRZScannerViewController

`MRZScannerViewController` is an extension of the `ViewController` class that implements MRZ scanning features.

## Definition

*Assembly:* DynamsoftMRZScanner.xcframework

<div class="sample-code-prefix"></div>
>- Objective-C
>- Swift
>
>1. 
```objc
@interface DSMRZScannerViewController: UIViewController
```
2. 
```swift
class MRZScannerViewController: UIViewController
```

## Properties

| Property | Type | Description |
| -------- | ---- | ----------- |
| [`config`](#config) | *DSMRZScannerConfig \** | Sets or returns the MRZ scanner configurations. |
| [`onScannedResult`](#onscannedresult) | *void (^)(DSMRZScanResult *)* | A property that holds a Block. The block is a callback that takes a single parameter of type `DSMRZScanResult` and returns no value. |

## config

Sets or returns the MRZ scanner configurations of type [`DSMRZScannerConfig`](https://www.dynamsoft.com/mrz-scanner/docs/mobile/programming/ios/api-reference/mrz-scanner-config.md).

<div class="sample-code-prefix"></div>
>- Objective-C
>- Swift
>
>1. 
```objc
@property (nonatomic, strong, readwrite) DSMRZScannerConfig * config
```
2. 
```swift
var config: MRZScannerConfig = .init()
```

## onScannedResult

A property that holds a Block. The block is a callback that takes a single parameter of type [`DSMRZScanResult`](https://www.dynamsoft.com/mrz-scanner/docs/mobile/programming/ios/api-reference/mrz-scan-result.md) and returns no value.

<div class="sample-code-prefix"></div>
>- Objective-C
>- Swift
>
>1. 
```objc
@property (nonatomic, copy, readwrite) void (^)(DSMRZScanResult *) onScannedResult
```
2. 
```swift
var onScannedResult: ((MRZScanResult) -> Void)?
```

## How to Use

<div class="sample-code-prefix"></div>
>- Objective-C
>- Swift
>
>1. 
```objc
#import "ViewController.h"
#import <DynamsoftLicense/DynamsoftLicense.h>
#import <DynamsoftMRZScanner/DynamsoftMRZScanner.h>
#import <DynamsoftMRZScanner/DynamsoftMRZScanner-Swift.h>
@interface ViewController ()
@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
   [super viewDidLoad];
   [self setup];
}
// Configure a button that pushes MRZScannerViewController when tapped.
- (void)buttonTapped {
   DSMRZScannerViewController *vc = [[DSMRZScannerViewController alloc] init];
   DSMRZScannerConfig *config = [[DSMRZScannerConfig alloc] init];
   config.license = @"DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9";
   vc.config = config;
   __weak typeof(self) weakSelf = self;
   vc.onScannedResult = ^(DSMRZScanResult *result) {
          // The result has 3 statuses: finished, canceled, and exception.
          switch (result.resultStatus) {
             case DSResultStatusFinished: {
                    // Access result.data for the parsed MRZ fields (name, DOB, nationality, expiry, etc.)
             }
             case DSResultStatusCanceled: {
                    // User dismissed the scanner — no MRZ data is available.
             }
             case DSResultStatusException: {
                    // An error occurred — check result.errorString for details.
             }
             default:
                    break;
          }
          dispatch_async(dispatch_get_main_queue(), ^{
             [weakSelf.navigationController popViewControllerAnimated:YES];
          });
   };
   dispatch_async(dispatch_get_main_queue(), ^{
          weakSelf.navigationController.navigationBar.hidden = YES;
          [weakSelf.navigationController pushViewController:vc animated:YES];
   });
}
@end
```
2. 
```swift
import UIKit
import DynamsoftLicense
import DynamsoftMRZScanner
class ViewController: UIViewController {
   let button = UIButton()
   let label = UILabel()
   override func viewDidLoad() {
          super.viewDidLoad()
          setup()
   }
   // Configure a button that pushes MRZScannerViewController when tapped.
   @objc func buttonTapped() {
          let vc = MRZScannerViewController()
          let config = MRZScannerConfig()
          config.license = "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9"
          vc.config = config
          // Set up the result callback of MRZScannerViewController.
          vc.onScannedResult = { [weak self] result in
             guard let self = self else { return }
             // The result has 3 statuses: finished, canceled, and exception.
             switch result.resultStatus {
             case .finished:
                    // Access result.data for the parsed MRZ fields (name, DOB, nationality, expiry, etc.)
             case .canceled:
                    // User dismissed the scanner — no MRZ data is available.
             case .exception:
                    // An error occurred — check result.errorString for details.
             @unknown default:
                    break
             }
             DispatchQueue.main.async {
                    self.navigationController?.popViewController(animated: true)
             }
          }
          DispatchQueue.main.async {
             self.navigationController?.navigationBar.isHidden = true
             self.navigationController?.pushViewController(vc, animated: true)
          }
   }
}
```
