├── README.md ├── TextRecognizerSwiftUI.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── mmitrevs.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── mmitrevs.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist └── TextRecognizerSwiftUI ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json └── Contents.json ├── Base.lproj └── LaunchScreen.storyboard ├── ContentView.swift ├── Info.plist ├── Preview Content └── Preview Assets.xcassets │ └── Contents.json ├── RecongizedText.swift ├── ScanningView.swift ├── SceneDelegate.swift └── TextRecognizer.swift /README.md: -------------------------------------------------------------------------------- 1 | # TextRecognizerSwiftUI 2 | Sample project showing how to use Vision's new text recognition API, along with Apple's new UI framework SwiftUI. 3 | 4 | Blog post: https://martinmitrevski.com/2019/06/16/text-recognition-on-ios-13-with-vision-swiftui-and-combine/. 5 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E80C7A8F22B67BA700E76B68 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80C7A8E22B67BA700E76B68 /* AppDelegate.swift */; }; 11 | E80C7A9122B67BA700E76B68 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80C7A9022B67BA700E76B68 /* SceneDelegate.swift */; }; 12 | E80C7A9322B67BA700E76B68 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80C7A9222B67BA700E76B68 /* ContentView.swift */; }; 13 | E80C7A9522B67BA800E76B68 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E80C7A9422B67BA800E76B68 /* Assets.xcassets */; }; 14 | E80C7A9822B67BA800E76B68 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E80C7A9722B67BA800E76B68 /* Preview Assets.xcassets */; }; 15 | E80C7A9B22B67BA800E76B68 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E80C7A9922B67BA800E76B68 /* LaunchScreen.storyboard */; }; 16 | E80C7AA522B67BD500E76B68 /* RecongizedText.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80C7AA222B67BD500E76B68 /* RecongizedText.swift */; }; 17 | E80C7AA722B67BD500E76B68 /* TextRecognizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80C7AA422B67BD500E76B68 /* TextRecognizer.swift */; }; 18 | E80C7AAA22B67C6B00E76B68 /* ScanningView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E80C7AA822B67BF300E76B68 /* ScanningView.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | E80C7A8B22B67BA700E76B68 /* TextRecognizerSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TextRecognizerSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | E80C7A8E22B67BA700E76B68 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 24 | E80C7A9022B67BA700E76B68 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 25 | E80C7A9222B67BA700E76B68 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 26 | E80C7A9422B67BA800E76B68 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 27 | E80C7A9722B67BA800E76B68 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 28 | E80C7A9A22B67BA800E76B68 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 29 | E80C7A9C22B67BA800E76B68 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 30 | E80C7AA222B67BD500E76B68 /* RecongizedText.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RecongizedText.swift; sourceTree = ""; }; 31 | E80C7AA422B67BD500E76B68 /* TextRecognizer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextRecognizer.swift; sourceTree = ""; }; 32 | E80C7AA822B67BF300E76B68 /* ScanningView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScanningView.swift; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | E80C7A8822B67BA700E76B68 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | E80C7A8222B67BA700E76B68 = { 47 | isa = PBXGroup; 48 | children = ( 49 | E80C7A8D22B67BA700E76B68 /* TextRecognizerSwiftUI */, 50 | E80C7A8C22B67BA700E76B68 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | E80C7A8C22B67BA700E76B68 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | E80C7A8B22B67BA700E76B68 /* TextRecognizerSwiftUI.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | E80C7A8D22B67BA700E76B68 /* TextRecognizerSwiftUI */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | E80C7A8E22B67BA700E76B68 /* AppDelegate.swift */, 66 | E80C7A9022B67BA700E76B68 /* SceneDelegate.swift */, 67 | E80C7A9222B67BA700E76B68 /* ContentView.swift */, 68 | E80C7AA822B67BF300E76B68 /* ScanningView.swift */, 69 | E80C7AA222B67BD500E76B68 /* RecongizedText.swift */, 70 | E80C7AA422B67BD500E76B68 /* TextRecognizer.swift */, 71 | E80C7A9422B67BA800E76B68 /* Assets.xcassets */, 72 | E80C7A9922B67BA800E76B68 /* LaunchScreen.storyboard */, 73 | E80C7A9C22B67BA800E76B68 /* Info.plist */, 74 | E80C7A9622B67BA800E76B68 /* Preview Content */, 75 | ); 76 | path = TextRecognizerSwiftUI; 77 | sourceTree = ""; 78 | }; 79 | E80C7A9622B67BA800E76B68 /* Preview Content */ = { 80 | isa = PBXGroup; 81 | children = ( 82 | E80C7A9722B67BA800E76B68 /* Preview Assets.xcassets */, 83 | ); 84 | path = "Preview Content"; 85 | sourceTree = ""; 86 | }; 87 | /* End PBXGroup section */ 88 | 89 | /* Begin PBXNativeTarget section */ 90 | E80C7A8A22B67BA700E76B68 /* TextRecognizerSwiftUI */ = { 91 | isa = PBXNativeTarget; 92 | buildConfigurationList = E80C7A9F22B67BA800E76B68 /* Build configuration list for PBXNativeTarget "TextRecognizerSwiftUI" */; 93 | buildPhases = ( 94 | E80C7A8722B67BA700E76B68 /* Sources */, 95 | E80C7A8822B67BA700E76B68 /* Frameworks */, 96 | E80C7A8922B67BA700E76B68 /* Resources */, 97 | ); 98 | buildRules = ( 99 | ); 100 | dependencies = ( 101 | ); 102 | name = TextRecognizerSwiftUI; 103 | productName = TextRecognizerSwiftUI; 104 | productReference = E80C7A8B22B67BA700E76B68 /* TextRecognizerSwiftUI.app */; 105 | productType = "com.apple.product-type.application"; 106 | }; 107 | /* End PBXNativeTarget section */ 108 | 109 | /* Begin PBXProject section */ 110 | E80C7A8322B67BA700E76B68 /* Project object */ = { 111 | isa = PBXProject; 112 | attributes = { 113 | LastSwiftUpdateCheck = 1100; 114 | LastUpgradeCheck = 1100; 115 | ORGANIZATIONNAME = Mitrevski; 116 | TargetAttributes = { 117 | E80C7A8A22B67BA700E76B68 = { 118 | CreatedOnToolsVersion = 11.0; 119 | }; 120 | }; 121 | }; 122 | buildConfigurationList = E80C7A8622B67BA700E76B68 /* Build configuration list for PBXProject "TextRecognizerSwiftUI" */; 123 | compatibilityVersion = "Xcode 9.3"; 124 | developmentRegion = en; 125 | hasScannedForEncodings = 0; 126 | knownRegions = ( 127 | en, 128 | Base, 129 | ); 130 | mainGroup = E80C7A8222B67BA700E76B68; 131 | productRefGroup = E80C7A8C22B67BA700E76B68 /* Products */; 132 | projectDirPath = ""; 133 | projectRoot = ""; 134 | targets = ( 135 | E80C7A8A22B67BA700E76B68 /* TextRecognizerSwiftUI */, 136 | ); 137 | }; 138 | /* End PBXProject section */ 139 | 140 | /* Begin PBXResourcesBuildPhase section */ 141 | E80C7A8922B67BA700E76B68 /* Resources */ = { 142 | isa = PBXResourcesBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | E80C7A9B22B67BA800E76B68 /* LaunchScreen.storyboard in Resources */, 146 | E80C7A9822B67BA800E76B68 /* Preview Assets.xcassets in Resources */, 147 | E80C7A9522B67BA800E76B68 /* Assets.xcassets in Resources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXResourcesBuildPhase section */ 152 | 153 | /* Begin PBXSourcesBuildPhase section */ 154 | E80C7A8722B67BA700E76B68 /* Sources */ = { 155 | isa = PBXSourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | E80C7A8F22B67BA700E76B68 /* AppDelegate.swift in Sources */, 159 | E80C7A9122B67BA700E76B68 /* SceneDelegate.swift in Sources */, 160 | E80C7AAA22B67C6B00E76B68 /* ScanningView.swift in Sources */, 161 | E80C7AA522B67BD500E76B68 /* RecongizedText.swift in Sources */, 162 | E80C7AA722B67BD500E76B68 /* TextRecognizer.swift in Sources */, 163 | E80C7A9322B67BA700E76B68 /* ContentView.swift in Sources */, 164 | ); 165 | runOnlyForDeploymentPostprocessing = 0; 166 | }; 167 | /* End PBXSourcesBuildPhase section */ 168 | 169 | /* Begin PBXVariantGroup section */ 170 | E80C7A9922B67BA800E76B68 /* LaunchScreen.storyboard */ = { 171 | isa = PBXVariantGroup; 172 | children = ( 173 | E80C7A9A22B67BA800E76B68 /* Base */, 174 | ); 175 | name = LaunchScreen.storyboard; 176 | sourceTree = ""; 177 | }; 178 | /* End PBXVariantGroup section */ 179 | 180 | /* Begin XCBuildConfiguration section */ 181 | E80C7A9D22B67BA800E76B68 /* Debug */ = { 182 | isa = XCBuildConfiguration; 183 | buildSettings = { 184 | ALWAYS_SEARCH_USER_PATHS = NO; 185 | CLANG_ANALYZER_NONNULL = YES; 186 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 187 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 188 | CLANG_CXX_LIBRARY = "libc++"; 189 | CLANG_ENABLE_MODULES = YES; 190 | CLANG_ENABLE_OBJC_ARC = YES; 191 | CLANG_ENABLE_OBJC_WEAK = YES; 192 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 193 | CLANG_WARN_BOOL_CONVERSION = YES; 194 | CLANG_WARN_COMMA = YES; 195 | CLANG_WARN_CONSTANT_CONVERSION = YES; 196 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 197 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 198 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 199 | CLANG_WARN_EMPTY_BODY = YES; 200 | CLANG_WARN_ENUM_CONVERSION = YES; 201 | CLANG_WARN_INFINITE_RECURSION = YES; 202 | CLANG_WARN_INT_CONVERSION = YES; 203 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 204 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 205 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 206 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 207 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 208 | CLANG_WARN_STRICT_PROTOTYPES = YES; 209 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 210 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 211 | CLANG_WARN_UNREACHABLE_CODE = YES; 212 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 213 | COPY_PHASE_STRIP = NO; 214 | DEBUG_INFORMATION_FORMAT = dwarf; 215 | ENABLE_STRICT_OBJC_MSGSEND = YES; 216 | ENABLE_TESTABILITY = YES; 217 | GCC_C_LANGUAGE_STANDARD = gnu11; 218 | GCC_DYNAMIC_NO_PIC = NO; 219 | GCC_NO_COMMON_BLOCKS = YES; 220 | GCC_OPTIMIZATION_LEVEL = 0; 221 | GCC_PREPROCESSOR_DEFINITIONS = ( 222 | "DEBUG=1", 223 | "$(inherited)", 224 | ); 225 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 226 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 227 | GCC_WARN_UNDECLARED_SELECTOR = YES; 228 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 229 | GCC_WARN_UNUSED_FUNCTION = YES; 230 | GCC_WARN_UNUSED_VARIABLE = YES; 231 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 232 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 233 | MTL_FAST_MATH = YES; 234 | ONLY_ACTIVE_ARCH = YES; 235 | SDKROOT = iphoneos; 236 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 237 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 238 | }; 239 | name = Debug; 240 | }; 241 | E80C7A9E22B67BA800E76B68 /* Release */ = { 242 | isa = XCBuildConfiguration; 243 | buildSettings = { 244 | ALWAYS_SEARCH_USER_PATHS = NO; 245 | CLANG_ANALYZER_NONNULL = YES; 246 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 247 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 248 | CLANG_CXX_LIBRARY = "libc++"; 249 | CLANG_ENABLE_MODULES = YES; 250 | CLANG_ENABLE_OBJC_ARC = YES; 251 | CLANG_ENABLE_OBJC_WEAK = YES; 252 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 253 | CLANG_WARN_BOOL_CONVERSION = YES; 254 | CLANG_WARN_COMMA = YES; 255 | CLANG_WARN_CONSTANT_CONVERSION = YES; 256 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 257 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 258 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 259 | CLANG_WARN_EMPTY_BODY = YES; 260 | CLANG_WARN_ENUM_CONVERSION = YES; 261 | CLANG_WARN_INFINITE_RECURSION = YES; 262 | CLANG_WARN_INT_CONVERSION = YES; 263 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 264 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 265 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 266 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 267 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 268 | CLANG_WARN_STRICT_PROTOTYPES = YES; 269 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 270 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 271 | CLANG_WARN_UNREACHABLE_CODE = YES; 272 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 273 | COPY_PHASE_STRIP = NO; 274 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 275 | ENABLE_NS_ASSERTIONS = NO; 276 | ENABLE_STRICT_OBJC_MSGSEND = YES; 277 | GCC_C_LANGUAGE_STANDARD = gnu11; 278 | GCC_NO_COMMON_BLOCKS = YES; 279 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 280 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 281 | GCC_WARN_UNDECLARED_SELECTOR = YES; 282 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 283 | GCC_WARN_UNUSED_FUNCTION = YES; 284 | GCC_WARN_UNUSED_VARIABLE = YES; 285 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 286 | MTL_ENABLE_DEBUG_INFO = NO; 287 | MTL_FAST_MATH = YES; 288 | SDKROOT = iphoneos; 289 | SWIFT_COMPILATION_MODE = wholemodule; 290 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 291 | VALIDATE_PRODUCT = YES; 292 | }; 293 | name = Release; 294 | }; 295 | E80C7AA022B67BA800E76B68 /* Debug */ = { 296 | isa = XCBuildConfiguration; 297 | buildSettings = { 298 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 299 | CODE_SIGN_IDENTITY = "iPhone Developer"; 300 | CODE_SIGN_STYLE = Manual; 301 | DEVELOPMENT_ASSET_PATHS = "TextRecognizerSwiftUI/Preview\\ Content"; 302 | DEVELOPMENT_TEAM = UAM22JDBB2; 303 | ENABLE_PREVIEWS = YES; 304 | INFOPLIST_FILE = TextRecognizerSwiftUI/Info.plist; 305 | LD_RUNPATH_SEARCH_PATHS = ( 306 | "$(inherited)", 307 | "@executable_path/Frameworks", 308 | ); 309 | PRODUCT_BUNDLE_IDENTIFIER = com.mitrevski.TextRecognizerSwiftUI; 310 | PRODUCT_NAME = "$(TARGET_NAME)"; 311 | PROVISIONING_PROFILE_SPECIFIER = MartinGenericProfile; 312 | SWIFT_VERSION = 5.0; 313 | TARGETED_DEVICE_FAMILY = "1,2"; 314 | }; 315 | name = Debug; 316 | }; 317 | E80C7AA122B67BA800E76B68 /* Release */ = { 318 | isa = XCBuildConfiguration; 319 | buildSettings = { 320 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 321 | CODE_SIGN_IDENTITY = "iPhone Developer"; 322 | CODE_SIGN_STYLE = Manual; 323 | DEVELOPMENT_ASSET_PATHS = "TextRecognizerSwiftUI/Preview\\ Content"; 324 | DEVELOPMENT_TEAM = UAM22JDBB2; 325 | ENABLE_PREVIEWS = YES; 326 | INFOPLIST_FILE = TextRecognizerSwiftUI/Info.plist; 327 | LD_RUNPATH_SEARCH_PATHS = ( 328 | "$(inherited)", 329 | "@executable_path/Frameworks", 330 | ); 331 | PRODUCT_BUNDLE_IDENTIFIER = com.mitrevski.TextRecognizerSwiftUI; 332 | PRODUCT_NAME = "$(TARGET_NAME)"; 333 | PROVISIONING_PROFILE_SPECIFIER = MartinGenericProfile; 334 | SWIFT_VERSION = 5.0; 335 | TARGETED_DEVICE_FAMILY = "1,2"; 336 | }; 337 | name = Release; 338 | }; 339 | /* End XCBuildConfiguration section */ 340 | 341 | /* Begin XCConfigurationList section */ 342 | E80C7A8622B67BA700E76B68 /* Build configuration list for PBXProject "TextRecognizerSwiftUI" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | E80C7A9D22B67BA800E76B68 /* Debug */, 346 | E80C7A9E22B67BA800E76B68 /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | E80C7A9F22B67BA800E76B68 /* Build configuration list for PBXNativeTarget "TextRecognizerSwiftUI" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | E80C7AA022B67BA800E76B68 /* Debug */, 355 | E80C7AA122B67BA800E76B68 /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | /* End XCConfigurationList section */ 361 | }; 362 | rootObject = E80C7A8322B67BA700E76B68 /* Project object */; 363 | } 364 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI.xcodeproj/project.xcworkspace/xcuserdata/mmitrevs.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinmitrevski/TextRecognizerSwiftUI/f1d048b78ad22ce11582dc2c013ae7cd8b042dbb/TextRecognizerSwiftUI.xcodeproj/project.xcworkspace/xcuserdata/mmitrevs.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /TextRecognizerSwiftUI.xcodeproj/xcuserdata/mmitrevs.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI.xcodeproj/xcuserdata/mmitrevs.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TextRecognizerSwiftUI.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // TextRecognizerSwiftUI 4 | // 5 | // Created by Martin Mitrevski on 16.06.19. 6 | // Copyright © 2019 Mitrevski. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 15 | // Override point for customization after application launch. 16 | return true 17 | } 18 | 19 | func applicationWillTerminate(_ application: UIApplication) { 20 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 21 | } 22 | 23 | // MARK: UISceneSession Lifecycle 24 | 25 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 26 | // Called when a new scene session is being created. 27 | // Use this method to select a configuration to create the new scene with. 28 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 29 | } 30 | 31 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 32 | // Called when the user discards a scene session. 33 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 34 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 35 | } 36 | 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // TextRecognizerSwiftUI 4 | // 5 | // Created by Martin Mitrevski on 16.06.19. 6 | // Copyright © 2019 Mitrevski. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | struct ContentView : View { 12 | 13 | @ObservedObject var recognizedText: RecognizedText = RecognizedText() 14 | 15 | var body: some View { 16 | NavigationView { 17 | VStack { 18 | Text(recognizedText.value) 19 | .lineLimit(nil) 20 | Spacer() 21 | NavigationLink(destination: ScanningView(recognizedText: $recognizedText.value)) { 22 | Text("Scan document") 23 | } 24 | } 25 | } 26 | } 27 | } 28 | 29 | #if DEBUG 30 | struct ContentView_Previews : PreviewProvider { 31 | static var previews: some View { 32 | ContentView() 33 | } 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSCameraUsageDescription 6 | Camera access is required to scan documents. 7 | CFBundleDevelopmentRegion 8 | $(DEVELOPMENT_LANGUAGE) 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIApplicationSceneManifest 26 | 27 | UIApplicationSupportsMultipleScenes 28 | 29 | UISceneConfigurations 30 | 31 | UIWindowSceneSessionRoleApplication 32 | 33 | 34 | UILaunchStoryboardName 35 | LaunchScreen 36 | UISceneConfigurationName 37 | Default Configuration 38 | UISceneDelegateClassName 39 | $(PRODUCT_MODULE_NAME).SceneDelegate 40 | 41 | 42 | 43 | 44 | UILaunchStoryboardName 45 | LaunchScreen 46 | UIRequiredDeviceCapabilities 47 | 48 | armv7 49 | 50 | UISupportedInterfaceOrientations 51 | 52 | UIInterfaceOrientationPortrait 53 | UIInterfaceOrientationLandscapeLeft 54 | UIInterfaceOrientationLandscapeRight 55 | 56 | UISupportedInterfaceOrientations~ipad 57 | 58 | UIInterfaceOrientationPortrait 59 | UIInterfaceOrientationPortraitUpsideDown 60 | UIInterfaceOrientationLandscapeLeft 61 | UIInterfaceOrientationLandscapeRight 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/RecongizedText.swift: -------------------------------------------------------------------------------- 1 | // Created by Martin Mitrevski on 16.06.19. 2 | // Copyright © 2019 Mitrevski. All rights reserved. 3 | // 4 | 5 | import Combine 6 | import SwiftUI 7 | 8 | final class RecognizedText: ObservableObject, Identifiable { 9 | 10 | let willChange = PassthroughSubject() 11 | 12 | var value: String = "Scan document to see its contents" { 13 | willSet { 14 | willChange.send(self) 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/ScanningView.swift: -------------------------------------------------------------------------------- 1 | // Created by Martin Mitrevski on 15.06.19. 2 | // Copyright © 2019 Mitrevski. All rights reserved. 3 | // 4 | 5 | import SwiftUI 6 | import UIKit 7 | import VisionKit 8 | import Combine 9 | 10 | struct ScanningView: UIViewControllerRepresentable { 11 | 12 | @Binding var recognizedText: String 13 | 14 | typealias UIViewControllerType = VNDocumentCameraViewController 15 | 16 | func makeCoordinator() -> Coordinator { 17 | return Coordinator(recognizedText: $recognizedText) 18 | } 19 | 20 | func makeUIViewController(context: UIViewControllerRepresentableContext) -> VNDocumentCameraViewController { 21 | let documentCameraViewController = VNDocumentCameraViewController() 22 | documentCameraViewController.delegate = context.coordinator 23 | return documentCameraViewController 24 | } 25 | 26 | func updateUIViewController(_ uiViewController: VNDocumentCameraViewController, context: UIViewControllerRepresentableContext) { 27 | 28 | } 29 | 30 | class Coordinator: NSObject, VNDocumentCameraViewControllerDelegate { 31 | 32 | var recognizedText: Binding 33 | private let textRecognizer: TextRecognizer 34 | 35 | init(recognizedText: Binding) { 36 | self.recognizedText = recognizedText 37 | textRecognizer = TextRecognizer(recognizedText: recognizedText) 38 | } 39 | 40 | public func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) { 41 | var images = [CGImage]() 42 | for pageIndex in 0 ..< scan.pageCount { 43 | let image = scan.imageOfPage(at: pageIndex) 44 | if let cgImage = image.cgImage { 45 | images.append(cgImage) 46 | } 47 | } 48 | textRecognizer.recognizeText(from: images) 49 | controller.navigationController?.popViewController(animated: true) 50 | } 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // TextRecognizerSwiftUI 4 | // 5 | // Created by Martin Mitrevski on 16.06.19. 6 | // Copyright © 2019 Mitrevski. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 17 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 18 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 19 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 20 | 21 | // Use a UIHostingController as window root view controller 22 | if let windowScene = scene as? UIWindowScene { 23 | let window = UIWindow(windowScene: windowScene) 24 | window.rootViewController = UIHostingController(rootView: ContentView()) 25 | self.window = window 26 | window.makeKeyAndVisible() 27 | } 28 | } 29 | 30 | func sceneDidDisconnect(_ scene: UIScene) { 31 | // Called as the scene is being released by the system. 32 | // This occurs shortly after the scene enters the background, or when its session is discarded. 33 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 34 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 35 | } 36 | 37 | func sceneDidBecomeActive(_ scene: UIScene) { 38 | // Called when the scene has moved from an inactive state to an active state. 39 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 40 | } 41 | 42 | func sceneWillResignActive(_ scene: UIScene) { 43 | // Called when the scene will move from an active state to an inactive state. 44 | // This may occur due to temporary interruptions (ex. an incoming phone call). 45 | } 46 | 47 | func sceneWillEnterForeground(_ scene: UIScene) { 48 | // Called as the scene transitions from the background to the foreground. 49 | // Use this method to undo the changes made on entering the background. 50 | } 51 | 52 | func sceneDidEnterBackground(_ scene: UIScene) { 53 | // Called as the scene transitions from the foreground to the background. 54 | // Use this method to save data, release shared resources, and store enough scene-specific state information 55 | // to restore the scene back to its current state. 56 | } 57 | 58 | 59 | } 60 | 61 | -------------------------------------------------------------------------------- /TextRecognizerSwiftUI/TextRecognizer.swift: -------------------------------------------------------------------------------- 1 | // Created by Martin Mitrevski on 15.06.19. 2 | 3 | import Vision 4 | import SwiftUI 5 | import Combine 6 | 7 | public struct TextRecognizer { 8 | 9 | @Binding var recognizedText: String 10 | 11 | private let textRecognitionWorkQueue = DispatchQueue(label: "TextRecognitionQueue", 12 | qos: .userInitiated, attributes: [], autoreleaseFrequency: .workItem) 13 | 14 | func recognizeText(from images: [CGImage]) { 15 | self.recognizedText = "" 16 | var tmp = "" 17 | let textRecognitionRequest = VNRecognizeTextRequest { (request, error) in 18 | guard let observations = request.results as? [VNRecognizedTextObservation] else { 19 | print("The observations are of an unexpected type.") 20 | return 21 | } 22 | // Concatenate the recognised text from all the observations. 23 | let maximumCandidates = 1 24 | for observation in observations { 25 | guard let candidate = observation.topCandidates(maximumCandidates).first else { continue } 26 | tmp += candidate.string + "\n" 27 | } 28 | } 29 | textRecognitionRequest.recognitionLevel = .accurate 30 | for image in images { 31 | let requestHandler = VNImageRequestHandler(cgImage: image, options: [:]) 32 | 33 | do { 34 | try requestHandler.perform([textRecognitionRequest]) 35 | } catch { 36 | print(error) 37 | } 38 | tmp += "\n\n" 39 | } 40 | self.recognizedText = tmp 41 | } 42 | 43 | } 44 | --------------------------------------------------------------------------------