Skip to content

Commit c2febc1

Browse files
committed
forceDocFormat changed type
1 parent c036bd9 commit c2febc1

3 files changed

Lines changed: 84 additions & 5 deletions

File tree

Samples/Advanced/DocumentReader-Swift/DocumentReader-Swift.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
868341E726F0C11B00644618 /* DocFormat+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 868341E626F0C11B00644618 /* DocFormat+Extensions.swift */; };
1011
86878F0626EF96360082F481 /* NSObject+ClassName.swift in Sources */ = {isa = PBXBuildFile; fileRef = 86878F0526EF96360082F481 /* NSObject+ClassName.swift */; };
1112
9D00FDD225D2E3DA00D6FEF1 /* BarcodeTypes+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D00FDD125D2E3DA00D6FEF1 /* BarcodeTypes+Extensions.swift */; };
1213
9D00FDD525D3C34300D6FEF1 /* BarcodeListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D00FDD425D3C34300D6FEF1 /* BarcodeListViewController.swift */; };
@@ -55,6 +56,7 @@
5556
0BBE1365BE97A7AE1B68DF58 /* Pods-DocumentReader-Swift.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocumentReader-Swift.release.xcconfig"; path = "Target Support Files/Pods-DocumentReader-Swift/Pods-DocumentReader-Swift.release.xcconfig"; sourceTree = "<group>"; };
5657
0DC5DA1B48C6A7B2425AF7F0 /* Pods_DocumentReader_Swift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_DocumentReader_Swift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
5758
2391B685CCD628B0DFA19E1A /* Pods-DocumentReader-Swift.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-DocumentReader-Swift.debug.xcconfig"; path = "Target Support Files/Pods-DocumentReader-Swift/Pods-DocumentReader-Swift.debug.xcconfig"; sourceTree = "<group>"; };
59+
868341E626F0C11B00644618 /* DocFormat+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DocFormat+Extensions.swift"; sourceTree = "<group>"; };
5860
86878F0526EF96360082F481 /* NSObject+ClassName.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSObject+ClassName.swift"; sourceTree = "<group>"; };
5961
9D00FDD125D2E3DA00D6FEF1 /* BarcodeTypes+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BarcodeTypes+Extensions.swift"; sourceTree = "<group>"; };
6062
9D00FDD425D3C34300D6FEF1 /* BarcodeListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BarcodeListViewController.swift; sourceTree = "<group>"; };
@@ -135,6 +137,7 @@
135137
9DC45D2F25D692AC0077AE4A /* DocReaderFrame+Extensions.swift */,
136138
9DFBD7D925E6689900428089 /* RFIDAccessControlProcedureType+Extensions.swift */,
137139
86878F0526EF96360082F481 /* NSObject+ClassName.swift */,
140+
868341E626F0C11B00644618 /* DocFormat+Extensions.swift */,
138141
);
139142
path = Extensions;
140143
sourceTree = "<group>";
@@ -387,6 +390,7 @@
387390
buildActionMask = 2147483647;
388391
files = (
389392
9D4B75C525D5315D00EB4EA4 /* CustomRfidViewController.swift in Sources */,
393+
868341E726F0C11B00644618 /* DocFormat+Extensions.swift in Sources */,
390394
9DF08E5C25D3F84B00880F7E /* TextFieldViewController.swift in Sources */,
391395
9DF08E5225D3C9C700880F7E /* SettingsActionCell.swift in Sources */,
392396
86878F0626EF96360082F481 /* NSObject+ClassName.swift in Sources */,
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// DocumentReaderDocumentType+Extesions.swift
3+
// DocumentReader-Swift
4+
//
5+
// Created by Pavel Kondrashkov on 9/14/21.
6+
// Copyright © 2021 Regula. All rights reserved.
7+
//
8+
9+
import DocumentReader
10+
11+
extension DocFormat: CaseIterable {
12+
public typealias AllCases = [DocFormat]
13+
14+
public static var allCases: [DocFormat] = [
15+
.ID1,
16+
.ID2,
17+
.ID3,
18+
.NON,
19+
.A4,
20+
.id3_x2,
21+
.ID1_90,
22+
.ID1_180,
23+
.ID1_270,
24+
.ID2_180,
25+
.ID3_180,
26+
.custom,
27+
.flexible,
28+
]
29+
}
30+
31+
extension DocFormat: LosslessStringConvertible {
32+
public var description: String {
33+
switch self {
34+
case .ID1: return "ID1"
35+
case .ID2: return "ID2"
36+
case .ID3: return "ID3"
37+
case .NON: return "NON"
38+
case .A4: return "A4"
39+
case .id3_x2: return "id3_x2"
40+
case .ID1_90: return "ID1_90"
41+
case .ID1_180: return "ID1_180"
42+
case .ID1_270: return "ID1_270"
43+
case .ID2_180: return "ID2_180"
44+
case .ID3_180: return "ID3_180"
45+
case .custom: return "custom"
46+
case .flexible: return "flexible"
47+
@unknown default:
48+
fatalError()
49+
}
50+
}
51+
52+
public init?(_ description: String) {
53+
guard let match = Self.allCases.first(where: { $0.description == description }) else {
54+
return nil
55+
}
56+
self.init(rawValue: match.rawValue)
57+
}
58+
}

Samples/Advanced/DocumentReader-Swift/DocumentReader-Swift/SettingsViewController/SettingsViewController.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,16 @@ class SettingsViewController: UIViewController {
335335
}
336336
let forceDocFormat = SettingsActionItem(title: "Force Doc Format") { [weak self] in
337337
guard let self = self else { return }
338-
self.showIntegerArrayEditor(title: "Force Doc Format", inputArray: DocReader.shared.processParams.forceDocFormat as? [Int]) { output in
339-
DocReader.shared.processParams.forceDocFormat = output
338+
let currentValue = params.forceDocFormat.map { $0.intValue }.flatMap { DocFormat(rawValue: $0)?.description } ?? "nil"
339+
let options: [String] = DocFormat.allCases.map { $0.description } + ["nil"]
340+
self.showOptionsPicker(title: "Force Doc Format", current: currentValue, options: options) { (result) in
341+
let param = DocFormat(result).map { NSNumber(value: $0.rawValue) }
342+
DocReader.shared.processParams.forceDocFormat = param
340343
self.tableView.reloadData()
341344
}
342345
} state: {
343-
let currentList = DocReader.shared.processParams.forceDocFormat ?? []
344-
let value = currentList.compactMap { $0.stringValue }.joined(separator: ", ")
345-
return value.isEmpty ? "nil" : value
346+
let currentValue = params.forceDocFormat.map { $0.intValue }.flatMap { DocFormat(rawValue: $0)?.description } ?? "nil"
347+
return currentValue
346348
}
347349
let multiDocOnImage = SettingsOptionalBoolItem(title: "Multi Doc On Image", object: params, keypath: \.multiDocOnImage)
348350
let shiftExpiryDate = SettingsOptionalIntItem(title: "Shift Expiry Date", object: params, keypath: \.shiftExpiryDate)
@@ -532,6 +534,21 @@ class SettingsViewController: UIViewController {
532534
present(actionSheet, animated: true, completion: nil)
533535
}
534536

537+
private func showOptionsPicker(title: String, current: String, options: [String], completion: @escaping (String) -> Void) {
538+
let actionSheet = UIAlertController(title: nil, message: title, preferredStyle: self.alertStyleForDevice())
539+
for option in options {
540+
let action = UIAlertAction(title: option, style: .default) { _ in
541+
completion(option)
542+
}
543+
if option == current {
544+
action.setValue(true, forKey: "checked")
545+
}
546+
actionSheet.addAction(action)
547+
}
548+
actionSheet.addAction(UIAlertAction.init(title: "Cancel", style: .cancel, handler: nil))
549+
present(actionSheet, animated: true, completion: nil)
550+
}
551+
535552
private func showCaptureModeList(_ completion: VoidClosure? = nil) {
536553
let modes: [CaptureMode] = [.auto, .captureVideo, .captureFrame]
537554
let actionSheet = UIAlertController(title: nil, message: "functionality.captureMode",

0 commit comments

Comments
 (0)