├── LiveCameraSwiftUI.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── David.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── LiveCameraSwiftUI ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── ContentView.swift ├── FrameHandler.swift ├── FrameView.swift ├── LiveCameraSwiftUIApp.swift └── Preview Content │ └── Preview Assets.xcassets │ └── Contents.json └── README.md /LiveCameraSwiftUI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 55; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 6362F5F7287974D000286B4A /* LiveCameraSwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6362F5F6287974D000286B4A /* LiveCameraSwiftUIApp.swift */; }; 11 | 6362F5F9287974D000286B4A /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6362F5F8287974D000286B4A /* ContentView.swift */; }; 12 | 6362F5FB287974D000286B4A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6362F5FA287974D000286B4A /* Assets.xcassets */; }; 13 | 6362F5FE287974D000286B4A /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6362F5FD287974D000286B4A /* Preview Assets.xcassets */; }; 14 | 6362F6412879C49500286B4A /* FrameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6362F6402879C49500286B4A /* FrameView.swift */; }; 15 | 6362F6432879C76400286B4A /* FrameHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6362F6422879C76400286B4A /* FrameHandler.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 6362F5F3287974D000286B4A /* LiveCameraSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LiveCameraSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | 6362F5F6287974D000286B4A /* LiveCameraSwiftUIApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LiveCameraSwiftUIApp.swift; sourceTree = ""; }; 21 | 6362F5F8287974D000286B4A /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 22 | 6362F5FA287974D000286B4A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | 6362F5FD287974D000286B4A /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 24 | 6362F6402879C49500286B4A /* FrameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameView.swift; sourceTree = ""; }; 25 | 6362F6422879C76400286B4A /* FrameHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FrameHandler.swift; sourceTree = ""; }; 26 | /* End PBXFileReference section */ 27 | 28 | /* Begin PBXFrameworksBuildPhase section */ 29 | 6362F5F0287974D000286B4A /* Frameworks */ = { 30 | isa = PBXFrameworksBuildPhase; 31 | buildActionMask = 2147483647; 32 | files = ( 33 | ); 34 | runOnlyForDeploymentPostprocessing = 0; 35 | }; 36 | /* End PBXFrameworksBuildPhase section */ 37 | 38 | /* Begin PBXGroup section */ 39 | 6362F5EA287974D000286B4A = { 40 | isa = PBXGroup; 41 | children = ( 42 | 6362F5F5287974D000286B4A /* LiveCameraSwiftUI */, 43 | 6362F5F4287974D000286B4A /* Products */, 44 | ); 45 | sourceTree = ""; 46 | }; 47 | 6362F5F4287974D000286B4A /* Products */ = { 48 | isa = PBXGroup; 49 | children = ( 50 | 6362F5F3287974D000286B4A /* LiveCameraSwiftUI.app */, 51 | ); 52 | name = Products; 53 | sourceTree = ""; 54 | }; 55 | 6362F5F5287974D000286B4A /* LiveCameraSwiftUI */ = { 56 | isa = PBXGroup; 57 | children = ( 58 | 6362F5F6287974D000286B4A /* LiveCameraSwiftUIApp.swift */, 59 | 6362F5F8287974D000286B4A /* ContentView.swift */, 60 | 6362F6402879C49500286B4A /* FrameView.swift */, 61 | 6362F6422879C76400286B4A /* FrameHandler.swift */, 62 | 6362F5FA287974D000286B4A /* Assets.xcassets */, 63 | 6362F5FC287974D000286B4A /* Preview Content */, 64 | ); 65 | path = LiveCameraSwiftUI; 66 | sourceTree = ""; 67 | }; 68 | 6362F5FC287974D000286B4A /* Preview Content */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 6362F5FD287974D000286B4A /* Preview Assets.xcassets */, 72 | ); 73 | path = "Preview Content"; 74 | sourceTree = ""; 75 | }; 76 | /* End PBXGroup section */ 77 | 78 | /* Begin PBXNativeTarget section */ 79 | 6362F5F2287974D000286B4A /* LiveCameraSwiftUI */ = { 80 | isa = PBXNativeTarget; 81 | buildConfigurationList = 6362F601287974D000286B4A /* Build configuration list for PBXNativeTarget "LiveCameraSwiftUI" */; 82 | buildPhases = ( 83 | 6362F5EF287974D000286B4A /* Sources */, 84 | 6362F5F0287974D000286B4A /* Frameworks */, 85 | 6362F5F1287974D000286B4A /* Resources */, 86 | ); 87 | buildRules = ( 88 | ); 89 | dependencies = ( 90 | ); 91 | name = LiveCameraSwiftUI; 92 | productName = LiveCameraSwiftUI; 93 | productReference = 6362F5F3287974D000286B4A /* LiveCameraSwiftUI.app */; 94 | productType = "com.apple.product-type.application"; 95 | }; 96 | /* End PBXNativeTarget section */ 97 | 98 | /* Begin PBXProject section */ 99 | 6362F5EB287974D000286B4A /* Project object */ = { 100 | isa = PBXProject; 101 | attributes = { 102 | BuildIndependentTargetsInParallel = 1; 103 | LastSwiftUpdateCheck = 1340; 104 | LastUpgradeCheck = 1340; 105 | TargetAttributes = { 106 | 6362F5F2287974D000286B4A = { 107 | CreatedOnToolsVersion = 13.4.1; 108 | }; 109 | }; 110 | }; 111 | buildConfigurationList = 6362F5EE287974D000286B4A /* Build configuration list for PBXProject "LiveCameraSwiftUI" */; 112 | compatibilityVersion = "Xcode 13.0"; 113 | developmentRegion = en; 114 | hasScannedForEncodings = 0; 115 | knownRegions = ( 116 | en, 117 | Base, 118 | ); 119 | mainGroup = 6362F5EA287974D000286B4A; 120 | productRefGroup = 6362F5F4287974D000286B4A /* Products */; 121 | projectDirPath = ""; 122 | projectRoot = ""; 123 | targets = ( 124 | 6362F5F2287974D000286B4A /* LiveCameraSwiftUI */, 125 | ); 126 | }; 127 | /* End PBXProject section */ 128 | 129 | /* Begin PBXResourcesBuildPhase section */ 130 | 6362F5F1287974D000286B4A /* Resources */ = { 131 | isa = PBXResourcesBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | 6362F5FE287974D000286B4A /* Preview Assets.xcassets in Resources */, 135 | 6362F5FB287974D000286B4A /* Assets.xcassets in Resources */, 136 | ); 137 | runOnlyForDeploymentPostprocessing = 0; 138 | }; 139 | /* End PBXResourcesBuildPhase section */ 140 | 141 | /* Begin PBXSourcesBuildPhase section */ 142 | 6362F5EF287974D000286B4A /* Sources */ = { 143 | isa = PBXSourcesBuildPhase; 144 | buildActionMask = 2147483647; 145 | files = ( 146 | 6362F6412879C49500286B4A /* FrameView.swift in Sources */, 147 | 6362F5F9287974D000286B4A /* ContentView.swift in Sources */, 148 | 6362F6432879C76400286B4A /* FrameHandler.swift in Sources */, 149 | 6362F5F7287974D000286B4A /* LiveCameraSwiftUIApp.swift in Sources */, 150 | ); 151 | runOnlyForDeploymentPostprocessing = 0; 152 | }; 153 | /* End PBXSourcesBuildPhase section */ 154 | 155 | /* Begin XCBuildConfiguration section */ 156 | 6362F5FF287974D000286B4A /* Debug */ = { 157 | isa = XCBuildConfiguration; 158 | buildSettings = { 159 | ALWAYS_SEARCH_USER_PATHS = NO; 160 | CLANG_ANALYZER_NONNULL = YES; 161 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 162 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 163 | CLANG_ENABLE_MODULES = YES; 164 | CLANG_ENABLE_OBJC_ARC = YES; 165 | CLANG_ENABLE_OBJC_WEAK = YES; 166 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 167 | CLANG_WARN_BOOL_CONVERSION = YES; 168 | CLANG_WARN_COMMA = YES; 169 | CLANG_WARN_CONSTANT_CONVERSION = YES; 170 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 171 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 172 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 173 | CLANG_WARN_EMPTY_BODY = YES; 174 | CLANG_WARN_ENUM_CONVERSION = YES; 175 | CLANG_WARN_INFINITE_RECURSION = YES; 176 | CLANG_WARN_INT_CONVERSION = YES; 177 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 178 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 179 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 180 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 181 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 182 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 183 | CLANG_WARN_STRICT_PROTOTYPES = YES; 184 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 185 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 186 | CLANG_WARN_UNREACHABLE_CODE = YES; 187 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 188 | COPY_PHASE_STRIP = NO; 189 | DEBUG_INFORMATION_FORMAT = dwarf; 190 | ENABLE_STRICT_OBJC_MSGSEND = YES; 191 | ENABLE_TESTABILITY = YES; 192 | GCC_C_LANGUAGE_STANDARD = gnu11; 193 | GCC_DYNAMIC_NO_PIC = NO; 194 | GCC_NO_COMMON_BLOCKS = YES; 195 | GCC_OPTIMIZATION_LEVEL = 0; 196 | GCC_PREPROCESSOR_DEFINITIONS = ( 197 | "DEBUG=1", 198 | "$(inherited)", 199 | ); 200 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 201 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 202 | GCC_WARN_UNDECLARED_SELECTOR = YES; 203 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 204 | GCC_WARN_UNUSED_FUNCTION = YES; 205 | GCC_WARN_UNUSED_VARIABLE = YES; 206 | IPHONEOS_DEPLOYMENT_TARGET = 15.5; 207 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 208 | MTL_FAST_MATH = YES; 209 | ONLY_ACTIVE_ARCH = YES; 210 | SDKROOT = iphoneos; 211 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 212 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 213 | }; 214 | name = Debug; 215 | }; 216 | 6362F600287974D000286B4A /* Release */ = { 217 | isa = XCBuildConfiguration; 218 | buildSettings = { 219 | ALWAYS_SEARCH_USER_PATHS = NO; 220 | CLANG_ANALYZER_NONNULL = YES; 221 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 222 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++17"; 223 | CLANG_ENABLE_MODULES = YES; 224 | CLANG_ENABLE_OBJC_ARC = YES; 225 | CLANG_ENABLE_OBJC_WEAK = YES; 226 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 227 | CLANG_WARN_BOOL_CONVERSION = YES; 228 | CLANG_WARN_COMMA = YES; 229 | CLANG_WARN_CONSTANT_CONVERSION = YES; 230 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 231 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 232 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 233 | CLANG_WARN_EMPTY_BODY = YES; 234 | CLANG_WARN_ENUM_CONVERSION = YES; 235 | CLANG_WARN_INFINITE_RECURSION = YES; 236 | CLANG_WARN_INT_CONVERSION = YES; 237 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 238 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 239 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 241 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 242 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 243 | CLANG_WARN_STRICT_PROTOTYPES = YES; 244 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 245 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 246 | CLANG_WARN_UNREACHABLE_CODE = YES; 247 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 248 | COPY_PHASE_STRIP = NO; 249 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 250 | ENABLE_NS_ASSERTIONS = NO; 251 | ENABLE_STRICT_OBJC_MSGSEND = YES; 252 | GCC_C_LANGUAGE_STANDARD = gnu11; 253 | GCC_NO_COMMON_BLOCKS = YES; 254 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 255 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 256 | GCC_WARN_UNDECLARED_SELECTOR = YES; 257 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 258 | GCC_WARN_UNUSED_FUNCTION = YES; 259 | GCC_WARN_UNUSED_VARIABLE = YES; 260 | IPHONEOS_DEPLOYMENT_TARGET = 15.5; 261 | MTL_ENABLE_DEBUG_INFO = NO; 262 | MTL_FAST_MATH = YES; 263 | SDKROOT = iphoneos; 264 | SWIFT_COMPILATION_MODE = wholemodule; 265 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 266 | VALIDATE_PRODUCT = YES; 267 | }; 268 | name = Release; 269 | }; 270 | 6362F602287974D000286B4A /* Debug */ = { 271 | isa = XCBuildConfiguration; 272 | buildSettings = { 273 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 274 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 275 | CODE_SIGN_IDENTITY = "Apple Development"; 276 | CODE_SIGN_STYLE = Manual; 277 | CURRENT_PROJECT_VERSION = 1; 278 | DEVELOPMENT_ASSET_PATHS = "\"LiveCameraSwiftUI/Preview Content\""; 279 | DEVELOPMENT_TEAM = ""; 280 | ENABLE_PREVIEWS = YES; 281 | GENERATE_INFOPLIST_FILE = YES; 282 | INFOPLIST_KEY_NSCameraUsageDescription = "Camera required for preview"; 283 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 284 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 285 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 286 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 287 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 288 | LD_RUNPATH_SEARCH_PATHS = ( 289 | "$(inherited)", 290 | "@executable_path/Frameworks", 291 | ); 292 | MARKETING_VERSION = 1.0; 293 | PRODUCT_NAME = "$(TARGET_NAME)"; 294 | PROVISIONING_PROFILE_SPECIFIER = ""; 295 | SWIFT_EMIT_LOC_STRINGS = YES; 296 | SWIFT_VERSION = 5.0; 297 | TARGETED_DEVICE_FAMILY = "1,2"; 298 | }; 299 | name = Debug; 300 | }; 301 | 6362F603287974D000286B4A /* Release */ = { 302 | isa = XCBuildConfiguration; 303 | buildSettings = { 304 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 305 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 306 | CODE_SIGN_IDENTITY = "Apple Development"; 307 | CODE_SIGN_STYLE = Manual; 308 | CURRENT_PROJECT_VERSION = 1; 309 | DEVELOPMENT_ASSET_PATHS = "\"LiveCameraSwiftUI/Preview Content\""; 310 | DEVELOPMENT_TEAM = ""; 311 | ENABLE_PREVIEWS = YES; 312 | GENERATE_INFOPLIST_FILE = YES; 313 | INFOPLIST_KEY_NSCameraUsageDescription = "Camera required for preview"; 314 | INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; 315 | INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; 316 | INFOPLIST_KEY_UILaunchScreen_Generation = YES; 317 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 318 | INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; 319 | LD_RUNPATH_SEARCH_PATHS = ( 320 | "$(inherited)", 321 | "@executable_path/Frameworks", 322 | ); 323 | MARKETING_VERSION = 1.0; 324 | PRODUCT_NAME = "$(TARGET_NAME)"; 325 | PROVISIONING_PROFILE_SPECIFIER = ""; 326 | SWIFT_EMIT_LOC_STRINGS = YES; 327 | SWIFT_VERSION = 5.0; 328 | TARGETED_DEVICE_FAMILY = "1,2"; 329 | }; 330 | name = Release; 331 | }; 332 | /* End XCBuildConfiguration section */ 333 | 334 | /* Begin XCConfigurationList section */ 335 | 6362F5EE287974D000286B4A /* Build configuration list for PBXProject "LiveCameraSwiftUI" */ = { 336 | isa = XCConfigurationList; 337 | buildConfigurations = ( 338 | 6362F5FF287974D000286B4A /* Debug */, 339 | 6362F600287974D000286B4A /* Release */, 340 | ); 341 | defaultConfigurationIsVisible = 0; 342 | defaultConfigurationName = Release; 343 | }; 344 | 6362F601287974D000286B4A /* Build configuration list for PBXNativeTarget "LiveCameraSwiftUI" */ = { 345 | isa = XCConfigurationList; 346 | buildConfigurations = ( 347 | 6362F602287974D000286B4A /* Debug */, 348 | 6362F603287974D000286B4A /* Release */, 349 | ); 350 | defaultConfigurationIsVisible = 0; 351 | defaultConfigurationName = Release; 352 | }; 353 | /* End XCConfigurationList section */ 354 | }; 355 | rootObject = 6362F5EB287974D000286B4A /* Project object */; 356 | } 357 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI.xcodeproj/xcuserdata/David.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LiveCameraSwiftUI.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/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 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/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" : "2x", 76 | "size" : "76x76" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "scale" : "2x", 81 | "size" : "83.5x83.5" 82 | }, 83 | { 84 | "idiom" : "ios-marketing", 85 | "scale" : "1x", 86 | "size" : "1024x1024" 87 | } 88 | ], 89 | "info" : { 90 | "author" : "xcode", 91 | "version" : 1 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/ContentView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct ContentView: View { 4 | @StateObject private var model = FrameHandler() 5 | 6 | var body: some View { 7 | FrameView(image: model.frame) 8 | .ignoresSafeArea() 9 | } 10 | } 11 | 12 | struct ContentView_Previews: PreviewProvider { 13 | static var previews: some View { 14 | ContentView() 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/FrameHandler.swift: -------------------------------------------------------------------------------- 1 | import AVFoundation 2 | import CoreImage 3 | 4 | class FrameHandler: NSObject, ObservableObject { 5 | @Published var frame: CGImage? 6 | private var permissionGranted = true 7 | private let captureSession = AVCaptureSession() 8 | private let sessionQueue = DispatchQueue(label: "sessionQueue") 9 | private let context = CIContext() 10 | 11 | 12 | override init() { 13 | super.init() 14 | self.checkPermission() 15 | sessionQueue.async { [unowned self] in 16 | self.setupCaptureSession() 17 | self.captureSession.startRunning() 18 | } 19 | } 20 | 21 | func checkPermission() { 22 | switch AVCaptureDevice.authorizationStatus(for: .video) { 23 | case .authorized: // The user has previously granted access to the camera. 24 | self.permissionGranted = true 25 | 26 | case .notDetermined: // The user has not yet been asked for camera access. 27 | self.requestPermission() 28 | 29 | // Combine the two other cases into the default case 30 | default: 31 | self.permissionGranted = false 32 | } 33 | } 34 | 35 | func requestPermission() { 36 | // Strong reference not a problem here but might become one in the future. 37 | AVCaptureDevice.requestAccess(for: .video) { [unowned self] granted in 38 | self.permissionGranted = granted 39 | } 40 | } 41 | 42 | func setupCaptureSession() { 43 | let videoOutput = AVCaptureVideoDataOutput() 44 | 45 | guard permissionGranted else { return } 46 | guard let videoDevice = AVCaptureDevice.default(.builtInDualWideCamera,for: .video, position: .back) else { return } 47 | guard let videoDeviceInput = try? AVCaptureDeviceInput(device: videoDevice) else { return } 48 | guard captureSession.canAddInput(videoDeviceInput) else { return } 49 | captureSession.addInput(videoDeviceInput) 50 | 51 | videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue(label: "sampleBufferQueue")) 52 | captureSession.addOutput(videoOutput) 53 | 54 | videoOutput.connection(with: .video)?.videoOrientation = .portrait 55 | } 56 | } 57 | 58 | 59 | extension FrameHandler: AVCaptureVideoDataOutputSampleBufferDelegate { 60 | func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { 61 | guard let cgImage = imageFromSampleBuffer(sampleBuffer: sampleBuffer) else { return } 62 | 63 | // All UI updates should be/ must be performed on the main queue. 64 | DispatchQueue.main.async { [unowned self] in 65 | self.frame = cgImage 66 | } 67 | } 68 | 69 | private func imageFromSampleBuffer(sampleBuffer: CMSampleBuffer) -> CGImage? { 70 | guard let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else { return nil } 71 | let ciImage = CIImage(cvPixelBuffer: imageBuffer) 72 | guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else { return nil } 73 | 74 | return cgImage 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/FrameView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | struct FrameView: View { 4 | var image: CGImage? 5 | private let label = Text("frame") 6 | 7 | var body: some View { 8 | if let image = image { 9 | Image(image, scale: 1.0, orientation: .up, label: label) 10 | } else { 11 | Color.black 12 | } 13 | } 14 | } 15 | 16 | struct FrameView_Previews: PreviewProvider { 17 | static var previews: some View { 18 | FrameView() 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/LiveCameraSwiftUIApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct LiveCameraSwiftUIApp: App { 5 | var body: some Scene { 6 | WindowGroup { 7 | ContentView() 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /LiveCameraSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Live Camera SwiftUI 2 | 3 | **Please note:** This repo is not maintained. 4 | 5 | Code from the [video](https://www.youtube.com/watch?v=cLnw5z8ZGqM&t=22s) which shows how to read frames from a phone's camera and display the feed on the screen using SwiftUI, without UIKit. 6 | 7 | ## Updates 8 | 9 | 29/07/2023 10 | 11 | - Changed default value for `permissionGranted` in `FrameHandler` to `true` to prevent a bug when the user runs the app the first time 12 | - Added `self` to some method calls and variables in `FrameHandler` to make code consistent 13 | --------------------------------------------------------------------------------