├── .DS_Store ├── .gitattributes ├── LICENSE ├── ScanAndRecognizeText.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── gabriel.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── gabriel.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── ScanAndRecognizeText ├── .DS_Store ├── Assets.xcassets │ ├── .DS_Store │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── Info.plist ├── Model.swift ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json ├── ScanAndRecognizeTextApp.swift ├── ScannerView.swift ├── TextPreviewView.swift └── TextRecognition.swift └── TextScannerStarter.zip /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextScanner/1dff8a7ec5808255252d6b8c9bd848fdd1005160/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Simon Ng 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ScanAndRecognizeText.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | C068CD8D25EAB787001C5AA9 /* ScanAndRecognizeTextApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068CD8C25EAB787001C5AA9 /* ScanAndRecognizeTextApp.swift */; }; 11 | C068CD8F25EAB787001C5AA9 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068CD8E25EAB787001C5AA9 /* ContentView.swift */; }; 12 | C068CD9125EAB78A001C5AA9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C068CD9025EAB78A001C5AA9 /* Assets.xcassets */; }; 13 | C068CD9425EAB78A001C5AA9 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C068CD9325EAB78A001C5AA9 /* Preview Assets.xcassets */; }; 14 | C068CD9D25EAB824001C5AA9 /* TextPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068CD9C25EAB824001C5AA9 /* TextPreviewView.swift */; }; 15 | C068CDA225EABAE0001C5AA9 /* ScannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068CDA125EABAE0001C5AA9 /* ScannerView.swift */; }; 16 | C068CDA625EAC098001C5AA9 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068CDA525EAC098001C5AA9 /* Model.swift */; }; 17 | C068CDA925EAC9B7001C5AA9 /* TextRecognition.swift in Sources */ = {isa = PBXBuildFile; fileRef = C068CDA825EAC9B7001C5AA9 /* TextRecognition.swift */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXFileReference section */ 21 | C068CD8925EAB787001C5AA9 /* ScanAndRecognizeText.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ScanAndRecognizeText.app; sourceTree = BUILT_PRODUCTS_DIR; }; 22 | C068CD8C25EAB787001C5AA9 /* ScanAndRecognizeTextApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScanAndRecognizeTextApp.swift; sourceTree = ""; }; 23 | C068CD8E25EAB787001C5AA9 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 24 | C068CD9025EAB78A001C5AA9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | C068CD9325EAB78A001C5AA9 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 26 | C068CD9525EAB78A001C5AA9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | C068CD9C25EAB824001C5AA9 /* TextPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextPreviewView.swift; sourceTree = ""; }; 28 | C068CDA125EABAE0001C5AA9 /* ScannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScannerView.swift; sourceTree = ""; }; 29 | C068CDA525EAC098001C5AA9 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; 30 | C068CDA825EAC9B7001C5AA9 /* TextRecognition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextRecognition.swift; sourceTree = ""; }; 31 | /* End PBXFileReference section */ 32 | 33 | /* Begin PBXFrameworksBuildPhase section */ 34 | C068CD8625EAB787001C5AA9 /* Frameworks */ = { 35 | isa = PBXFrameworksBuildPhase; 36 | buildActionMask = 2147483647; 37 | files = ( 38 | ); 39 | runOnlyForDeploymentPostprocessing = 0; 40 | }; 41 | /* End PBXFrameworksBuildPhase section */ 42 | 43 | /* Begin PBXGroup section */ 44 | C068CD8025EAB786001C5AA9 = { 45 | isa = PBXGroup; 46 | children = ( 47 | C068CD8B25EAB787001C5AA9 /* ScanAndRecognizeText */, 48 | C068CD8A25EAB787001C5AA9 /* Products */, 49 | ); 50 | sourceTree = ""; 51 | }; 52 | C068CD8A25EAB787001C5AA9 /* Products */ = { 53 | isa = PBXGroup; 54 | children = ( 55 | C068CD8925EAB787001C5AA9 /* ScanAndRecognizeText.app */, 56 | ); 57 | name = Products; 58 | sourceTree = ""; 59 | }; 60 | C068CD8B25EAB787001C5AA9 /* ScanAndRecognizeText */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | C068CD8C25EAB787001C5AA9 /* ScanAndRecognizeTextApp.swift */, 64 | C068CD8E25EAB787001C5AA9 /* ContentView.swift */, 65 | C068CD9C25EAB824001C5AA9 /* TextPreviewView.swift */, 66 | C068CDA525EAC098001C5AA9 /* Model.swift */, 67 | C068CDA125EABAE0001C5AA9 /* ScannerView.swift */, 68 | C068CDA825EAC9B7001C5AA9 /* TextRecognition.swift */, 69 | C068CD9025EAB78A001C5AA9 /* Assets.xcassets */, 70 | C068CD9525EAB78A001C5AA9 /* Info.plist */, 71 | C068CD9225EAB78A001C5AA9 /* Preview Content */, 72 | ); 73 | path = ScanAndRecognizeText; 74 | sourceTree = ""; 75 | }; 76 | C068CD9225EAB78A001C5AA9 /* Preview Content */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | C068CD9325EAB78A001C5AA9 /* Preview Assets.xcassets */, 80 | ); 81 | path = "Preview Content"; 82 | sourceTree = ""; 83 | }; 84 | /* End PBXGroup section */ 85 | 86 | /* Begin PBXNativeTarget section */ 87 | C068CD8825EAB787001C5AA9 /* ScanAndRecognizeText */ = { 88 | isa = PBXNativeTarget; 89 | buildConfigurationList = C068CD9825EAB78A001C5AA9 /* Build configuration list for PBXNativeTarget "ScanAndRecognizeText" */; 90 | buildPhases = ( 91 | C068CD8525EAB787001C5AA9 /* Sources */, 92 | C068CD8625EAB787001C5AA9 /* Frameworks */, 93 | C068CD8725EAB787001C5AA9 /* Resources */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = ScanAndRecognizeText; 100 | productName = ScanAndRecognizeText; 101 | productReference = C068CD8925EAB787001C5AA9 /* ScanAndRecognizeText.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | C068CD8125EAB786001C5AA9 /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastSwiftUpdateCheck = 1240; 111 | LastUpgradeCheck = 1240; 112 | TargetAttributes = { 113 | C068CD8825EAB787001C5AA9 = { 114 | CreatedOnToolsVersion = 12.4; 115 | }; 116 | }; 117 | }; 118 | buildConfigurationList = C068CD8425EAB787001C5AA9 /* Build configuration list for PBXProject "ScanAndRecognizeText" */; 119 | compatibilityVersion = "Xcode 9.3"; 120 | developmentRegion = en; 121 | hasScannedForEncodings = 0; 122 | knownRegions = ( 123 | en, 124 | Base, 125 | ); 126 | mainGroup = C068CD8025EAB786001C5AA9; 127 | productRefGroup = C068CD8A25EAB787001C5AA9 /* Products */; 128 | projectDirPath = ""; 129 | projectRoot = ""; 130 | targets = ( 131 | C068CD8825EAB787001C5AA9 /* ScanAndRecognizeText */, 132 | ); 133 | }; 134 | /* End PBXProject section */ 135 | 136 | /* Begin PBXResourcesBuildPhase section */ 137 | C068CD8725EAB787001C5AA9 /* Resources */ = { 138 | isa = PBXResourcesBuildPhase; 139 | buildActionMask = 2147483647; 140 | files = ( 141 | C068CD9425EAB78A001C5AA9 /* Preview Assets.xcassets in Resources */, 142 | C068CD9125EAB78A001C5AA9 /* Assets.xcassets in Resources */, 143 | ); 144 | runOnlyForDeploymentPostprocessing = 0; 145 | }; 146 | /* End PBXResourcesBuildPhase section */ 147 | 148 | /* Begin PBXSourcesBuildPhase section */ 149 | C068CD8525EAB787001C5AA9 /* Sources */ = { 150 | isa = PBXSourcesBuildPhase; 151 | buildActionMask = 2147483647; 152 | files = ( 153 | C068CDA625EAC098001C5AA9 /* Model.swift in Sources */, 154 | C068CD8F25EAB787001C5AA9 /* ContentView.swift in Sources */, 155 | C068CDA225EABAE0001C5AA9 /* ScannerView.swift in Sources */, 156 | C068CD9D25EAB824001C5AA9 /* TextPreviewView.swift in Sources */, 157 | C068CDA925EAC9B7001C5AA9 /* TextRecognition.swift in Sources */, 158 | C068CD8D25EAB787001C5AA9 /* ScanAndRecognizeTextApp.swift in Sources */, 159 | ); 160 | runOnlyForDeploymentPostprocessing = 0; 161 | }; 162 | /* End PBXSourcesBuildPhase section */ 163 | 164 | /* Begin XCBuildConfiguration section */ 165 | C068CD9625EAB78A001C5AA9 /* Debug */ = { 166 | isa = XCBuildConfiguration; 167 | buildSettings = { 168 | ALWAYS_SEARCH_USER_PATHS = NO; 169 | CLANG_ANALYZER_NONNULL = YES; 170 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 171 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 172 | CLANG_CXX_LIBRARY = "libc++"; 173 | CLANG_ENABLE_MODULES = YES; 174 | CLANG_ENABLE_OBJC_ARC = YES; 175 | CLANG_ENABLE_OBJC_WEAK = YES; 176 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 177 | CLANG_WARN_BOOL_CONVERSION = YES; 178 | CLANG_WARN_COMMA = YES; 179 | CLANG_WARN_CONSTANT_CONVERSION = YES; 180 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 181 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 182 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 183 | CLANG_WARN_EMPTY_BODY = YES; 184 | CLANG_WARN_ENUM_CONVERSION = YES; 185 | CLANG_WARN_INFINITE_RECURSION = YES; 186 | CLANG_WARN_INT_CONVERSION = YES; 187 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 188 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 189 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 190 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 191 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 192 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 193 | CLANG_WARN_STRICT_PROTOTYPES = YES; 194 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 195 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 196 | CLANG_WARN_UNREACHABLE_CODE = YES; 197 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 198 | COPY_PHASE_STRIP = NO; 199 | DEBUG_INFORMATION_FORMAT = dwarf; 200 | ENABLE_STRICT_OBJC_MSGSEND = YES; 201 | ENABLE_TESTABILITY = YES; 202 | GCC_C_LANGUAGE_STANDARD = gnu11; 203 | GCC_DYNAMIC_NO_PIC = NO; 204 | GCC_NO_COMMON_BLOCKS = YES; 205 | GCC_OPTIMIZATION_LEVEL = 0; 206 | GCC_PREPROCESSOR_DEFINITIONS = ( 207 | "DEBUG=1", 208 | "$(inherited)", 209 | ); 210 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 211 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 212 | GCC_WARN_UNDECLARED_SELECTOR = YES; 213 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 214 | GCC_WARN_UNUSED_FUNCTION = YES; 215 | GCC_WARN_UNUSED_VARIABLE = YES; 216 | IPHONEOS_DEPLOYMENT_TARGET = 14.4; 217 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 218 | MTL_FAST_MATH = YES; 219 | ONLY_ACTIVE_ARCH = YES; 220 | SDKROOT = iphoneos; 221 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 222 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 223 | }; 224 | name = Debug; 225 | }; 226 | C068CD9725EAB78A001C5AA9 /* Release */ = { 227 | isa = XCBuildConfiguration; 228 | buildSettings = { 229 | ALWAYS_SEARCH_USER_PATHS = NO; 230 | CLANG_ANALYZER_NONNULL = YES; 231 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 232 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 233 | CLANG_CXX_LIBRARY = "libc++"; 234 | CLANG_ENABLE_MODULES = YES; 235 | CLANG_ENABLE_OBJC_ARC = YES; 236 | CLANG_ENABLE_OBJC_WEAK = YES; 237 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 238 | CLANG_WARN_BOOL_CONVERSION = YES; 239 | CLANG_WARN_COMMA = YES; 240 | CLANG_WARN_CONSTANT_CONVERSION = YES; 241 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 242 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 243 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 244 | CLANG_WARN_EMPTY_BODY = YES; 245 | CLANG_WARN_ENUM_CONVERSION = YES; 246 | CLANG_WARN_INFINITE_RECURSION = YES; 247 | CLANG_WARN_INT_CONVERSION = YES; 248 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 250 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 251 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 252 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 253 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 254 | CLANG_WARN_STRICT_PROTOTYPES = YES; 255 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 256 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 257 | CLANG_WARN_UNREACHABLE_CODE = YES; 258 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 259 | COPY_PHASE_STRIP = NO; 260 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 261 | ENABLE_NS_ASSERTIONS = NO; 262 | ENABLE_STRICT_OBJC_MSGSEND = YES; 263 | GCC_C_LANGUAGE_STANDARD = gnu11; 264 | GCC_NO_COMMON_BLOCKS = YES; 265 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 266 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 267 | GCC_WARN_UNDECLARED_SELECTOR = YES; 268 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 269 | GCC_WARN_UNUSED_FUNCTION = YES; 270 | GCC_WARN_UNUSED_VARIABLE = YES; 271 | IPHONEOS_DEPLOYMENT_TARGET = 14.4; 272 | MTL_ENABLE_DEBUG_INFO = NO; 273 | MTL_FAST_MATH = YES; 274 | SDKROOT = iphoneos; 275 | SWIFT_COMPILATION_MODE = wholemodule; 276 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 277 | VALIDATE_PRODUCT = YES; 278 | }; 279 | name = Release; 280 | }; 281 | C068CD9925EAB78A001C5AA9 /* Debug */ = { 282 | isa = XCBuildConfiguration; 283 | buildSettings = { 284 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 285 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 286 | CODE_SIGN_STYLE = Automatic; 287 | DEVELOPMENT_ASSET_PATHS = "\"ScanAndRecognizeText/Preview Content\""; 288 | DEVELOPMENT_TEAM = 9BTCAVN99V; 289 | ENABLE_PREVIEWS = YES; 290 | INFOPLIST_FILE = ScanAndRecognizeText/Info.plist; 291 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 292 | LD_RUNPATH_SEARCH_PATHS = ( 293 | "$(inherited)", 294 | "@executable_path/Frameworks", 295 | ); 296 | PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.ScanAndRecognizeText; 297 | PRODUCT_NAME = "$(TARGET_NAME)"; 298 | SWIFT_VERSION = 5.0; 299 | TARGETED_DEVICE_FAMILY = "1,2"; 300 | }; 301 | name = Debug; 302 | }; 303 | C068CD9A25EAB78A001C5AA9 /* Release */ = { 304 | isa = XCBuildConfiguration; 305 | buildSettings = { 306 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 307 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 308 | CODE_SIGN_STYLE = Automatic; 309 | DEVELOPMENT_ASSET_PATHS = "\"ScanAndRecognizeText/Preview Content\""; 310 | DEVELOPMENT_TEAM = 9BTCAVN99V; 311 | ENABLE_PREVIEWS = YES; 312 | INFOPLIST_FILE = ScanAndRecognizeText/Info.plist; 313 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 314 | LD_RUNPATH_SEARCH_PATHS = ( 315 | "$(inherited)", 316 | "@executable_path/Frameworks", 317 | ); 318 | PRODUCT_BUNDLE_IDENTIFIER = com.appcoda.ScanAndRecognizeText; 319 | PRODUCT_NAME = "$(TARGET_NAME)"; 320 | SWIFT_VERSION = 5.0; 321 | TARGETED_DEVICE_FAMILY = "1,2"; 322 | }; 323 | name = Release; 324 | }; 325 | /* End XCBuildConfiguration section */ 326 | 327 | /* Begin XCConfigurationList section */ 328 | C068CD8425EAB787001C5AA9 /* Build configuration list for PBXProject "ScanAndRecognizeText" */ = { 329 | isa = XCConfigurationList; 330 | buildConfigurations = ( 331 | C068CD9625EAB78A001C5AA9 /* Debug */, 332 | C068CD9725EAB78A001C5AA9 /* Release */, 333 | ); 334 | defaultConfigurationIsVisible = 0; 335 | defaultConfigurationName = Release; 336 | }; 337 | C068CD9825EAB78A001C5AA9 /* Build configuration list for PBXNativeTarget "ScanAndRecognizeText" */ = { 338 | isa = XCConfigurationList; 339 | buildConfigurations = ( 340 | C068CD9925EAB78A001C5AA9 /* Debug */, 341 | C068CD9A25EAB78A001C5AA9 /* Release */, 342 | ); 343 | defaultConfigurationIsVisible = 0; 344 | defaultConfigurationName = Release; 345 | }; 346 | /* End XCConfigurationList section */ 347 | }; 348 | rootObject = C068CD8125EAB786001C5AA9 /* Project object */; 349 | } 350 | -------------------------------------------------------------------------------- /ScanAndRecognizeText.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ScanAndRecognizeText.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ScanAndRecognizeText.xcodeproj/project.xcworkspace/xcuserdata/gabriel.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextScanner/1dff8a7ec5808255252d6b8c9bd848fdd1005160/ScanAndRecognizeText.xcodeproj/project.xcworkspace/xcuserdata/gabriel.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /ScanAndRecognizeText.xcodeproj/xcuserdata/gabriel.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | ScanAndRecognizeText.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextScanner/1dff8a7ec5808255252d6b8c9bd848fdd1005160/ScanAndRecognizeText/.DS_Store -------------------------------------------------------------------------------- /ScanAndRecognizeText/Assets.xcassets/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextScanner/1dff8a7ec5808255252d6b8c9bd848fdd1005160/ScanAndRecognizeText/Assets.xcassets/.DS_Store -------------------------------------------------------------------------------- /ScanAndRecognizeText/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "scale" : "1x", 46 | "size" : "20x20" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "scale" : "2x", 51 | "size" : "20x20" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "scale" : "1x", 56 | "size" : "29x29" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "scale" : "2x", 61 | "size" : "29x29" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "scale" : "1x", 66 | "size" : "40x40" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "scale" : "2x", 71 | "size" : "40x40" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "scale" : "1x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "76x76" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "scale" : "2x", 86 | "size" : "83.5x83.5" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "scale" : "1x", 91 | "size" : "1024x1024" 92 | } 93 | ], 94 | "info" : { 95 | "author" : "xcode", 96 | "version" : 1 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // ScanAndRecognizeText 4 | // 5 | // Created by Gabriel Theodoropoulos. 6 | // 7 | 8 | import SwiftUI 9 | 10 | struct ContentView: View { 11 | @ObservedObject var recognizedContent = RecognizedContent() 12 | @State private var showScanner = false 13 | @State private var isRecognizing = false 14 | 15 | var body: some View { 16 | NavigationView { 17 | ZStack(alignment: .bottom) { 18 | List(recognizedContent.items, id: \.id) { textItem in 19 | NavigationLink(destination: TextPreviewView(text: textItem.text)) { 20 | Text(String(textItem.text.prefix(50)).appending("...")) 21 | } 22 | } 23 | 24 | 25 | if isRecognizing { 26 | ProgressView() 27 | .progressViewStyle(CircularProgressViewStyle(tint: Color(UIColor.systemIndigo))) 28 | .padding(.bottom, 20) 29 | } 30 | 31 | } 32 | .navigationTitle("Text Scanner") 33 | .navigationBarItems(trailing: Button(action: { 34 | guard !isRecognizing else { return } 35 | showScanner = true 36 | }, label: { 37 | HStack { 38 | Image(systemName: "doc.text.viewfinder") 39 | .renderingMode(.template) 40 | .foregroundColor(.white) 41 | 42 | Text("Scan") 43 | .foregroundColor(.white) 44 | } 45 | .padding(.horizontal, 16) 46 | .frame(height: 36) 47 | .background(Color(UIColor.systemIndigo)) 48 | .cornerRadius(18) 49 | })) 50 | } 51 | .sheet(isPresented: $showScanner, content: { 52 | ScannerView { result in 53 | switch result { 54 | case .success(let scannedImages): 55 | isRecognizing = true 56 | 57 | TextRecognition(scannedImages: scannedImages, 58 | recognizedContent: recognizedContent) { 59 | // Text recognition is finished, hide the progress indicator. 60 | isRecognizing = false 61 | } 62 | .recognizeText() 63 | 64 | case .failure(let error): 65 | print(error.localizedDescription) 66 | } 67 | 68 | showScanner = false 69 | 70 | } didCancelScanning: { 71 | // Dismiss the scanner controller and the sheet. 72 | showScanner = false 73 | } 74 | }) 75 | } 76 | } 77 | 78 | struct ContentView_Previews: PreviewProvider { 79 | static var previews: some View { 80 | ContentView() 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | 28 | UIApplicationSupportsIndirectInputEvents 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | NSCameraUsageDescription 50 | The app needs to access the camera in order to scan documents. 51 | 52 | 53 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/Model.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Model.swift 3 | // ScanAndRecognizeText 4 | // 5 | // Created by Gabriel Theodoropoulos. 6 | // 7 | 8 | import Foundation 9 | 10 | class TextItem: Identifiable { 11 | var id: String 12 | var text: String = "" 13 | 14 | init() { 15 | id = UUID().uuidString 16 | } 17 | } 18 | 19 | 20 | class RecognizedContent: ObservableObject { 21 | @Published var items = [TextItem]() 22 | } 23 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/ScanAndRecognizeTextApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScanAndRecognizeTextApp.swift 3 | // ScanAndRecognizeText 4 | // 5 | // Created by Gabriel Theodoropoulos. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct ScanAndRecognizeTextApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ScanAndRecognizeText/ScannerView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ScannerView.swift 3 | // ScanAndRecognizeText 4 | // 5 | // Created by Gabriel Theodoropoulos. 6 | // 7 | 8 | import SwiftUI 9 | import VisionKit 10 | 11 | struct ScannerView: UIViewControllerRepresentable { 12 | var didFinishScanning: ((_ result: Result<[UIImage], Error>) -> Void) 13 | var didCancelScanning: () -> Void 14 | 15 | func makeUIViewController(context: Context) -> VNDocumentCameraViewController { 16 | let scannerViewController = VNDocumentCameraViewController() 17 | scannerViewController.delegate = context.coordinator 18 | return scannerViewController 19 | } 20 | 21 | func updateUIViewController(_ uiViewController: VNDocumentCameraViewController, context: Context) { } 22 | 23 | 24 | func makeCoordinator() -> Coordinator { 25 | Coordinator(with: self) 26 | } 27 | 28 | 29 | class Coordinator: NSObject, VNDocumentCameraViewControllerDelegate { 30 | let scannerView: ScannerView 31 | 32 | init(with scannerView: ScannerView) { 33 | self.scannerView = scannerView 34 | } 35 | 36 | 37 | // MARK: - VNDocumentCameraViewControllerDelegate 38 | 39 | func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) { 40 | var scannedPages = [UIImage]() 41 | 42 | for i in 0.. Void 15 | 16 | 17 | func recognizeText() { 18 | let queue = DispatchQueue(label: "textRecognitionQueue", qos: .userInitiated) 19 | queue.async { 20 | for image in scannedImages { 21 | guard let cgImage = image.cgImage else { return } 22 | 23 | let requestHandler = VNImageRequestHandler(cgImage: cgImage, options: [:]) 24 | 25 | do { 26 | let textItem = TextItem() 27 | try requestHandler.perform([getTextRecognitionRequest(with: textItem)]) 28 | 29 | DispatchQueue.main.async { 30 | recognizedContent.items.append(textItem) 31 | } 32 | } catch { 33 | print(error.localizedDescription) 34 | } 35 | 36 | DispatchQueue.main.async { 37 | didFinishRecognition() 38 | } 39 | } 40 | } 41 | } 42 | 43 | 44 | private func getTextRecognitionRequest(with textItem: TextItem) -> VNRecognizeTextRequest { 45 | let request = VNRecognizeTextRequest { request, error in 46 | if let error = error { 47 | print(error.localizedDescription) 48 | return 49 | } 50 | 51 | guard let observations = request.results as? [VNRecognizedTextObservation] else { return } 52 | 53 | observations.forEach { observation in 54 | guard let recognizedText = observation.topCandidates(1).first else { return } 55 | textItem.text += recognizedText.string 56 | textItem.text += "\n" 57 | } 58 | } 59 | 60 | request.recognitionLevel = .accurate 61 | request.usesLanguageCorrection = true 62 | 63 | return request 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /TextScannerStarter.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/appcoda/TextScanner/1dff8a7ec5808255252d6b8c9bd848fdd1005160/TextScannerStarter.zip --------------------------------------------------------------------------------