├── NetworkLayerSetup.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── Xoriant.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── NetworkLayerSetup ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── Model │ └── Model1.swift ├── Networking │ ├── ErrorHandling │ │ └── APIError.swift │ ├── Manager │ │ ├── APIClient.swift │ │ └── MyClient.swift │ ├── Request │ │ ├── API.swift │ │ └── Endpoint.swift │ └── Response │ │ └── Result.swift └── ViewControllers │ └── ViewController.swift └── README.md /NetworkLayerSetup.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 48D016DF20F27B4D00061B7E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016DE20F27B4D00061B7E /* AppDelegate.swift */; }; 11 | 48D016E120F27B4D00061B7E /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016E020F27B4D00061B7E /* ViewController.swift */; }; 12 | 48D016E420F27B4D00061B7E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 48D016E220F27B4D00061B7E /* Main.storyboard */; }; 13 | 48D016E620F27B5800061B7E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 48D016E520F27B5800061B7E /* Assets.xcassets */; }; 14 | 48D016E920F27B5800061B7E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 48D016E720F27B5800061B7E /* LaunchScreen.storyboard */; }; 15 | 48D016F320F27C1000061B7E /* Result.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016F220F27C1000061B7E /* Result.swift */; }; 16 | 48D016F520F2865900061B7E /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016F420F2865900061B7E /* Endpoint.swift */; }; 17 | 48D016F720F28B9200061B7E /* API.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016F620F28B9200061B7E /* API.swift */; }; 18 | 48D016F920F28C7800061B7E /* APIError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016F820F28C7800061B7E /* APIError.swift */; }; 19 | 48D016FB20F2929500061B7E /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016FA20F2929500061B7E /* APIClient.swift */; }; 20 | 48D016FD20F3426600061B7E /* MyClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016FC20F3426600061B7E /* MyClient.swift */; }; 21 | 48D016FF20F357E900061B7E /* Model1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48D016FE20F357E900061B7E /* Model1.swift */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 48D016DB20F27B4D00061B7E /* NetworkLayerSetup.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = NetworkLayerSetup.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | 48D016DE20F27B4D00061B7E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 27 | 48D016E020F27B4D00061B7E /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 28 | 48D016E320F27B4D00061B7E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 48D016E520F27B5800061B7E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 30 | 48D016E820F27B5800061B7E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 31 | 48D016EA20F27B5800061B7E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 32 | 48D016F220F27C1000061B7E /* Result.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Result.swift; sourceTree = ""; }; 33 | 48D016F420F2865900061B7E /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = ""; }; 34 | 48D016F620F28B9200061B7E /* API.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = API.swift; sourceTree = ""; }; 35 | 48D016F820F28C7800061B7E /* APIError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIError.swift; sourceTree = ""; }; 36 | 48D016FA20F2929500061B7E /* APIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClient.swift; sourceTree = ""; }; 37 | 48D016FC20F3426600061B7E /* MyClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyClient.swift; sourceTree = ""; }; 38 | 48D016FE20F357E900061B7E /* Model1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model1.swift; sourceTree = ""; }; 39 | /* End PBXFileReference section */ 40 | 41 | /* Begin PBXFrameworksBuildPhase section */ 42 | 48D016D820F27B4D00061B7E /* Frameworks */ = { 43 | isa = PBXFrameworksBuildPhase; 44 | buildActionMask = 2147483647; 45 | files = ( 46 | ); 47 | runOnlyForDeploymentPostprocessing = 0; 48 | }; 49 | /* End PBXFrameworksBuildPhase section */ 50 | 51 | /* Begin PBXGroup section */ 52 | 48D016D220F27B4D00061B7E = { 53 | isa = PBXGroup; 54 | children = ( 55 | 48D016DD20F27B4D00061B7E /* NetworkLayerSetup */, 56 | 48D016DC20F27B4D00061B7E /* Products */, 57 | ); 58 | sourceTree = ""; 59 | }; 60 | 48D016DC20F27B4D00061B7E /* Products */ = { 61 | isa = PBXGroup; 62 | children = ( 63 | 48D016DB20F27B4D00061B7E /* NetworkLayerSetup.app */, 64 | ); 65 | name = Products; 66 | sourceTree = ""; 67 | }; 68 | 48D016DD20F27B4D00061B7E /* NetworkLayerSetup */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 48D0170820F38EFD00061B7E /* ViewControllers */, 72 | 48D016F120F27BB900061B7E /* Networking */, 73 | 48D016F020F27BA100061B7E /* Model */, 74 | 48D016DE20F27B4D00061B7E /* AppDelegate.swift */, 75 | 48D016E220F27B4D00061B7E /* Main.storyboard */, 76 | 48D016E520F27B5800061B7E /* Assets.xcassets */, 77 | 48D016E720F27B5800061B7E /* LaunchScreen.storyboard */, 78 | 48D016EA20F27B5800061B7E /* Info.plist */, 79 | ); 80 | path = NetworkLayerSetup; 81 | sourceTree = ""; 82 | }; 83 | 48D016F020F27BA100061B7E /* Model */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 48D016FE20F357E900061B7E /* Model1.swift */, 87 | ); 88 | path = Model; 89 | sourceTree = ""; 90 | }; 91 | 48D016F120F27BB900061B7E /* Networking */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | 48D0170720F36E3900061B7E /* Response */, 95 | 48D0170620F36E0300061B7E /* Manager */, 96 | 48D0170520F36DE400061B7E /* Request */, 97 | 48D0170420F36DA000061B7E /* ErrorHandling */, 98 | ); 99 | path = Networking; 100 | sourceTree = ""; 101 | }; 102 | 48D0170420F36DA000061B7E /* ErrorHandling */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 48D016F820F28C7800061B7E /* APIError.swift */, 106 | ); 107 | path = ErrorHandling; 108 | sourceTree = ""; 109 | }; 110 | 48D0170520F36DE400061B7E /* Request */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 48D016F420F2865900061B7E /* Endpoint.swift */, 114 | 48D016F620F28B9200061B7E /* API.swift */, 115 | ); 116 | path = Request; 117 | sourceTree = ""; 118 | }; 119 | 48D0170620F36E0300061B7E /* Manager */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 48D016FA20F2929500061B7E /* APIClient.swift */, 123 | 48D016FC20F3426600061B7E /* MyClient.swift */, 124 | ); 125 | path = Manager; 126 | sourceTree = ""; 127 | }; 128 | 48D0170720F36E3900061B7E /* Response */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 48D016F220F27C1000061B7E /* Result.swift */, 132 | ); 133 | path = Response; 134 | sourceTree = ""; 135 | }; 136 | 48D0170820F38EFD00061B7E /* ViewControllers */ = { 137 | isa = PBXGroup; 138 | children = ( 139 | 48D016E020F27B4D00061B7E /* ViewController.swift */, 140 | ); 141 | path = ViewControllers; 142 | sourceTree = ""; 143 | }; 144 | /* End PBXGroup section */ 145 | 146 | /* Begin PBXNativeTarget section */ 147 | 48D016DA20F27B4D00061B7E /* NetworkLayerSetup */ = { 148 | isa = PBXNativeTarget; 149 | buildConfigurationList = 48D016ED20F27B5800061B7E /* Build configuration list for PBXNativeTarget "NetworkLayerSetup" */; 150 | buildPhases = ( 151 | 48D016D720F27B4D00061B7E /* Sources */, 152 | 48D016D820F27B4D00061B7E /* Frameworks */, 153 | 48D016D920F27B4D00061B7E /* Resources */, 154 | ); 155 | buildRules = ( 156 | ); 157 | dependencies = ( 158 | ); 159 | name = NetworkLayerSetup; 160 | productName = NetworkLayerSetup; 161 | productReference = 48D016DB20F27B4D00061B7E /* NetworkLayerSetup.app */; 162 | productType = "com.apple.product-type.application"; 163 | }; 164 | /* End PBXNativeTarget section */ 165 | 166 | /* Begin PBXProject section */ 167 | 48D016D320F27B4D00061B7E /* Project object */ = { 168 | isa = PBXProject; 169 | attributes = { 170 | LastSwiftUpdateCheck = 0940; 171 | LastUpgradeCheck = 0940; 172 | ORGANIZATIONNAME = Assignment; 173 | TargetAttributes = { 174 | 48D016DA20F27B4D00061B7E = { 175 | CreatedOnToolsVersion = 9.4; 176 | }; 177 | }; 178 | }; 179 | buildConfigurationList = 48D016D620F27B4D00061B7E /* Build configuration list for PBXProject "NetworkLayerSetup" */; 180 | compatibilityVersion = "Xcode 9.3"; 181 | developmentRegion = en; 182 | hasScannedForEncodings = 0; 183 | knownRegions = ( 184 | en, 185 | Base, 186 | ); 187 | mainGroup = 48D016D220F27B4D00061B7E; 188 | productRefGroup = 48D016DC20F27B4D00061B7E /* Products */; 189 | projectDirPath = ""; 190 | projectRoot = ""; 191 | targets = ( 192 | 48D016DA20F27B4D00061B7E /* NetworkLayerSetup */, 193 | ); 194 | }; 195 | /* End PBXProject section */ 196 | 197 | /* Begin PBXResourcesBuildPhase section */ 198 | 48D016D920F27B4D00061B7E /* Resources */ = { 199 | isa = PBXResourcesBuildPhase; 200 | buildActionMask = 2147483647; 201 | files = ( 202 | 48D016E920F27B5800061B7E /* LaunchScreen.storyboard in Resources */, 203 | 48D016E620F27B5800061B7E /* Assets.xcassets in Resources */, 204 | 48D016E420F27B4D00061B7E /* Main.storyboard in Resources */, 205 | ); 206 | runOnlyForDeploymentPostprocessing = 0; 207 | }; 208 | /* End PBXResourcesBuildPhase section */ 209 | 210 | /* Begin PBXSourcesBuildPhase section */ 211 | 48D016D720F27B4D00061B7E /* Sources */ = { 212 | isa = PBXSourcesBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | 48D016F320F27C1000061B7E /* Result.swift in Sources */, 216 | 48D016FB20F2929500061B7E /* APIClient.swift in Sources */, 217 | 48D016E120F27B4D00061B7E /* ViewController.swift in Sources */, 218 | 48D016F520F2865900061B7E /* Endpoint.swift in Sources */, 219 | 48D016F720F28B9200061B7E /* API.swift in Sources */, 220 | 48D016DF20F27B4D00061B7E /* AppDelegate.swift in Sources */, 221 | 48D016FF20F357E900061B7E /* Model1.swift in Sources */, 222 | 48D016FD20F3426600061B7E /* MyClient.swift in Sources */, 223 | 48D016F920F28C7800061B7E /* APIError.swift in Sources */, 224 | ); 225 | runOnlyForDeploymentPostprocessing = 0; 226 | }; 227 | /* End PBXSourcesBuildPhase section */ 228 | 229 | /* Begin PBXVariantGroup section */ 230 | 48D016E220F27B4D00061B7E /* Main.storyboard */ = { 231 | isa = PBXVariantGroup; 232 | children = ( 233 | 48D016E320F27B4D00061B7E /* Base */, 234 | ); 235 | name = Main.storyboard; 236 | sourceTree = ""; 237 | }; 238 | 48D016E720F27B5800061B7E /* LaunchScreen.storyboard */ = { 239 | isa = PBXVariantGroup; 240 | children = ( 241 | 48D016E820F27B5800061B7E /* Base */, 242 | ); 243 | name = LaunchScreen.storyboard; 244 | sourceTree = ""; 245 | }; 246 | /* End PBXVariantGroup section */ 247 | 248 | /* Begin XCBuildConfiguration section */ 249 | 48D016EB20F27B5800061B7E /* Debug */ = { 250 | isa = XCBuildConfiguration; 251 | buildSettings = { 252 | ALWAYS_SEARCH_USER_PATHS = NO; 253 | CLANG_ANALYZER_NONNULL = YES; 254 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 255 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 256 | CLANG_CXX_LIBRARY = "libc++"; 257 | CLANG_ENABLE_MODULES = YES; 258 | CLANG_ENABLE_OBJC_ARC = YES; 259 | CLANG_ENABLE_OBJC_WEAK = YES; 260 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 261 | CLANG_WARN_BOOL_CONVERSION = YES; 262 | CLANG_WARN_COMMA = YES; 263 | CLANG_WARN_CONSTANT_CONVERSION = YES; 264 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 265 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 266 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 267 | CLANG_WARN_EMPTY_BODY = YES; 268 | CLANG_WARN_ENUM_CONVERSION = YES; 269 | CLANG_WARN_INFINITE_RECURSION = YES; 270 | CLANG_WARN_INT_CONVERSION = YES; 271 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 272 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 273 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 276 | CLANG_WARN_STRICT_PROTOTYPES = YES; 277 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 278 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 279 | CLANG_WARN_UNREACHABLE_CODE = YES; 280 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 281 | CODE_SIGN_IDENTITY = "iPhone Developer"; 282 | COPY_PHASE_STRIP = NO; 283 | DEBUG_INFORMATION_FORMAT = dwarf; 284 | ENABLE_STRICT_OBJC_MSGSEND = YES; 285 | ENABLE_TESTABILITY = YES; 286 | GCC_C_LANGUAGE_STANDARD = gnu11; 287 | GCC_DYNAMIC_NO_PIC = NO; 288 | GCC_NO_COMMON_BLOCKS = YES; 289 | GCC_OPTIMIZATION_LEVEL = 0; 290 | GCC_PREPROCESSOR_DEFINITIONS = ( 291 | "DEBUG=1", 292 | "$(inherited)", 293 | ); 294 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 295 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 296 | GCC_WARN_UNDECLARED_SELECTOR = YES; 297 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 298 | GCC_WARN_UNUSED_FUNCTION = YES; 299 | GCC_WARN_UNUSED_VARIABLE = YES; 300 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 301 | MTL_ENABLE_DEBUG_INFO = YES; 302 | ONLY_ACTIVE_ARCH = YES; 303 | SDKROOT = iphoneos; 304 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 305 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 306 | }; 307 | name = Debug; 308 | }; 309 | 48D016EC20F27B5800061B7E /* Release */ = { 310 | isa = XCBuildConfiguration; 311 | buildSettings = { 312 | ALWAYS_SEARCH_USER_PATHS = NO; 313 | CLANG_ANALYZER_NONNULL = YES; 314 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 315 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 316 | CLANG_CXX_LIBRARY = "libc++"; 317 | CLANG_ENABLE_MODULES = YES; 318 | CLANG_ENABLE_OBJC_ARC = YES; 319 | CLANG_ENABLE_OBJC_WEAK = YES; 320 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 321 | CLANG_WARN_BOOL_CONVERSION = YES; 322 | CLANG_WARN_COMMA = YES; 323 | CLANG_WARN_CONSTANT_CONVERSION = YES; 324 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 325 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 326 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 327 | CLANG_WARN_EMPTY_BODY = YES; 328 | CLANG_WARN_ENUM_CONVERSION = YES; 329 | CLANG_WARN_INFINITE_RECURSION = YES; 330 | CLANG_WARN_INT_CONVERSION = YES; 331 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 332 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 333 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 334 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 335 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 336 | CLANG_WARN_STRICT_PROTOTYPES = YES; 337 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 338 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 339 | CLANG_WARN_UNREACHABLE_CODE = YES; 340 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 341 | CODE_SIGN_IDENTITY = "iPhone Developer"; 342 | COPY_PHASE_STRIP = NO; 343 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 344 | ENABLE_NS_ASSERTIONS = NO; 345 | ENABLE_STRICT_OBJC_MSGSEND = YES; 346 | GCC_C_LANGUAGE_STANDARD = gnu11; 347 | GCC_NO_COMMON_BLOCKS = YES; 348 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 349 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 350 | GCC_WARN_UNDECLARED_SELECTOR = YES; 351 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 352 | GCC_WARN_UNUSED_FUNCTION = YES; 353 | GCC_WARN_UNUSED_VARIABLE = YES; 354 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 355 | MTL_ENABLE_DEBUG_INFO = NO; 356 | SDKROOT = iphoneos; 357 | SWIFT_COMPILATION_MODE = wholemodule; 358 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 359 | VALIDATE_PRODUCT = YES; 360 | }; 361 | name = Release; 362 | }; 363 | 48D016EE20F27B5800061B7E /* Debug */ = { 364 | isa = XCBuildConfiguration; 365 | buildSettings = { 366 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 367 | CODE_SIGN_STYLE = Automatic; 368 | INFOPLIST_FILE = NetworkLayerSetup/Info.plist; 369 | LD_RUNPATH_SEARCH_PATHS = ( 370 | "$(inherited)", 371 | "@executable_path/Frameworks", 372 | ); 373 | PRODUCT_BUNDLE_IDENTIFIER = com.assignment.app.NetworkLayerSetup; 374 | PRODUCT_NAME = "$(TARGET_NAME)"; 375 | SWIFT_VERSION = 4.0; 376 | TARGETED_DEVICE_FAMILY = "1,2"; 377 | }; 378 | name = Debug; 379 | }; 380 | 48D016EF20F27B5800061B7E /* Release */ = { 381 | isa = XCBuildConfiguration; 382 | buildSettings = { 383 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 384 | CODE_SIGN_STYLE = Automatic; 385 | INFOPLIST_FILE = NetworkLayerSetup/Info.plist; 386 | LD_RUNPATH_SEARCH_PATHS = ( 387 | "$(inherited)", 388 | "@executable_path/Frameworks", 389 | ); 390 | PRODUCT_BUNDLE_IDENTIFIER = com.assignment.app.NetworkLayerSetup; 391 | PRODUCT_NAME = "$(TARGET_NAME)"; 392 | SWIFT_VERSION = 4.0; 393 | TARGETED_DEVICE_FAMILY = "1,2"; 394 | }; 395 | name = Release; 396 | }; 397 | /* End XCBuildConfiguration section */ 398 | 399 | /* Begin XCConfigurationList section */ 400 | 48D016D620F27B4D00061B7E /* Build configuration list for PBXProject "NetworkLayerSetup" */ = { 401 | isa = XCConfigurationList; 402 | buildConfigurations = ( 403 | 48D016EB20F27B5800061B7E /* Debug */, 404 | 48D016EC20F27B5800061B7E /* Release */, 405 | ); 406 | defaultConfigurationIsVisible = 0; 407 | defaultConfigurationName = Release; 408 | }; 409 | 48D016ED20F27B5800061B7E /* Build configuration list for PBXNativeTarget "NetworkLayerSetup" */ = { 410 | isa = XCConfigurationList; 411 | buildConfigurations = ( 412 | 48D016EE20F27B5800061B7E /* Debug */, 413 | 48D016EF20F27B5800061B7E /* Release */, 414 | ); 415 | defaultConfigurationIsVisible = 0; 416 | defaultConfigurationName = Release; 417 | }; 418 | /* End XCConfigurationList section */ 419 | }; 420 | rootObject = 48D016D320F27B4D00061B7E /* Project object */; 421 | } 422 | -------------------------------------------------------------------------------- /NetworkLayerSetup.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /NetworkLayerSetup.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /NetworkLayerSetup.xcodeproj/xcuserdata/Xoriant.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | NetworkLayerSetup.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /NetworkLayerSetup/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/8/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /NetworkLayerSetup/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 | } -------------------------------------------------------------------------------- /NetworkLayerSetup/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /NetworkLayerSetup/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 | -------------------------------------------------------------------------------- /NetworkLayerSetup/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 | -------------------------------------------------------------------------------- /NetworkLayerSetup/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 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /NetworkLayerSetup/Model/Model1.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Model1.swift, Model2.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/9/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Model1: Decodable { 12 | let key1: String? 13 | let key2: String? 14 | let key3: String? 15 | let key4: String? 16 | let key5: String? 17 | let key6: String? 18 | } 19 | 20 | struct Model2: Decodable { 21 | let results: [Model1]? 22 | } 23 | -------------------------------------------------------------------------------- /NetworkLayerSetup/Networking/ErrorHandling/APIError.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APIError.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/8/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum APIError: Error { 12 | case invalidData 13 | case requestFailed 14 | case jsonConversionFailure 15 | case jsonParsingFailure 16 | case responseUnsuccessful 17 | 18 | var localizedDescription: String { 19 | switch self { 20 | case .invalidData: 21 | return "Invalid Data" 22 | case .requestFailed: 23 | return "Request Failed" 24 | case .jsonConversionFailure: 25 | return "JSON Conversion Failure" 26 | case .jsonParsingFailure: 27 | return "JSON Parsing Failure" 28 | case .responseUnsuccessful: 29 | return "Response Unsuccessful" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /NetworkLayerSetup/Networking/Manager/APIClient.swift: -------------------------------------------------------------------------------- 1 | // 2 | // APIClient.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/9/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | // Code for generic API calling and decoding of response 12 | 13 | protocol APIClient { 14 | var session: URLSession { get } 15 | func callAPI (with request: URLRequest, decode: @escaping (Decodable) -> T?, 16 | completion: @escaping (Result) -> Void) 17 | } 18 | 19 | extension APIClient { 20 | typealias jsonTaskCompletionHandler = (Decodable?, APIError?) -> Void 21 | 22 | private func decodingTask (with request: URLRequest, decodingType: T.Type, completion: @escaping jsonTaskCompletionHandler) -> URLSessionDataTask { 23 | 24 | let task = session.dataTask(with: request) { (data, response, error) in 25 | guard let httpResponse = response as? HTTPURLResponse else { 26 | completion(nil, .requestFailed) 27 | return 28 | } 29 | 30 | if httpResponse.statusCode == 200 { 31 | if let data = data { 32 | do { 33 | let genericModel = try JSONDecoder().decode(decodingType, from: data) 34 | completion(genericModel, nil) 35 | } catch { 36 | completion(nil, .jsonConversionFailure) 37 | } 38 | } else { 39 | completion(nil, .invalidData) 40 | } 41 | } else { 42 | completion(nil, .responseUnsuccessful) 43 | } 44 | } 45 | return task 46 | } 47 | 48 | func callAPI (with request: URLRequest, decode: @escaping (Decodable) -> T?, 49 | completion: @escaping (Result) -> Void) { 50 | let task = decodingTask(with: request, decodingType: T.self) { (json, error) in 51 | 52 | // Switch to main queue 53 | DispatchQueue.main.async { 54 | guard let json = json else { 55 | if let error = error { 56 | completion(Result.failure(error)) 57 | } else { 58 | completion(Result.failure(.invalidData)) 59 | } 60 | return 61 | } 62 | 63 | if let value = decode(json) { 64 | completion(Result.success(value)) 65 | } else { 66 | completion(Result.failure(.jsonParsingFailure)) 67 | } 68 | } 69 | } 70 | task.resume() 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /NetworkLayerSetup/Networking/Manager/MyClient.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MyClient.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/9/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | class MyClient: APIClient { 12 | 13 | var session: URLSession 14 | 15 | init(configuration: URLSessionConfiguration) { 16 | self.session = URLSession(configuration: configuration) 17 | } 18 | 19 | convenience init() { 20 | self.init(configuration: .default) 21 | } 22 | } 23 | 24 | // MARK: - API Request calls 25 | 26 | extension MyClient { 27 | //In the signature of the function we define the Class type that is the generic one in the API 28 | func getSomething(from endpoint: Endpoint, completion: @escaping (Result) -> Void) { 29 | 30 | let request = endpoint.request 31 | 32 | callAPI(with: request, decode: { json -> Model2? in 33 | guard let model2 = json as? Model2 else { return nil } 34 | return model2 35 | }, completion: completion) 36 | } 37 | } 38 | 39 | -------------------------------------------------------------------------------- /NetworkLayerSetup/Networking/Request/API.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EndpointList.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/8/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum API: String { 12 | case api1 = "api1/string/value" 13 | case api2 = "api2/string/value" 14 | 15 | // To get the API endpoint with request setup 16 | func getAPIEndpoint(queryItems: [URLQueryItem] = [], headers: HTTPHeaders = [ : ], body: Data = Data()) -> Endpoint { 17 | return Endpoint(path: self.rawValue, httpMethod: .post, headers: headers, body: body, queryItems: queryItems) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /NetworkLayerSetup/Networking/Request/Endpoint.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Endpoint.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/8/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | public typealias HTTPHeaders = [String:String] 12 | 13 | enum HTTPMethod: String { 14 | case get = "GET" 15 | case post = "POST" 16 | case put = "PUT" 17 | case delete = "DELETE" 18 | case patch = "PATCH" 19 | case head = "HEAD" 20 | case trace = "TRACE" 21 | case connect = "CONNECT" 22 | case options = "OPTIONS" 23 | } 24 | 25 | public struct Endpoint { 26 | var path: String 27 | var httpMethod: HTTPMethod 28 | var headers: HTTPHeaders? 29 | var body: Data? 30 | var queryItems: [URLQueryItem]? 31 | } 32 | 33 | // MARK: - Request Setup 34 | 35 | extension Endpoint { 36 | 37 | var urlComponents: URLComponents { 38 | let base: String = "your/base/string" 39 | var component = URLComponents(string: base)! 40 | component.path = path 41 | component.queryItems = queryItems 42 | return component 43 | } 44 | 45 | var request: URLRequest { 46 | var request = URLRequest(url: urlComponents.url!) 47 | request.httpMethod = httpMethod.rawValue 48 | request.httpBody = body 49 | if let headers = headers { 50 | for(headerField, headerValue) in headers { 51 | request.setValue(headerValue, forHTTPHeaderField: headerField) 52 | } 53 | } 54 | request.httpShouldHandleCookies = true 55 | return request 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /NetworkLayerSetup/Networking/Response/Result.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Result.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/8/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | enum Result where E: Error { 12 | case success(T) 13 | case failure(E) 14 | } 15 | -------------------------------------------------------------------------------- /NetworkLayerSetup/ViewControllers/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // NetworkLayerSetup 4 | // 5 | // Created by Sayalee on 7/8/18. 6 | // Copyright © 2018 Assignment. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | private let client = MyClient() 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | callAPI1() 18 | } 19 | 20 | override func didReceiveMemoryWarning() { 21 | super.didReceiveMemoryWarning() 22 | } 23 | 24 | // MARK:- API Calls 25 | 26 | func callAPI1() { 27 | 28 | // Query item 29 | let queryItem = [ URLQueryItem(name: "keyName", value: "ValueName") ] 30 | 31 | /* 32 | // Body as string 33 | let bodyString = "yourParameterString" 34 | let body = bodyString.data(using: .utf8) */ 35 | 36 | // Body as dictionary 37 | let parameters : [String : Any] = [ "key1" : "value1", "key2": "value2" ] 38 | guard let body = try? JSONSerialization.data(withJSONObject: parameters) else { return } 39 | 40 | // Headers 41 | let headers: [String: String] = [ "Header-key1": "value1", 42 | "Header-key2": "value2" ] 43 | 44 | let api: API = .api1 45 | let endpoint: Endpoint = api.getAPIEndpoint(queryItems: queryItem, headers: headers, body: body) 46 | 47 | client.getSomething(from: endpoint) { [weak self] result in 48 | switch result { 49 | case .success(let model2Result): 50 | guard let model2Result = model2Result?.results else { return } 51 | print(model2Result) 52 | case .failure(let error): 53 | print("the error \(error)") 54 | } 55 | } 56 | } 57 | 58 | } 59 | 60 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetworkLayerSetup 2 | A generic network layer in iOS with Swift 4 using protocol programming. 3 |
4 | This is an easy setup for networking in iOS without any third party framework.
5 | Helps you make GET, POST, DELETE, PUT, etc calls and decode the JSON response to required model type without too much of boilerplate code. 6 | --------------------------------------------------------------------------------