├── MMParser.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── mahsa.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── mahsa.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── MMParser ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── MMParser.xcdatamodeld │ └── MMParser.xcdatamodel │ │ └── contents ├── Model.swift ├── NetworkManager.swift ├── SceneDelegate.swift ├── ViewController.swift └── ViewModel.swift └── README.md /MMParser.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 195B5DE424D14F4800C020F8 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195B5DE324D14F4800C020F8 /* Model.swift */; }; 11 | 195B5DE624D17EC600C020F8 /* ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 195B5DE524D17EC600C020F8 /* ViewModel.swift */; }; 12 | 19F0185E24CF38B900D0C08F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F0185D24CF38B900D0C08F /* AppDelegate.swift */; }; 13 | 19F0186024CF38B900D0C08F /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F0185F24CF38B900D0C08F /* SceneDelegate.swift */; }; 14 | 19F0186224CF38B900D0C08F /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F0186124CF38B900D0C08F /* ViewController.swift */; }; 15 | 19F0186524CF38B900D0C08F /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 19F0186324CF38B900D0C08F /* Main.storyboard */; }; 16 | 19F0186824CF38B900D0C08F /* MMParser.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 19F0186624CF38B900D0C08F /* MMParser.xcdatamodeld */; }; 17 | 19F0186A24CF38BB00D0C08F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 19F0186924CF38BB00D0C08F /* Assets.xcassets */; }; 18 | 19F0186D24CF38BB00D0C08F /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 19F0186B24CF38BB00D0C08F /* LaunchScreen.storyboard */; }; 19 | 19F0187524CF393100D0C08F /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19F0187424CF393100D0C08F /* NetworkManager.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXFileReference section */ 23 | 195B5DE324D14F4800C020F8 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; 24 | 195B5DE524D17EC600C020F8 /* ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewModel.swift; sourceTree = ""; }; 25 | 19F0185A24CF38B900D0C08F /* MMParser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MMParser.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | 19F0185D24CF38B900D0C08F /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 27 | 19F0185F24CF38B900D0C08F /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 28 | 19F0186124CF38B900D0C08F /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 29 | 19F0186424CF38B900D0C08F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 19F0186724CF38B900D0C08F /* MMParser.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = MMParser.xcdatamodel; sourceTree = ""; }; 31 | 19F0186924CF38BB00D0C08F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 32 | 19F0186C24CF38BB00D0C08F /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 33 | 19F0186E24CF38BB00D0C08F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | 19F0187424CF393100D0C08F /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = ""; }; 35 | /* End PBXFileReference section */ 36 | 37 | /* Begin PBXFrameworksBuildPhase section */ 38 | 19F0185724CF38B900D0C08F /* Frameworks */ = { 39 | isa = PBXFrameworksBuildPhase; 40 | buildActionMask = 2147483647; 41 | files = ( 42 | ); 43 | runOnlyForDeploymentPostprocessing = 0; 44 | }; 45 | /* End PBXFrameworksBuildPhase section */ 46 | 47 | /* Begin PBXGroup section */ 48 | 19F0185124CF38B900D0C08F = { 49 | isa = PBXGroup; 50 | children = ( 51 | 19F0185C24CF38B900D0C08F /* MMParser */, 52 | 19F0185B24CF38B900D0C08F /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 19F0185B24CF38B900D0C08F /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 19F0185A24CF38B900D0C08F /* MMParser.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 19F0185C24CF38B900D0C08F /* MMParser */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 19F0185D24CF38B900D0C08F /* AppDelegate.swift */, 68 | 19F0185F24CF38B900D0C08F /* SceneDelegate.swift */, 69 | 19F0186124CF38B900D0C08F /* ViewController.swift */, 70 | 19F0187424CF393100D0C08F /* NetworkManager.swift */, 71 | 195B5DE324D14F4800C020F8 /* Model.swift */, 72 | 19F0186324CF38B900D0C08F /* Main.storyboard */, 73 | 19F0186924CF38BB00D0C08F /* Assets.xcassets */, 74 | 19F0186B24CF38BB00D0C08F /* LaunchScreen.storyboard */, 75 | 19F0186E24CF38BB00D0C08F /* Info.plist */, 76 | 19F0186624CF38B900D0C08F /* MMParser.xcdatamodeld */, 77 | 195B5DE524D17EC600C020F8 /* ViewModel.swift */, 78 | ); 79 | path = MMParser; 80 | sourceTree = ""; 81 | }; 82 | /* End PBXGroup section */ 83 | 84 | /* Begin PBXNativeTarget section */ 85 | 19F0185924CF38B900D0C08F /* MMParser */ = { 86 | isa = PBXNativeTarget; 87 | buildConfigurationList = 19F0187124CF38BB00D0C08F /* Build configuration list for PBXNativeTarget "MMParser" */; 88 | buildPhases = ( 89 | 19F0185624CF38B900D0C08F /* Sources */, 90 | 19F0185724CF38B900D0C08F /* Frameworks */, 91 | 19F0185824CF38B900D0C08F /* Resources */, 92 | ); 93 | buildRules = ( 94 | ); 95 | dependencies = ( 96 | ); 97 | name = MMParser; 98 | productName = MMParser; 99 | productReference = 19F0185A24CF38B900D0C08F /* MMParser.app */; 100 | productType = "com.apple.product-type.application"; 101 | }; 102 | /* End PBXNativeTarget section */ 103 | 104 | /* Begin PBXProject section */ 105 | 19F0185224CF38B900D0C08F /* Project object */ = { 106 | isa = PBXProject; 107 | attributes = { 108 | LastSwiftUpdateCheck = 1130; 109 | LastUpgradeCheck = 1130; 110 | ORGANIZATIONNAME = "Mahsa Mo"; 111 | TargetAttributes = { 112 | 19F0185924CF38B900D0C08F = { 113 | CreatedOnToolsVersion = 11.3.1; 114 | }; 115 | }; 116 | }; 117 | buildConfigurationList = 19F0185524CF38B900D0C08F /* Build configuration list for PBXProject "MMParser" */; 118 | compatibilityVersion = "Xcode 9.3"; 119 | developmentRegion = en; 120 | hasScannedForEncodings = 0; 121 | knownRegions = ( 122 | en, 123 | Base, 124 | ); 125 | mainGroup = 19F0185124CF38B900D0C08F; 126 | productRefGroup = 19F0185B24CF38B900D0C08F /* Products */; 127 | projectDirPath = ""; 128 | projectRoot = ""; 129 | targets = ( 130 | 19F0185924CF38B900D0C08F /* MMParser */, 131 | ); 132 | }; 133 | /* End PBXProject section */ 134 | 135 | /* Begin PBXResourcesBuildPhase section */ 136 | 19F0185824CF38B900D0C08F /* Resources */ = { 137 | isa = PBXResourcesBuildPhase; 138 | buildActionMask = 2147483647; 139 | files = ( 140 | 19F0186D24CF38BB00D0C08F /* LaunchScreen.storyboard in Resources */, 141 | 19F0186A24CF38BB00D0C08F /* Assets.xcassets in Resources */, 142 | 19F0186524CF38B900D0C08F /* Main.storyboard in Resources */, 143 | ); 144 | runOnlyForDeploymentPostprocessing = 0; 145 | }; 146 | /* End PBXResourcesBuildPhase section */ 147 | 148 | /* Begin PBXSourcesBuildPhase section */ 149 | 19F0185624CF38B900D0C08F /* Sources */ = { 150 | isa = PBXSourcesBuildPhase; 151 | buildActionMask = 2147483647; 152 | files = ( 153 | 19F0186824CF38B900D0C08F /* MMParser.xcdatamodeld in Sources */, 154 | 19F0186224CF38B900D0C08F /* ViewController.swift in Sources */, 155 | 19F0187524CF393100D0C08F /* NetworkManager.swift in Sources */, 156 | 195B5DE424D14F4800C020F8 /* Model.swift in Sources */, 157 | 19F0185E24CF38B900D0C08F /* AppDelegate.swift in Sources */, 158 | 19F0186024CF38B900D0C08F /* SceneDelegate.swift in Sources */, 159 | 195B5DE624D17EC600C020F8 /* ViewModel.swift in Sources */, 160 | ); 161 | runOnlyForDeploymentPostprocessing = 0; 162 | }; 163 | /* End PBXSourcesBuildPhase section */ 164 | 165 | /* Begin PBXVariantGroup section */ 166 | 19F0186324CF38B900D0C08F /* Main.storyboard */ = { 167 | isa = PBXVariantGroup; 168 | children = ( 169 | 19F0186424CF38B900D0C08F /* Base */, 170 | ); 171 | name = Main.storyboard; 172 | sourceTree = ""; 173 | }; 174 | 19F0186B24CF38BB00D0C08F /* LaunchScreen.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | 19F0186C24CF38BB00D0C08F /* Base */, 178 | ); 179 | name = LaunchScreen.storyboard; 180 | sourceTree = ""; 181 | }; 182 | /* End PBXVariantGroup section */ 183 | 184 | /* Begin XCBuildConfiguration section */ 185 | 19F0186F24CF38BB00D0C08F /* Debug */ = { 186 | isa = XCBuildConfiguration; 187 | buildSettings = { 188 | ALWAYS_SEARCH_USER_PATHS = NO; 189 | CLANG_ANALYZER_NONNULL = YES; 190 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 191 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 192 | CLANG_CXX_LIBRARY = "libc++"; 193 | CLANG_ENABLE_MODULES = YES; 194 | CLANG_ENABLE_OBJC_ARC = YES; 195 | CLANG_ENABLE_OBJC_WEAK = YES; 196 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_COMMA = YES; 199 | CLANG_WARN_CONSTANT_CONVERSION = YES; 200 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 201 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 202 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 203 | CLANG_WARN_EMPTY_BODY = YES; 204 | CLANG_WARN_ENUM_CONVERSION = YES; 205 | CLANG_WARN_INFINITE_RECURSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 208 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 209 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 210 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 211 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 212 | CLANG_WARN_STRICT_PROTOTYPES = YES; 213 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 214 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 215 | CLANG_WARN_UNREACHABLE_CODE = YES; 216 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 217 | COPY_PHASE_STRIP = NO; 218 | DEBUG_INFORMATION_FORMAT = dwarf; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | ENABLE_TESTABILITY = YES; 221 | GCC_C_LANGUAGE_STANDARD = gnu11; 222 | GCC_DYNAMIC_NO_PIC = NO; 223 | GCC_NO_COMMON_BLOCKS = YES; 224 | GCC_OPTIMIZATION_LEVEL = 0; 225 | GCC_PREPROCESSOR_DEFINITIONS = ( 226 | "DEBUG=1", 227 | "$(inherited)", 228 | ); 229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 231 | GCC_WARN_UNDECLARED_SELECTOR = YES; 232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 233 | GCC_WARN_UNUSED_FUNCTION = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 236 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 237 | MTL_FAST_MATH = YES; 238 | ONLY_ACTIVE_ARCH = YES; 239 | SDKROOT = iphoneos; 240 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 241 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 242 | }; 243 | name = Debug; 244 | }; 245 | 19F0187024CF38BB00D0C08F /* Release */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ALWAYS_SEARCH_USER_PATHS = NO; 249 | CLANG_ANALYZER_NONNULL = YES; 250 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 251 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 252 | CLANG_CXX_LIBRARY = "libc++"; 253 | CLANG_ENABLE_MODULES = YES; 254 | CLANG_ENABLE_OBJC_ARC = YES; 255 | CLANG_ENABLE_OBJC_WEAK = YES; 256 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 257 | CLANG_WARN_BOOL_CONVERSION = YES; 258 | CLANG_WARN_COMMA = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 263 | CLANG_WARN_EMPTY_BODY = YES; 264 | CLANG_WARN_ENUM_CONVERSION = YES; 265 | CLANG_WARN_INFINITE_RECURSION = YES; 266 | CLANG_WARN_INT_CONVERSION = YES; 267 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 268 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 269 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 272 | CLANG_WARN_STRICT_PROTOTYPES = YES; 273 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 274 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_NS_ASSERTIONS = NO; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu11; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 13.2; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | MTL_FAST_MATH = YES; 292 | SDKROOT = iphoneos; 293 | SWIFT_COMPILATION_MODE = wholemodule; 294 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 295 | VALIDATE_PRODUCT = YES; 296 | }; 297 | name = Release; 298 | }; 299 | 19F0187224CF38BB00D0C08F /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | CODE_SIGN_STYLE = Automatic; 304 | INFOPLIST_FILE = MMParser/Info.plist; 305 | LD_RUNPATH_SEARCH_PATHS = ( 306 | "$(inherited)", 307 | "@executable_path/Frameworks", 308 | ); 309 | PRODUCT_BUNDLE_IDENTIFIER = com.MMParser; 310 | PRODUCT_NAME = "$(TARGET_NAME)"; 311 | SWIFT_VERSION = 5.0; 312 | TARGETED_DEVICE_FAMILY = "1,2"; 313 | }; 314 | name = Debug; 315 | }; 316 | 19F0187324CF38BB00D0C08F /* Release */ = { 317 | isa = XCBuildConfiguration; 318 | buildSettings = { 319 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 320 | CODE_SIGN_STYLE = Automatic; 321 | INFOPLIST_FILE = MMParser/Info.plist; 322 | LD_RUNPATH_SEARCH_PATHS = ( 323 | "$(inherited)", 324 | "@executable_path/Frameworks", 325 | ); 326 | PRODUCT_BUNDLE_IDENTIFIER = com.MMParser; 327 | PRODUCT_NAME = "$(TARGET_NAME)"; 328 | SWIFT_VERSION = 5.0; 329 | TARGETED_DEVICE_FAMILY = "1,2"; 330 | }; 331 | name = Release; 332 | }; 333 | /* End XCBuildConfiguration section */ 334 | 335 | /* Begin XCConfigurationList section */ 336 | 19F0185524CF38B900D0C08F /* Build configuration list for PBXProject "MMParser" */ = { 337 | isa = XCConfigurationList; 338 | buildConfigurations = ( 339 | 19F0186F24CF38BB00D0C08F /* Debug */, 340 | 19F0187024CF38BB00D0C08F /* Release */, 341 | ); 342 | defaultConfigurationIsVisible = 0; 343 | defaultConfigurationName = Release; 344 | }; 345 | 19F0187124CF38BB00D0C08F /* Build configuration list for PBXNativeTarget "MMParser" */ = { 346 | isa = XCConfigurationList; 347 | buildConfigurations = ( 348 | 19F0187224CF38BB00D0C08F /* Debug */, 349 | 19F0187324CF38BB00D0C08F /* Release */, 350 | ); 351 | defaultConfigurationIsVisible = 0; 352 | defaultConfigurationName = Release; 353 | }; 354 | /* End XCConfigurationList section */ 355 | 356 | /* Begin XCVersionGroup section */ 357 | 19F0186624CF38B900D0C08F /* MMParser.xcdatamodeld */ = { 358 | isa = XCVersionGroup; 359 | children = ( 360 | 19F0186724CF38B900D0C08F /* MMParser.xcdatamodel */, 361 | ); 362 | currentVersion = 19F0186724CF38B900D0C08F /* MMParser.xcdatamodel */; 363 | path = MMParser.xcdatamodeld; 364 | sourceTree = ""; 365 | versionGroupType = wrapper.xcdatamodel; 366 | }; 367 | /* End XCVersionGroup section */ 368 | }; 369 | rootObject = 19F0185224CF38B900D0C08F /* Project object */; 370 | } 371 | -------------------------------------------------------------------------------- /MMParser.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /MMParser.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /MMParser.xcodeproj/project.xcworkspace/xcuserdata/mahsa.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/engmahsa/SwiftDecoderEncoder/7b1b012d25324c5af11364ba8abe0053dc88f9d9/MMParser.xcodeproj/project.xcworkspace/xcuserdata/mahsa.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /MMParser.xcodeproj/xcuserdata/mahsa.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 9 | 21 | 22 | 23 | 25 | 37 | 38 | 39 | 41 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /MMParser.xcodeproj/xcuserdata/mahsa.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | MMParser.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /MMParser/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // MMParser 4 | // 5 | // Created by Mahsa Mo on 5/6/1399 AP. 6 | // Copyright © 1399 Mahsa Mo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreData 11 | 12 | @UIApplicationMain 13 | class AppDelegate: UIResponder, UIApplicationDelegate { 14 | 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | // MARK: UISceneSession Lifecycle 23 | 24 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 25 | // Called when a new scene session is being created. 26 | // Use this method to select a configuration to create the new scene with. 27 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 28 | } 29 | 30 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 31 | // Called when the user discards a scene session. 32 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 33 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 34 | } 35 | 36 | // MARK: - Core Data stack 37 | 38 | lazy var persistentContainer: NSPersistentContainer = { 39 | /* 40 | The persistent container for the application. This implementation 41 | creates and returns a container, having loaded the store for the 42 | application to it. This property is optional since there are legitimate 43 | error conditions that could cause the creation of the store to fail. 44 | */ 45 | let container = NSPersistentContainer(name: "MMParser") 46 | container.loadPersistentStores(completionHandler: { (storeDescription, error) in 47 | if let error = error as NSError? { 48 | // Replace this implementation with code to handle the error appropriately. 49 | // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 50 | 51 | /* 52 | Typical reasons for an error here include: 53 | * The parent directory does not exist, cannot be created, or disallows writing. 54 | * The persistent store is not accessible, due to permissions or data protection when the device is locked. 55 | * The device is out of space. 56 | * The store could not be migrated to the current model version. 57 | Check the error message to determine what the actual problem was. 58 | */ 59 | fatalError("Unresolved error \(error), \(error.userInfo)") 60 | } 61 | }) 62 | return container 63 | }() 64 | 65 | // MARK: - Core Data Saving support 66 | 67 | func saveContext () { 68 | let context = persistentContainer.viewContext 69 | if context.hasChanges { 70 | do { 71 | try context.save() 72 | } catch { 73 | // Replace this implementation with code to handle the error appropriately. 74 | // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 75 | let nserror = error as NSError 76 | fatalError("Unresolved error \(nserror), \(nserror.userInfo)") 77 | } 78 | } 79 | } 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /MMParser/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 | } -------------------------------------------------------------------------------- /MMParser/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /MMParser/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 | -------------------------------------------------------------------------------- /MMParser/Base.lproj/Main.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 | -------------------------------------------------------------------------------- /MMParser/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 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UISceneConfigurationName 33 | Default Configuration 34 | UISceneDelegateClassName 35 | $(PRODUCT_MODULE_NAME).SceneDelegate 36 | UISceneStoryboardFile 37 | Main 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIMainStoryboardFile 45 | Main 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 | -------------------------------------------------------------------------------- /MMParser/MMParser.xcdatamodeld/MMParser.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /MMParser/Model.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Model.swift 3 | // MMParser 4 | // 5 | // Created by Mahsa Mo on 5/8/1399 AP. 6 | // Copyright © 1399 Mahsa Mo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct AppConstants { 12 | static let countryByCodeURL = "https://restcountries-v1.p.rapidapi.com/callingcode/" 13 | } 14 | 15 | 16 | 17 | 18 | 19 | 20 | // MARK: - CountryModel 21 | struct Country: Codable { 22 | let name: String 23 | let topLevelDomain: [String] 24 | let alpha2Code, alpha3Code: String 25 | let callingCodes: [String] 26 | let capital: String 27 | let altSpellings: [String] 28 | let region, subregion: String 29 | let population: Int 30 | let latlng: [Int] 31 | let demonym: String 32 | let area: Int 33 | let gini: Double 34 | let timezones, borders: [String] 35 | let nativeName, numericCode: String 36 | let currencies, languages: [String] 37 | let translations: Translations 38 | let relevance: String 39 | } 40 | 41 | // MARK: - Translations 42 | struct Translations: Codable { 43 | let de, es, fr, ja: String 44 | let it: String 45 | } 46 | 47 | typealias Response = [Country] 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | // MARK: Mapper Initialization 59 | struct Mapper { 60 | 61 | init() { 62 | } 63 | func mapp(jsString: String) -> Any { 64 | if let jsonData = jsString.data(using: .utf8) { 65 | let decoder = JSONDecoder() 66 | do { 67 | let model = try decoder.decode(Response.self, from: jsonData) 68 | 69 | return model 70 | 71 | }catch { 72 | print(error.localizedDescription) 73 | } 74 | 75 | }else { 76 | 77 | } 78 | return "Error" 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /MMParser/NetworkManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // NetworkManager.swift 3 | // MMParser 4 | // 5 | // Created by Mahsa Mo on 5/6/1399 AP. 6 | // Copyright © 1399 Mahsa Mo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class NetworkManager:BaseRequest{ 12 | 13 | static let sharedInstance = NetworkManager() 14 | let mapper = Mapper.init() 15 | func startDownloadTask(request:URLRequest ,completion: @escaping (_ data: Any?) -> Void) { 16 | 17 | 18 | let session = URLSession.shared 19 | let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in 20 | if (error != nil) { 21 | print(error ?? "try again") 22 | } else { 23 | let responseString = NSString(data: data!, encoding: String.Encoding.utf8.rawValue) 24 | 25 | let result = self.mapper.mapp(jsString: responseString as! String) 26 | completion(result) 27 | } 28 | }) 29 | 30 | dataTask.resume() 31 | } 32 | } 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | class BaseRequest { 45 | 46 | init() { 47 | 48 | } 49 | func defaultRequestHeaders() -> [String: String] { 50 | let headers = [ 51 | "x-rapidapi-host": "restcountries-v1.p.rapidapi.com", 52 | "x-rapidapi-key": "432d4e5b88msh307290e7ce97588p1fff49jsnf41765bb8e44" 53 | ] 54 | return headers 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /MMParser/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // MMParser 4 | // 5 | // Created by Mahsa Mo on 5/6/1399 AP. 6 | // Copyright © 1399 Mahsa Mo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 12 | 13 | var window: UIWindow? 14 | 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 | guard let _ = (scene as? UIWindowScene) else { return } 21 | } 22 | 23 | func sceneDidDisconnect(_ scene: UIScene) { 24 | // Called as the scene is being released by the system. 25 | // This occurs shortly after the scene enters the background, or when its session is discarded. 26 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 27 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 28 | } 29 | 30 | func sceneDidBecomeActive(_ scene: UIScene) { 31 | // Called when the scene has moved from an inactive state to an active state. 32 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 33 | } 34 | 35 | func sceneWillResignActive(_ scene: UIScene) { 36 | // Called when the scene will move from an active state to an inactive state. 37 | // This may occur due to temporary interruptions (ex. an incoming phone call). 38 | } 39 | 40 | func sceneWillEnterForeground(_ scene: UIScene) { 41 | // Called as the scene transitions from the background to the foreground. 42 | // Use this method to undo the changes made on entering the background. 43 | } 44 | 45 | func sceneDidEnterBackground(_ scene: UIScene) { 46 | // Called as the scene transitions from the foreground to the background. 47 | // Use this method to save data, release shared resources, and store enough scene-specific state information 48 | // to restore the scene back to its current state. 49 | 50 | // Save changes in the application's managed object context when the application transitions to the background. 51 | (UIApplication.shared.delegate as? AppDelegate)?.saveContext() 52 | } 53 | 54 | 55 | } 56 | 57 | -------------------------------------------------------------------------------- /MMParser/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // MMParser 4 | // 5 | // Created by Mahsa Mo on 5/6/1399 AP. 6 | // Copyright © 1399 Mahsa Mo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController,ViewModelProtocol { 12 | 13 | lazy var viewModel: ViewModel = { 14 | let viewModel = ViewModel() 15 | return viewModel 16 | }() 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | viewModel.viewModelMDelegate = self 21 | viewModel.getCountryByCode(code: "57") 22 | } 23 | 24 | 25 | func DataReceived(result: Any) { 26 | print(result) 27 | //update view 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /MMParser/ViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewModel.swift 3 | // MMParser 4 | // 5 | // Created by Mahsa Mo on 5/8/1399 AP. 6 | // Copyright © 1399 Mahsa Mo. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | protocol ViewModelProtocol { 12 | func DataReceived(result: Any) 13 | } 14 | 15 | struct ViewModel { 16 | var viewModelMDelegate: ViewModelProtocol? 17 | let networkManager = NetworkManager.sharedInstance 18 | let baseRq = BaseRequest.init() 19 | 20 | 21 | func getCountryByCode(code:String) { 22 | 23 | let url = String(format: "%@%@", AppConstants.countryByCodeURL,code) 24 | let request = NSMutableURLRequest(url: NSURL(string:url)! as URL, 25 | cachePolicy: .useProtocolCachePolicy, 26 | timeoutInterval: 10.0) 27 | request.httpMethod = "GET" 28 | request.allHTTPHeaderFields = baseRq.defaultRequestHeaders() 29 | networkManager.startDownloadTask(request: request as URLRequest) { (data) in 30 | self.viewModelMDelegate?.DataReceived(result: data) 31 | } 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SwiftDecoderEncoder 2 | This is the easiest way to parse JSON object to a Swift. 3 | 4 | 5 | JSON is a text-based data format that many webservices use . It’s superior to XML, because it’s efficient, easily parsed, and readable by humans. JSON is an agreed upon format for webservices, APIs and apps. It’s used throughout the web, apps, and online services, because the format is simple and flexible. So, as an iOS developer, you’ll come across JSON sooner rather than later. 6 | 7 | How can you encode and decode JSON data to Swift objects effectively? 8 | 9 | Before Swift 4, you’d have to serialize the JSON yourself, and then type cast every property of the JSON to the right Swift type. 10 | Like this: 11 | 12 | ```swift 13 | let json = try? JSONSerialization.jsonObject(with: data, options: []) 14 | 15 | if let result = json as? [String: Any] { 16 | if let property = result["property"] as? Int { 17 | resultObject.yield = property 18 | } 19 | } 20 | ``` 21 | 22 | Which was extremely verbose. Even though it works, it’s not ideal.Libraries like **SwiftyJSON** make working with JSON a lot easier, but you still need to map the JSON data to their respective Swift objects and properties. 23 | With **Swift 4** and later you can now use the *Codable* protocol. Your Swift struct or class merely has to adopt that protocol, and you get JSON encoding and decoding for free. 24 | 25 | In this project I’ve used nested types which are great general-purpose approach to complex JSON data structures. I’ve also used the **MVVM** Structure which arranged as below: 26 | 27 | **Model:** Includes AppConstants, Country(sample model) and mapper function 28 | 29 | **ViewModel:** Prepares URLRequest and Ask the NetworkManager to download data 30 | 31 | **ViewController:** Get the mapped the data from ViewModel and update the data 32 | 33 | Let’s take a look at the flow: 34 | First from [www.rapidapi.com](https://rapidapi.com/apilayernet/api/rest-countries-v1) I’ve found some test api and JSON data. Then to decode the JSON to an actual Swift object, I’ve created a struct called Country. Like this: 35 | 36 | ```swift 37 | // MARK: - CountryModel 38 | struct Country: Codable { 39 | let name: String 40 | let topLevelDomain: [String] 41 | let alpha2Code, alpha3Code: String 42 | let callingCodes: [String] 43 | let capital: String 44 | let altSpellings: [String] 45 | let region, subregion: String 46 | let population: Int 47 | let latlng: [Int] 48 | let demonym: String 49 | let area: Int 50 | let gini: Double 51 | let timezones, borders: [String] 52 | let nativeName, numericCode: String 53 | let currencies, languages: [String] 54 | let translations: Translations 55 | let relevance: String 56 | } 57 | 58 | // MARK: - Translations 59 | struct Translations: Codable { 60 | let de, es, fr, ja: String 61 | let it: String 62 | } 63 | 64 | typealias Response = [Country] 65 | ``` 66 | What I’ve done next, is decoding the JSON and turning it into a Country object at Mapper: 67 | 68 | ```swift 69 | func mapp(jsString: String) -> Any { 70 | } 71 | ``` 72 | 73 | **Easy, right? I’ve “mapped” the JSON object to a Swift struct, and decoded the JSON format to a native object Swift can work with.** 74 | --------------------------------------------------------------------------------