├── .gitignore ├── CoreMLwithSwiftUI.xcodeproj ├── project.pbxproj └── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── CoreMLwithSwiftUI ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── lemon.imageset │ │ ├── Contents.json │ │ └── lemon.jpg │ ├── pineapple.imageset │ │ ├── Contents.json │ │ └── pineapple.jpg │ └── strawberry.imageset │ │ ├── Contents.json │ │ └── strawberry.jpg ├── ContentView.swift ├── CoreMLwithSwiftUIApp.swift ├── Info.plist ├── MobileNetV2.mlmodel ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json └── UIImage+Extension.swift ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | # 51 | # Add this line if you want to avoid checking in source code from the Xcode workspace 52 | # *.xcworkspace 53 | 54 | # Carthage 55 | # 56 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 57 | # Carthage/Checkouts 58 | 59 | Carthage/Build 60 | 61 | # fastlane 62 | # 63 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 64 | # screenshots whenever they are needed. 65 | # For more information about the recommended setup visit: 66 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 67 | 68 | fastlane/report.xml 69 | fastlane/Preview.html 70 | fastlane/screenshots/**/*.png 71 | fastlane/test_output 72 | 73 | # Code Injection 74 | # 75 | # After new code Injection tools there's a generated folder /iOSInjectionProject 76 | # https://github.com/johnno1962/injectionforxcode 77 | 78 | iOSInjectionProject/ 79 | 80 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A9939458265BCD8900D7B90F /* CoreMLwithSwiftUIApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9939457265BCD8900D7B90F /* CoreMLwithSwiftUIApp.swift */; }; 11 | A993945A265BCD8900D7B90F /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9939459265BCD8900D7B90F /* ContentView.swift */; }; 12 | A993945C265BCD8B00D7B90F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A993945B265BCD8B00D7B90F /* Assets.xcassets */; }; 13 | A993945F265BCD8B00D7B90F /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A993945E265BCD8B00D7B90F /* Preview Assets.xcassets */; }; 14 | A9939467265BCF2100D7B90F /* MobileNetV2.mlmodel in Sources */ = {isa = PBXBuildFile; fileRef = A9939466265BCF2000D7B90F /* MobileNetV2.mlmodel */; }; 15 | A9939469265BD2A400D7B90F /* UIImage+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9939468265BD2A400D7B90F /* UIImage+Extension.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | A9939454265BCD8900D7B90F /* CoreMLwithSwiftUI.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CoreMLwithSwiftUI.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | A9939457265BCD8900D7B90F /* CoreMLwithSwiftUIApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreMLwithSwiftUIApp.swift; sourceTree = ""; }; 21 | A9939459265BCD8900D7B90F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 22 | A993945B265BCD8B00D7B90F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 23 | A993945E265BCD8B00D7B90F /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 24 | A9939460265BCD8B00D7B90F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 25 | A9939466265BCF2000D7B90F /* MobileNetV2.mlmodel */ = {isa = PBXFileReference; lastKnownFileType = file.mlmodel; path = MobileNetV2.mlmodel; sourceTree = ""; }; 26 | A9939468265BD2A400D7B90F /* UIImage+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Extension.swift"; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | A9939451265BCD8900D7B90F /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | A993944B265BCD8900D7B90F = { 41 | isa = PBXGroup; 42 | children = ( 43 | A9939456265BCD8900D7B90F /* CoreMLwithSwiftUI */, 44 | A9939455265BCD8900D7B90F /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | A9939455265BCD8900D7B90F /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | A9939454265BCD8900D7B90F /* CoreMLwithSwiftUI.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | A9939456265BCD8900D7B90F /* CoreMLwithSwiftUI */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | A9939457265BCD8900D7B90F /* CoreMLwithSwiftUIApp.swift */, 60 | A9939468265BD2A400D7B90F /* UIImage+Extension.swift */, 61 | A9939459265BCD8900D7B90F /* ContentView.swift */, 62 | A9939466265BCF2000D7B90F /* MobileNetV2.mlmodel */, 63 | A993945B265BCD8B00D7B90F /* Assets.xcassets */, 64 | A9939460265BCD8B00D7B90F /* Info.plist */, 65 | A993945D265BCD8B00D7B90F /* Preview Content */, 66 | ); 67 | path = CoreMLwithSwiftUI; 68 | sourceTree = ""; 69 | }; 70 | A993945D265BCD8B00D7B90F /* Preview Content */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | A993945E265BCD8B00D7B90F /* Preview Assets.xcassets */, 74 | ); 75 | path = "Preview Content"; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | A9939453265BCD8900D7B90F /* CoreMLwithSwiftUI */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = A9939463265BCD8B00D7B90F /* Build configuration list for PBXNativeTarget "CoreMLwithSwiftUI" */; 84 | buildPhases = ( 85 | A9939450265BCD8900D7B90F /* Sources */, 86 | A9939451265BCD8900D7B90F /* Frameworks */, 87 | A9939452265BCD8900D7B90F /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = CoreMLwithSwiftUI; 94 | productName = CoreMLwithSwiftUI; 95 | productReference = A9939454265BCD8900D7B90F /* CoreMLwithSwiftUI.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | A993944C265BCD8900D7B90F /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastSwiftUpdateCheck = 1250; 105 | LastUpgradeCheck = 1250; 106 | TargetAttributes = { 107 | A9939453265BCD8900D7B90F = { 108 | CreatedOnToolsVersion = 12.5; 109 | }; 110 | }; 111 | }; 112 | buildConfigurationList = A993944F265BCD8900D7B90F /* Build configuration list for PBXProject "CoreMLwithSwiftUI" */; 113 | compatibilityVersion = "Xcode 9.3"; 114 | developmentRegion = en; 115 | hasScannedForEncodings = 0; 116 | knownRegions = ( 117 | en, 118 | Base, 119 | ); 120 | mainGroup = A993944B265BCD8900D7B90F; 121 | productRefGroup = A9939455265BCD8900D7B90F /* Products */; 122 | projectDirPath = ""; 123 | projectRoot = ""; 124 | targets = ( 125 | A9939453265BCD8900D7B90F /* CoreMLwithSwiftUI */, 126 | ); 127 | }; 128 | /* End PBXProject section */ 129 | 130 | /* Begin PBXResourcesBuildPhase section */ 131 | A9939452265BCD8900D7B90F /* Resources */ = { 132 | isa = PBXResourcesBuildPhase; 133 | buildActionMask = 2147483647; 134 | files = ( 135 | A993945F265BCD8B00D7B90F /* Preview Assets.xcassets in Resources */, 136 | A993945C265BCD8B00D7B90F /* Assets.xcassets in Resources */, 137 | ); 138 | runOnlyForDeploymentPostprocessing = 0; 139 | }; 140 | /* End PBXResourcesBuildPhase section */ 141 | 142 | /* Begin PBXSourcesBuildPhase section */ 143 | A9939450265BCD8900D7B90F /* Sources */ = { 144 | isa = PBXSourcesBuildPhase; 145 | buildActionMask = 2147483647; 146 | files = ( 147 | A9939467265BCF2100D7B90F /* MobileNetV2.mlmodel in Sources */, 148 | A993945A265BCD8900D7B90F /* ContentView.swift in Sources */, 149 | A9939458265BCD8900D7B90F /* CoreMLwithSwiftUIApp.swift in Sources */, 150 | A9939469265BD2A400D7B90F /* UIImage+Extension.swift in Sources */, 151 | ); 152 | runOnlyForDeploymentPostprocessing = 0; 153 | }; 154 | /* End PBXSourcesBuildPhase section */ 155 | 156 | /* Begin XCBuildConfiguration section */ 157 | A9939461265BCD8B00D7B90F /* Debug */ = { 158 | isa = XCBuildConfiguration; 159 | buildSettings = { 160 | ALWAYS_SEARCH_USER_PATHS = NO; 161 | CLANG_ANALYZER_NONNULL = YES; 162 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 163 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 164 | CLANG_CXX_LIBRARY = "libc++"; 165 | CLANG_ENABLE_MODULES = YES; 166 | CLANG_ENABLE_OBJC_ARC = YES; 167 | CLANG_ENABLE_OBJC_WEAK = YES; 168 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 169 | CLANG_WARN_BOOL_CONVERSION = YES; 170 | CLANG_WARN_COMMA = YES; 171 | CLANG_WARN_CONSTANT_CONVERSION = YES; 172 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 173 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 174 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 175 | CLANG_WARN_EMPTY_BODY = YES; 176 | CLANG_WARN_ENUM_CONVERSION = YES; 177 | CLANG_WARN_INFINITE_RECURSION = YES; 178 | CLANG_WARN_INT_CONVERSION = YES; 179 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 180 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 181 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 182 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 183 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 184 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 185 | CLANG_WARN_STRICT_PROTOTYPES = YES; 186 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 187 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 188 | CLANG_WARN_UNREACHABLE_CODE = YES; 189 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 190 | COPY_PHASE_STRIP = NO; 191 | DEBUG_INFORMATION_FORMAT = dwarf; 192 | ENABLE_STRICT_OBJC_MSGSEND = YES; 193 | ENABLE_TESTABILITY = YES; 194 | GCC_C_LANGUAGE_STANDARD = gnu11; 195 | GCC_DYNAMIC_NO_PIC = NO; 196 | GCC_NO_COMMON_BLOCKS = YES; 197 | GCC_OPTIMIZATION_LEVEL = 0; 198 | GCC_PREPROCESSOR_DEFINITIONS = ( 199 | "DEBUG=1", 200 | "$(inherited)", 201 | ); 202 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 203 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 204 | GCC_WARN_UNDECLARED_SELECTOR = YES; 205 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 206 | GCC_WARN_UNUSED_FUNCTION = YES; 207 | GCC_WARN_UNUSED_VARIABLE = YES; 208 | IPHONEOS_DEPLOYMENT_TARGET = 14.5; 209 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 210 | MTL_FAST_MATH = YES; 211 | ONLY_ACTIVE_ARCH = YES; 212 | SDKROOT = iphoneos; 213 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 214 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 215 | }; 216 | name = Debug; 217 | }; 218 | A9939462265BCD8B00D7B90F /* Release */ = { 219 | isa = XCBuildConfiguration; 220 | buildSettings = { 221 | ALWAYS_SEARCH_USER_PATHS = NO; 222 | CLANG_ANALYZER_NONNULL = YES; 223 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 224 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 225 | CLANG_CXX_LIBRARY = "libc++"; 226 | CLANG_ENABLE_MODULES = YES; 227 | CLANG_ENABLE_OBJC_ARC = YES; 228 | CLANG_ENABLE_OBJC_WEAK = YES; 229 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 230 | CLANG_WARN_BOOL_CONVERSION = YES; 231 | CLANG_WARN_COMMA = YES; 232 | CLANG_WARN_CONSTANT_CONVERSION = YES; 233 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 234 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 235 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 236 | CLANG_WARN_EMPTY_BODY = YES; 237 | CLANG_WARN_ENUM_CONVERSION = YES; 238 | CLANG_WARN_INFINITE_RECURSION = YES; 239 | CLANG_WARN_INT_CONVERSION = YES; 240 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 241 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 242 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 243 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 244 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 245 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 246 | CLANG_WARN_STRICT_PROTOTYPES = YES; 247 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 248 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 249 | CLANG_WARN_UNREACHABLE_CODE = YES; 250 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 251 | COPY_PHASE_STRIP = NO; 252 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 253 | ENABLE_NS_ASSERTIONS = NO; 254 | ENABLE_STRICT_OBJC_MSGSEND = YES; 255 | GCC_C_LANGUAGE_STANDARD = gnu11; 256 | GCC_NO_COMMON_BLOCKS = YES; 257 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 258 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 259 | GCC_WARN_UNDECLARED_SELECTOR = YES; 260 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 261 | GCC_WARN_UNUSED_FUNCTION = YES; 262 | GCC_WARN_UNUSED_VARIABLE = YES; 263 | IPHONEOS_DEPLOYMENT_TARGET = 14.5; 264 | MTL_ENABLE_DEBUG_INFO = NO; 265 | MTL_FAST_MATH = YES; 266 | SDKROOT = iphoneos; 267 | SWIFT_COMPILATION_MODE = wholemodule; 268 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 269 | VALIDATE_PRODUCT = YES; 270 | }; 271 | name = Release; 272 | }; 273 | A9939464265BCD8B00D7B90F /* Debug */ = { 274 | isa = XCBuildConfiguration; 275 | buildSettings = { 276 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 277 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 278 | CODE_SIGN_STYLE = Automatic; 279 | DEVELOPMENT_ASSET_PATHS = "\"CoreMLwithSwiftUI/Preview Content\""; 280 | ENABLE_PREVIEWS = YES; 281 | INFOPLIST_FILE = CoreMLwithSwiftUI/Info.plist; 282 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 283 | LD_RUNPATH_SEARCH_PATHS = ( 284 | "$(inherited)", 285 | "@executable_path/Frameworks", 286 | ); 287 | PRODUCT_BUNDLE_IDENTIFIER = com.myname.CoreMLwithSwiftUI; 288 | PRODUCT_NAME = "$(TARGET_NAME)"; 289 | SWIFT_VERSION = 5.0; 290 | TARGETED_DEVICE_FAMILY = "1,2"; 291 | }; 292 | name = Debug; 293 | }; 294 | A9939465265BCD8B00D7B90F /* Release */ = { 295 | isa = XCBuildConfiguration; 296 | buildSettings = { 297 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 298 | ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; 299 | CODE_SIGN_STYLE = Automatic; 300 | DEVELOPMENT_ASSET_PATHS = "\"CoreMLwithSwiftUI/Preview Content\""; 301 | ENABLE_PREVIEWS = YES; 302 | INFOPLIST_FILE = CoreMLwithSwiftUI/Info.plist; 303 | IPHONEOS_DEPLOYMENT_TARGET = 14.0; 304 | LD_RUNPATH_SEARCH_PATHS = ( 305 | "$(inherited)", 306 | "@executable_path/Frameworks", 307 | ); 308 | PRODUCT_BUNDLE_IDENTIFIER = com.myname.CoreMLwithSwiftUI; 309 | PRODUCT_NAME = "$(TARGET_NAME)"; 310 | SWIFT_VERSION = 5.0; 311 | TARGETED_DEVICE_FAMILY = "1,2"; 312 | }; 313 | name = Release; 314 | }; 315 | /* End XCBuildConfiguration section */ 316 | 317 | /* Begin XCConfigurationList section */ 318 | A993944F265BCD8900D7B90F /* Build configuration list for PBXProject "CoreMLwithSwiftUI" */ = { 319 | isa = XCConfigurationList; 320 | buildConfigurations = ( 321 | A9939461265BCD8B00D7B90F /* Debug */, 322 | A9939462265BCD8B00D7B90F /* Release */, 323 | ); 324 | defaultConfigurationIsVisible = 0; 325 | defaultConfigurationName = Release; 326 | }; 327 | A9939463265BCD8B00D7B90F /* Build configuration list for PBXNativeTarget "CoreMLwithSwiftUI" */ = { 328 | isa = XCConfigurationList; 329 | buildConfigurations = ( 330 | A9939464265BCD8B00D7B90F /* Debug */, 331 | A9939465265BCD8B00D7B90F /* Release */, 332 | ); 333 | defaultConfigurationIsVisible = 0; 334 | defaultConfigurationName = Release; 335 | }; 336 | /* End XCConfigurationList section */ 337 | }; 338 | rootObject = A993944C265BCD8900D7B90F /* Project object */; 339 | } 340 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/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 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/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 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Assets.xcassets/lemon.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "lemon.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Assets.xcassets/lemon.imageset/lemon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/create-with-swift/coreml-with-swiftui/b6cd56f1efbe9e097312c2a3e224a38852e18009/CoreMLwithSwiftUI/Assets.xcassets/lemon.imageset/lemon.jpg -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Assets.xcassets/pineapple.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "pineapple.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Assets.xcassets/pineapple.imageset/pineapple.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/create-with-swift/coreml-with-swiftui/b6cd56f1efbe9e097312c2a3e224a38852e18009/CoreMLwithSwiftUI/Assets.xcassets/pineapple.imageset/pineapple.jpg -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Assets.xcassets/strawberry.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "strawberry.jpg", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "author" : "xcode", 19 | "version" : 1 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Assets.xcassets/strawberry.imageset/strawberry.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/create-with-swift/coreml-with-swiftui/b6cd56f1efbe9e097312c2a3e224a38852e18009/CoreMLwithSwiftUI/Assets.xcassets/strawberry.imageset/strawberry.jpg -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // CoreMLwithSwiftUI 4 | // 5 | // Created by Moritz Philip Recke for Create with Swift on 24 May 2021. 6 | // 7 | 8 | import SwiftUI 9 | import CoreML 10 | 11 | struct ContentView: View { 12 | 13 | let model = MobileNetV2() 14 | @State private var classificationLabel: String = "" 15 | 16 | let photos = ["pineapple", "strawberry", "lemon"] 17 | @State private var currentIndex: Int = 0 18 | 19 | var body: some View { 20 | VStack { 21 | Image(photos[currentIndex]) 22 | .resizable() 23 | .frame(width: 200, height: 200) 24 | HStack { 25 | Button("Back") { 26 | if self.currentIndex >= self.photos.count { 27 | self.currentIndex = self.currentIndex - 1 28 | } else { 29 | self.currentIndex = 0 30 | } 31 | } 32 | .padding() 33 | .foregroundColor(Color.white) 34 | .background(Color.gray) 35 | 36 | Button("Next") { 37 | if self.currentIndex < self.photos.count - 1 { 38 | self.currentIndex = self.currentIndex + 1 39 | } else { 40 | self.currentIndex = 0 41 | } 42 | } 43 | .padding() 44 | .foregroundColor(Color.white) 45 | .background(Color.gray) 46 | } 47 | // The button we will use to classify the image using our model 48 | Button("Classify") { 49 | // Add more code here 50 | classifyImage() 51 | } 52 | .padding() 53 | .foregroundColor(Color.white) 54 | .background(Color.green) 55 | 56 | // The Text View that we will use to display the results of the classification 57 | Text(classificationLabel) 58 | .padding() 59 | .font(.body) 60 | Spacer() 61 | } 62 | } 63 | 64 | private func classifyImage() { 65 | let currentImageName = photos[currentIndex] 66 | 67 | guard let image = UIImage(named: currentImageName), 68 | let resizedImage = image.resizeImageTo(size:CGSize(width: 224, height: 224)), 69 | let buffer = resizedImage.convertToBuffer() else { 70 | return 71 | } 72 | 73 | let output = try? model.prediction(image: buffer) 74 | 75 | if let output = output { 76 | let results = output.classLabelProbs.sorted { $0.1 > $1.1 } 77 | let result = results.map { (key, value) in 78 | return "\(key) = \(String(format: "%.2f", value * 100))%" 79 | }.joined(separator: "\n") 80 | 81 | self.classificationLabel = result 82 | } 83 | } 84 | 85 | } 86 | 87 | struct ContentView_Previews: PreviewProvider { 88 | static var previews: some View { 89 | ContentView() 90 | .previewDevice("iPhone 12") 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/CoreMLwithSwiftUIApp.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CoreMLwithSwiftUIApp.swift 3 | // CoreMLwithSwiftUI 4 | // 5 | // Created by Moritz Philip Recke for Create with Swift on 24 May 2021. 6 | // 7 | 8 | import SwiftUI 9 | 10 | @main 11 | struct CoreMLwithSwiftUIApp: App { 12 | var body: some Scene { 13 | WindowGroup { 14 | ContentView() 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/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 | 50 | 51 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/MobileNetV2.mlmodel: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/create-with-swift/coreml-with-swiftui/b6cd56f1efbe9e097312c2a3e224a38852e18009/CoreMLwithSwiftUI/MobileNetV2.mlmodel -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CoreMLwithSwiftUI/UIImage+Extension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Extension.swift 3 | // CoreMLmeetsSwiftUI 4 | // 5 | // Created by Moritz Philip Recke for Create with Swift on 10 February 2021. 6 | // 7 | 8 | import Foundation 9 | import UIKit 10 | 11 | extension UIImage { 12 | 13 | func resizeImageTo(size: CGSize) -> UIImage? { 14 | 15 | UIGraphicsBeginImageContextWithOptions(size, false, 0.0) 16 | self.draw(in: CGRect(origin: CGPoint.zero, size: size)) 17 | let resizedImage = UIGraphicsGetImageFromCurrentImageContext()! 18 | UIGraphicsEndImageContext() 19 | return resizedImage 20 | } 21 | 22 | func convertToBuffer() -> CVPixelBuffer? { 23 | 24 | let attributes = [ 25 | kCVPixelBufferCGImageCompatibilityKey: kCFBooleanTrue, 26 | kCVPixelBufferCGBitmapContextCompatibilityKey: kCFBooleanTrue 27 | ] as CFDictionary 28 | 29 | var pixelBuffer: CVPixelBuffer? 30 | 31 | let status = CVPixelBufferCreate( 32 | kCFAllocatorDefault, Int(self.size.width), 33 | Int(self.size.height), 34 | kCVPixelFormatType_32ARGB, 35 | attributes, 36 | &pixelBuffer) 37 | 38 | guard (status == kCVReturnSuccess) else { 39 | return nil 40 | } 41 | 42 | CVPixelBufferLockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) 43 | 44 | let pixelData = CVPixelBufferGetBaseAddress(pixelBuffer!) 45 | let rgbColorSpace = CGColorSpaceCreateDeviceRGB() 46 | 47 | let context = CGContext( 48 | data: pixelData, 49 | width: Int(self.size.width), 50 | height: Int(self.size.height), 51 | bitsPerComponent: 8, 52 | bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer!), 53 | space: rgbColorSpace, 54 | bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue) 55 | 56 | context?.translateBy(x: 0, y: self.size.height) 57 | context?.scaleBy(x: 1.0, y: -1.0) 58 | 59 | UIGraphicsPushContext(context!) 60 | self.draw(in: CGRect(x: 0, y: 0, width: self.size.width, height: self.size.height)) 61 | UIGraphicsPopContext() 62 | 63 | CVPixelBufferUnlockBaseAddress(pixelBuffer!, CVPixelBufferLockFlags(rawValue: 0)) 64 | 65 | return pixelBuffer 66 | } 67 | 68 | } 69 | 70 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Create with Swift 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Core ML with SwiftUI 2 | 3 | Basic implementation for using Image Classification Core ML models such as MobileNetV2 in an Xcode Project for iOS using SwiftUI. The project has few sample images procured from unslplash.com to test the model. The model used in the prject was downloaded from Apple"s Core ML website https://developer.apple.com/machine-learning/models/. 4 | --------------------------------------------------------------------------------