├── AnyCodable.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── shopback.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── shopback.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── AnyCodable ├── AnyCodable.h ├── DecodingContainer+AnyCollection.swift ├── EncodingContainer+AnyCollection.swift └── Info.plist ├── AnyCodableTests ├── AnyCodingKeyTests.swift ├── DecodingContainer+AnyCollectionTests.swift ├── EncodingContainer+AnyCollectionTests.swift ├── Info.plist ├── MockCodableIfPresentObject.swift └── MockCodableObject.swift ├── DynamicCodable.podspec ├── LICENSE ├── README.md ├── icon.png └── icon.sketch /AnyCodable.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 8D746EE621F2F28D00C0A07C /* AnyCodable.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8D746EDC21F2F28C00C0A07C /* AnyCodable.framework */; }; 11 | 8D746EED21F2F28D00C0A07C /* AnyCodable.h in Headers */ = {isa = PBXBuildFile; fileRef = 8D746EDF21F2F28C00C0A07C /* AnyCodable.h */; settings = {ATTRIBUTES = (Public, ); }; }; 12 | 8D746EF821F2F29C00C0A07C /* EncodingContainer+AnyCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746EF621F2F29B00C0A07C /* EncodingContainer+AnyCollection.swift */; }; 13 | 8D746EF921F2F29C00C0A07C /* DecodingContainer+AnyCollection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746EF721F2F29B00C0A07C /* DecodingContainer+AnyCollection.swift */; }; 14 | 8D746EFF21F2F2A900C0A07C /* AnyCodingKeyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746EFA21F2F2A900C0A07C /* AnyCodingKeyTests.swift */; }; 15 | 8D746F0021F2F2A900C0A07C /* EncodingContainer+AnyCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746EFB21F2F2A900C0A07C /* EncodingContainer+AnyCollectionTests.swift */; }; 16 | 8D746F0121F2F2A900C0A07C /* MockCodableIfPresentObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746EFC21F2F2A900C0A07C /* MockCodableIfPresentObject.swift */; }; 17 | 8D746F0221F2F2A900C0A07C /* MockCodableObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746EFD21F2F2A900C0A07C /* MockCodableObject.swift */; }; 18 | 8D746F0321F2F2A900C0A07C /* DecodingContainer+AnyCollectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D746EFE21F2F2A900C0A07C /* DecodingContainer+AnyCollectionTests.swift */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXContainerItemProxy section */ 22 | 8D746EE721F2F28D00C0A07C /* PBXContainerItemProxy */ = { 23 | isa = PBXContainerItemProxy; 24 | containerPortal = 8D746ED321F2F28C00C0A07C /* Project object */; 25 | proxyType = 1; 26 | remoteGlobalIDString = 8D746EDB21F2F28C00C0A07C; 27 | remoteInfo = AnyCodable; 28 | }; 29 | /* End PBXContainerItemProxy section */ 30 | 31 | /* Begin PBXFileReference section */ 32 | 8D746EDC21F2F28C00C0A07C /* AnyCodable.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AnyCodable.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 8D746EDF21F2F28C00C0A07C /* AnyCodable.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AnyCodable.h; sourceTree = ""; }; 34 | 8D746EE021F2F28C00C0A07C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 35 | 8D746EE521F2F28D00C0A07C /* AnyCodableTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = AnyCodableTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | 8D746EEC21F2F28D00C0A07C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 37 | 8D746EF621F2F29B00C0A07C /* EncodingContainer+AnyCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "EncodingContainer+AnyCollection.swift"; sourceTree = ""; }; 38 | 8D746EF721F2F29B00C0A07C /* DecodingContainer+AnyCollection.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DecodingContainer+AnyCollection.swift"; sourceTree = ""; }; 39 | 8D746EFA21F2F2A900C0A07C /* AnyCodingKeyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCodingKeyTests.swift; sourceTree = ""; }; 40 | 8D746EFB21F2F2A900C0A07C /* EncodingContainer+AnyCollectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "EncodingContainer+AnyCollectionTests.swift"; sourceTree = ""; }; 41 | 8D746EFC21F2F2A900C0A07C /* MockCodableIfPresentObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockCodableIfPresentObject.swift; sourceTree = ""; }; 42 | 8D746EFD21F2F2A900C0A07C /* MockCodableObject.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockCodableObject.swift; sourceTree = ""; }; 43 | 8D746EFE21F2F2A900C0A07C /* DecodingContainer+AnyCollectionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DecodingContainer+AnyCollectionTests.swift"; sourceTree = ""; }; 44 | /* End PBXFileReference section */ 45 | 46 | /* Begin PBXFrameworksBuildPhase section */ 47 | 8D746ED921F2F28C00C0A07C /* Frameworks */ = { 48 | isa = PBXFrameworksBuildPhase; 49 | buildActionMask = 2147483647; 50 | files = ( 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | 8D746EE221F2F28D00C0A07C /* Frameworks */ = { 55 | isa = PBXFrameworksBuildPhase; 56 | buildActionMask = 2147483647; 57 | files = ( 58 | 8D746EE621F2F28D00C0A07C /* AnyCodable.framework in Frameworks */, 59 | ); 60 | runOnlyForDeploymentPostprocessing = 0; 61 | }; 62 | /* End PBXFrameworksBuildPhase section */ 63 | 64 | /* Begin PBXGroup section */ 65 | 8D746ED221F2F28C00C0A07C = { 66 | isa = PBXGroup; 67 | children = ( 68 | 8D746EDE21F2F28C00C0A07C /* AnyCodable */, 69 | 8D746EE921F2F28D00C0A07C /* AnyCodableTests */, 70 | 8D746EDD21F2F28C00C0A07C /* Products */, 71 | ); 72 | sourceTree = ""; 73 | }; 74 | 8D746EDD21F2F28C00C0A07C /* Products */ = { 75 | isa = PBXGroup; 76 | children = ( 77 | 8D746EDC21F2F28C00C0A07C /* AnyCodable.framework */, 78 | 8D746EE521F2F28D00C0A07C /* AnyCodableTests.xctest */, 79 | ); 80 | name = Products; 81 | sourceTree = ""; 82 | }; 83 | 8D746EDE21F2F28C00C0A07C /* AnyCodable */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 8D746EDF21F2F28C00C0A07C /* AnyCodable.h */, 87 | 8D746EF721F2F29B00C0A07C /* DecodingContainer+AnyCollection.swift */, 88 | 8D746EF621F2F29B00C0A07C /* EncodingContainer+AnyCollection.swift */, 89 | 8D746EE021F2F28C00C0A07C /* Info.plist */, 90 | ); 91 | path = AnyCodable; 92 | sourceTree = ""; 93 | }; 94 | 8D746EE921F2F28D00C0A07C /* AnyCodableTests */ = { 95 | isa = PBXGroup; 96 | children = ( 97 | 8D746EFA21F2F2A900C0A07C /* AnyCodingKeyTests.swift */, 98 | 8D746EFE21F2F2A900C0A07C /* DecodingContainer+AnyCollectionTests.swift */, 99 | 8D746EFB21F2F2A900C0A07C /* EncodingContainer+AnyCollectionTests.swift */, 100 | 8D746EFC21F2F2A900C0A07C /* MockCodableIfPresentObject.swift */, 101 | 8D746EFD21F2F2A900C0A07C /* MockCodableObject.swift */, 102 | 8D746EEC21F2F28D00C0A07C /* Info.plist */, 103 | ); 104 | path = AnyCodableTests; 105 | sourceTree = ""; 106 | }; 107 | /* End PBXGroup section */ 108 | 109 | /* Begin PBXHeadersBuildPhase section */ 110 | 8D746ED721F2F28C00C0A07C /* Headers */ = { 111 | isa = PBXHeadersBuildPhase; 112 | buildActionMask = 2147483647; 113 | files = ( 114 | 8D746EED21F2F28D00C0A07C /* AnyCodable.h in Headers */, 115 | ); 116 | runOnlyForDeploymentPostprocessing = 0; 117 | }; 118 | /* End PBXHeadersBuildPhase section */ 119 | 120 | /* Begin PBXNativeTarget section */ 121 | 8D746EDB21F2F28C00C0A07C /* AnyCodable */ = { 122 | isa = PBXNativeTarget; 123 | buildConfigurationList = 8D746EF021F2F28D00C0A07C /* Build configuration list for PBXNativeTarget "AnyCodable" */; 124 | buildPhases = ( 125 | 8D746ED721F2F28C00C0A07C /* Headers */, 126 | 8D746ED821F2F28C00C0A07C /* Sources */, 127 | 8D746ED921F2F28C00C0A07C /* Frameworks */, 128 | 8D746EDA21F2F28C00C0A07C /* Resources */, 129 | ); 130 | buildRules = ( 131 | ); 132 | dependencies = ( 133 | ); 134 | name = AnyCodable; 135 | productName = AnyCodable; 136 | productReference = 8D746EDC21F2F28C00C0A07C /* AnyCodable.framework */; 137 | productType = "com.apple.product-type.framework"; 138 | }; 139 | 8D746EE421F2F28D00C0A07C /* AnyCodableTests */ = { 140 | isa = PBXNativeTarget; 141 | buildConfigurationList = 8D746EF321F2F28D00C0A07C /* Build configuration list for PBXNativeTarget "AnyCodableTests" */; 142 | buildPhases = ( 143 | 8D746EE121F2F28D00C0A07C /* Sources */, 144 | 8D746EE221F2F28D00C0A07C /* Frameworks */, 145 | 8D746EE321F2F28D00C0A07C /* Resources */, 146 | ); 147 | buildRules = ( 148 | ); 149 | dependencies = ( 150 | 8D746EE821F2F28D00C0A07C /* PBXTargetDependency */, 151 | ); 152 | name = AnyCodableTests; 153 | productName = AnyCodableTests; 154 | productReference = 8D746EE521F2F28D00C0A07C /* AnyCodableTests.xctest */; 155 | productType = "com.apple.product-type.bundle.unit-test"; 156 | }; 157 | /* End PBXNativeTarget section */ 158 | 159 | /* Begin PBXProject section */ 160 | 8D746ED321F2F28C00C0A07C /* Project object */ = { 161 | isa = PBXProject; 162 | attributes = { 163 | LastSwiftUpdateCheck = 1010; 164 | LastUpgradeCheck = 1010; 165 | ORGANIZATIONNAME = levantAJ; 166 | TargetAttributes = { 167 | 8D746EDB21F2F28C00C0A07C = { 168 | CreatedOnToolsVersion = 10.1; 169 | LastSwiftMigration = 1010; 170 | }; 171 | 8D746EE421F2F28D00C0A07C = { 172 | CreatedOnToolsVersion = 10.1; 173 | }; 174 | }; 175 | }; 176 | buildConfigurationList = 8D746ED621F2F28C00C0A07C /* Build configuration list for PBXProject "AnyCodable" */; 177 | compatibilityVersion = "Xcode 9.3"; 178 | developmentRegion = en; 179 | hasScannedForEncodings = 0; 180 | knownRegions = ( 181 | en, 182 | ); 183 | mainGroup = 8D746ED221F2F28C00C0A07C; 184 | productRefGroup = 8D746EDD21F2F28C00C0A07C /* Products */; 185 | projectDirPath = ""; 186 | projectRoot = ""; 187 | targets = ( 188 | 8D746EDB21F2F28C00C0A07C /* AnyCodable */, 189 | 8D746EE421F2F28D00C0A07C /* AnyCodableTests */, 190 | ); 191 | }; 192 | /* End PBXProject section */ 193 | 194 | /* Begin PBXResourcesBuildPhase section */ 195 | 8D746EDA21F2F28C00C0A07C /* Resources */ = { 196 | isa = PBXResourcesBuildPhase; 197 | buildActionMask = 2147483647; 198 | files = ( 199 | ); 200 | runOnlyForDeploymentPostprocessing = 0; 201 | }; 202 | 8D746EE321F2F28D00C0A07C /* Resources */ = { 203 | isa = PBXResourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | ); 207 | runOnlyForDeploymentPostprocessing = 0; 208 | }; 209 | /* End PBXResourcesBuildPhase section */ 210 | 211 | /* Begin PBXSourcesBuildPhase section */ 212 | 8D746ED821F2F28C00C0A07C /* Sources */ = { 213 | isa = PBXSourcesBuildPhase; 214 | buildActionMask = 2147483647; 215 | files = ( 216 | 8D746EF821F2F29C00C0A07C /* EncodingContainer+AnyCollection.swift in Sources */, 217 | 8D746EF921F2F29C00C0A07C /* DecodingContainer+AnyCollection.swift in Sources */, 218 | ); 219 | runOnlyForDeploymentPostprocessing = 0; 220 | }; 221 | 8D746EE121F2F28D00C0A07C /* Sources */ = { 222 | isa = PBXSourcesBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | 8D746F0221F2F2A900C0A07C /* MockCodableObject.swift in Sources */, 226 | 8D746F0121F2F2A900C0A07C /* MockCodableIfPresentObject.swift in Sources */, 227 | 8D746EFF21F2F2A900C0A07C /* AnyCodingKeyTests.swift in Sources */, 228 | 8D746F0021F2F2A900C0A07C /* EncodingContainer+AnyCollectionTests.swift in Sources */, 229 | 8D746F0321F2F2A900C0A07C /* DecodingContainer+AnyCollectionTests.swift in Sources */, 230 | ); 231 | runOnlyForDeploymentPostprocessing = 0; 232 | }; 233 | /* End PBXSourcesBuildPhase section */ 234 | 235 | /* Begin PBXTargetDependency section */ 236 | 8D746EE821F2F28D00C0A07C /* PBXTargetDependency */ = { 237 | isa = PBXTargetDependency; 238 | target = 8D746EDB21F2F28C00C0A07C /* AnyCodable */; 239 | targetProxy = 8D746EE721F2F28D00C0A07C /* PBXContainerItemProxy */; 240 | }; 241 | /* End PBXTargetDependency section */ 242 | 243 | /* Begin XCBuildConfiguration section */ 244 | 8D746EEE21F2F28D00C0A07C /* Debug */ = { 245 | isa = XCBuildConfiguration; 246 | buildSettings = { 247 | ALWAYS_SEARCH_USER_PATHS = NO; 248 | CLANG_ANALYZER_NONNULL = YES; 249 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 250 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 251 | CLANG_CXX_LIBRARY = "libc++"; 252 | CLANG_ENABLE_MODULES = YES; 253 | CLANG_ENABLE_OBJC_ARC = YES; 254 | CLANG_ENABLE_OBJC_WEAK = YES; 255 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 256 | CLANG_WARN_BOOL_CONVERSION = YES; 257 | CLANG_WARN_COMMA = YES; 258 | CLANG_WARN_CONSTANT_CONVERSION = YES; 259 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 260 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 261 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 262 | CLANG_WARN_EMPTY_BODY = YES; 263 | CLANG_WARN_ENUM_CONVERSION = YES; 264 | CLANG_WARN_INFINITE_RECURSION = YES; 265 | CLANG_WARN_INT_CONVERSION = YES; 266 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 267 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 268 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 269 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 270 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 271 | CLANG_WARN_STRICT_PROTOTYPES = YES; 272 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 273 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 274 | CLANG_WARN_UNREACHABLE_CODE = YES; 275 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 276 | CODE_SIGN_IDENTITY = "iPhone Developer"; 277 | COPY_PHASE_STRIP = NO; 278 | CURRENT_PROJECT_VERSION = 1; 279 | DEBUG_INFORMATION_FORMAT = dwarf; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | ENABLE_TESTABILITY = YES; 282 | GCC_C_LANGUAGE_STANDARD = gnu11; 283 | GCC_DYNAMIC_NO_PIC = NO; 284 | GCC_NO_COMMON_BLOCKS = YES; 285 | GCC_OPTIMIZATION_LEVEL = 0; 286 | GCC_PREPROCESSOR_DEFINITIONS = ( 287 | "DEBUG=1", 288 | "$(inherited)", 289 | ); 290 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 291 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 292 | GCC_WARN_UNDECLARED_SELECTOR = YES; 293 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 294 | GCC_WARN_UNUSED_FUNCTION = YES; 295 | GCC_WARN_UNUSED_VARIABLE = YES; 296 | IPHONEOS_DEPLOYMENT_TARGET = 12.1; 297 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 298 | MTL_FAST_MATH = YES; 299 | ONLY_ACTIVE_ARCH = YES; 300 | SDKROOT = iphoneos; 301 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 302 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 303 | VERSIONING_SYSTEM = "apple-generic"; 304 | VERSION_INFO_PREFIX = ""; 305 | }; 306 | name = Debug; 307 | }; 308 | 8D746EEF21F2F28D00C0A07C /* Release */ = { 309 | isa = XCBuildConfiguration; 310 | buildSettings = { 311 | ALWAYS_SEARCH_USER_PATHS = NO; 312 | CLANG_ANALYZER_NONNULL = YES; 313 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 314 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 315 | CLANG_CXX_LIBRARY = "libc++"; 316 | CLANG_ENABLE_MODULES = YES; 317 | CLANG_ENABLE_OBJC_ARC = YES; 318 | CLANG_ENABLE_OBJC_WEAK = YES; 319 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 320 | CLANG_WARN_BOOL_CONVERSION = YES; 321 | CLANG_WARN_COMMA = YES; 322 | CLANG_WARN_CONSTANT_CONVERSION = YES; 323 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 324 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 325 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 326 | CLANG_WARN_EMPTY_BODY = YES; 327 | CLANG_WARN_ENUM_CONVERSION = YES; 328 | CLANG_WARN_INFINITE_RECURSION = YES; 329 | CLANG_WARN_INT_CONVERSION = YES; 330 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 331 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 332 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 333 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 334 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 335 | CLANG_WARN_STRICT_PROTOTYPES = YES; 336 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 337 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 338 | CLANG_WARN_UNREACHABLE_CODE = YES; 339 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 340 | CODE_SIGN_IDENTITY = "iPhone Developer"; 341 | COPY_PHASE_STRIP = NO; 342 | CURRENT_PROJECT_VERSION = 1; 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 = 12.1; 355 | MTL_ENABLE_DEBUG_INFO = NO; 356 | MTL_FAST_MATH = YES; 357 | SDKROOT = iphoneos; 358 | SWIFT_COMPILATION_MODE = wholemodule; 359 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 360 | VALIDATE_PRODUCT = YES; 361 | VERSIONING_SYSTEM = "apple-generic"; 362 | VERSION_INFO_PREFIX = ""; 363 | }; 364 | name = Release; 365 | }; 366 | 8D746EF121F2F28D00C0A07C /* Debug */ = { 367 | isa = XCBuildConfiguration; 368 | buildSettings = { 369 | CLANG_ENABLE_MODULES = YES; 370 | CODE_SIGN_IDENTITY = ""; 371 | CODE_SIGN_STYLE = Automatic; 372 | DEFINES_MODULE = YES; 373 | DYLIB_COMPATIBILITY_VERSION = 1; 374 | DYLIB_CURRENT_VERSION = 1; 375 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 376 | INFOPLIST_FILE = AnyCodable/Info.plist; 377 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 378 | LD_RUNPATH_SEARCH_PATHS = ( 379 | "$(inherited)", 380 | "@executable_path/Frameworks", 381 | "@loader_path/Frameworks", 382 | ); 383 | PRODUCT_BUNDLE_IDENTIFIER = com.levantAJ.AnyCodable; 384 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 385 | SKIP_INSTALL = YES; 386 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 387 | SWIFT_VERSION = 4.2; 388 | TARGETED_DEVICE_FAMILY = "1,2"; 389 | }; 390 | name = Debug; 391 | }; 392 | 8D746EF221F2F28D00C0A07C /* Release */ = { 393 | isa = XCBuildConfiguration; 394 | buildSettings = { 395 | CLANG_ENABLE_MODULES = YES; 396 | CODE_SIGN_IDENTITY = ""; 397 | CODE_SIGN_STYLE = Automatic; 398 | DEFINES_MODULE = YES; 399 | DYLIB_COMPATIBILITY_VERSION = 1; 400 | DYLIB_CURRENT_VERSION = 1; 401 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 402 | INFOPLIST_FILE = AnyCodable/Info.plist; 403 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 404 | LD_RUNPATH_SEARCH_PATHS = ( 405 | "$(inherited)", 406 | "@executable_path/Frameworks", 407 | "@loader_path/Frameworks", 408 | ); 409 | PRODUCT_BUNDLE_IDENTIFIER = com.levantAJ.AnyCodable; 410 | PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; 411 | SKIP_INSTALL = YES; 412 | SWIFT_VERSION = 4.2; 413 | TARGETED_DEVICE_FAMILY = "1,2"; 414 | }; 415 | name = Release; 416 | }; 417 | 8D746EF421F2F28D00C0A07C /* Debug */ = { 418 | isa = XCBuildConfiguration; 419 | buildSettings = { 420 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 421 | CODE_SIGN_STYLE = Automatic; 422 | INFOPLIST_FILE = AnyCodableTests/Info.plist; 423 | LD_RUNPATH_SEARCH_PATHS = ( 424 | "$(inherited)", 425 | "@executable_path/Frameworks", 426 | "@loader_path/Frameworks", 427 | ); 428 | PRODUCT_BUNDLE_IDENTIFIER = com.levantAJ.AnyCodableTests; 429 | PRODUCT_NAME = "$(TARGET_NAME)"; 430 | SWIFT_VERSION = 4.2; 431 | TARGETED_DEVICE_FAMILY = "1,2"; 432 | }; 433 | name = Debug; 434 | }; 435 | 8D746EF521F2F28D00C0A07C /* Release */ = { 436 | isa = XCBuildConfiguration; 437 | buildSettings = { 438 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 439 | CODE_SIGN_STYLE = Automatic; 440 | INFOPLIST_FILE = AnyCodableTests/Info.plist; 441 | LD_RUNPATH_SEARCH_PATHS = ( 442 | "$(inherited)", 443 | "@executable_path/Frameworks", 444 | "@loader_path/Frameworks", 445 | ); 446 | PRODUCT_BUNDLE_IDENTIFIER = com.levantAJ.AnyCodableTests; 447 | PRODUCT_NAME = "$(TARGET_NAME)"; 448 | SWIFT_VERSION = 4.2; 449 | TARGETED_DEVICE_FAMILY = "1,2"; 450 | }; 451 | name = Release; 452 | }; 453 | /* End XCBuildConfiguration section */ 454 | 455 | /* Begin XCConfigurationList section */ 456 | 8D746ED621F2F28C00C0A07C /* Build configuration list for PBXProject "AnyCodable" */ = { 457 | isa = XCConfigurationList; 458 | buildConfigurations = ( 459 | 8D746EEE21F2F28D00C0A07C /* Debug */, 460 | 8D746EEF21F2F28D00C0A07C /* Release */, 461 | ); 462 | defaultConfigurationIsVisible = 0; 463 | defaultConfigurationName = Release; 464 | }; 465 | 8D746EF021F2F28D00C0A07C /* Build configuration list for PBXNativeTarget "AnyCodable" */ = { 466 | isa = XCConfigurationList; 467 | buildConfigurations = ( 468 | 8D746EF121F2F28D00C0A07C /* Debug */, 469 | 8D746EF221F2F28D00C0A07C /* Release */, 470 | ); 471 | defaultConfigurationIsVisible = 0; 472 | defaultConfigurationName = Release; 473 | }; 474 | 8D746EF321F2F28D00C0A07C /* Build configuration list for PBXNativeTarget "AnyCodableTests" */ = { 475 | isa = XCConfigurationList; 476 | buildConfigurations = ( 477 | 8D746EF421F2F28D00C0A07C /* Debug */, 478 | 8D746EF521F2F28D00C0A07C /* Release */, 479 | ); 480 | defaultConfigurationIsVisible = 0; 481 | defaultConfigurationName = Release; 482 | }; 483 | /* End XCConfigurationList section */ 484 | }; 485 | rootObject = 8D746ED321F2F28C00C0A07C /* Project object */; 486 | } 487 | -------------------------------------------------------------------------------- /AnyCodable.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /AnyCodable.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /AnyCodable.xcodeproj/project.xcworkspace/xcuserdata/shopback.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/levantAJ/AnyCodable/d15b0420338bf2245ee56510d3f9dbb26e65b94a/AnyCodable.xcodeproj/project.xcworkspace/xcuserdata/shopback.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /AnyCodable.xcodeproj/xcuserdata/shopback.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | AnyCodable.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /AnyCodable/AnyCodable.h: -------------------------------------------------------------------------------- 1 | // 2 | // AnyCodable.h 3 | // AnyCodable 4 | // 5 | // Created by ShopBack on 1/19/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for AnyCodable. 12 | FOUNDATION_EXPORT double AnyCodableVersionNumber; 13 | 14 | //! Project version string for AnyCodable. 15 | FOUNDATION_EXPORT const unsigned char AnyCodableVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /AnyCodable/DecodingContainer+AnyCollection.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DecodingContainer+AnyCollection.swift 3 | // AnyDecodable 4 | // 5 | // Created by levantAJ on 1/18/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct AnyCodingKey: CodingKey { 12 | var stringValue: String 13 | var intValue: Int? 14 | 15 | init?(stringValue: String) { 16 | self.stringValue = stringValue 17 | } 18 | 19 | init?(intValue: Int) { 20 | self.intValue = intValue 21 | self.stringValue = String(intValue) 22 | } 23 | } 24 | 25 | extension KeyedDecodingContainer { 26 | /// Decodes a value of the given type for the given key. 27 | /// 28 | /// - parameter type: The type of value to decode. 29 | /// - parameter key: The key that the decoded value is associated with. 30 | /// - returns: A value of the requested type, if present for the given key 31 | /// and convertible to the requested type. 32 | /// - throws: `DecodingError.typeMismatch` if the encountered encoded value 33 | /// is not convertible to the requested type. 34 | /// - throws: `DecodingError.keyNotFound` if `self` does not have an entry 35 | /// for the given key. 36 | /// - throws: `DecodingError.valueNotFound` if `self` has a null entry for 37 | /// the given key. 38 | public func decode(_ type: [Any].Type, forKey key: KeyedDecodingContainer.Key) throws -> [Any] { 39 | var values = try nestedUnkeyedContainer(forKey: key) 40 | return try values.decode(type) 41 | } 42 | 43 | /// Decodes a value of the given type for the given key. 44 | /// 45 | /// - parameter type: The type of value to decode. 46 | /// - parameter key: The key that the decoded value is associated with. 47 | /// - returns: A value of the requested type, if present for the given key 48 | /// and convertible to the requested type. 49 | /// - throws: `DecodingError.typeMismatch` if the encountered encoded value 50 | /// is not convertible to the requested type. 51 | /// - throws: `DecodingError.keyNotFound` if `self` does not have an entry 52 | /// for the given key. 53 | /// - throws: `DecodingError.valueNotFound` if `self` has a null entry for 54 | /// the given key. 55 | public func decode(_ type: [String: Any].Type, forKey key: KeyedDecodingContainer.Key) throws -> [String: Any] { 56 | let values = try nestedContainer(keyedBy: AnyCodingKey.self, forKey: key) 57 | return try values.decode(type) 58 | } 59 | 60 | /// Decodes a value of the given type for the given key, if present. 61 | /// 62 | /// This method returns `nil` if the container does not have a value 63 | /// associated with `key`, or if the value is null. The difference between 64 | /// these states can be distinguished with a `contains(_:)` call. 65 | /// 66 | /// - parameter type: The type of value to decode. 67 | /// - parameter key: The key that the decoded value is associated with. 68 | /// - returns: A decoded value of the requested type, or `nil` if the 69 | /// `Decoder` does not have an entry associated with the given key, or if 70 | /// the value is a null value. 71 | /// - throws: `DecodingError.typeMismatch` if the encountered encoded value 72 | /// is not convertible to the requested type. 73 | public func decodeIfPresent(_ type: [Any].Type, forKey key: KeyedDecodingContainer.Key) throws -> [Any]? { 74 | guard contains(key), 75 | try decodeNil(forKey: key) == false else { return nil } 76 | return try decode(type, forKey: key) 77 | } 78 | 79 | /// Decodes a value of the given type for the given key, if present. 80 | /// 81 | /// This method returns `nil` if the container does not have a value 82 | /// associated with `key`, or if the value is null. The difference between 83 | /// these states can be distinguished with a `contains(_:)` call. 84 | /// 85 | /// - parameter type: The type of value to decode. 86 | /// - parameter key: The key that the decoded value is associated with. 87 | /// - returns: A decoded value of the requested type, or `nil` if the 88 | /// `Decoder` does not have an entry associated with the given key, or if 89 | /// the value is a null value. 90 | /// - throws: `DecodingError.typeMismatch` if the encountered encoded value 91 | /// is not convertible to the requested type. 92 | public func decodeIfPresent(_ type: [String: Any].Type, forKey key: KeyedDecodingContainer.Key) throws -> [String: Any]? { 93 | guard contains(key), 94 | try decodeNil(forKey: key) == false else { return nil } 95 | return try decode(type, forKey: key) 96 | } 97 | } 98 | 99 | private extension KeyedDecodingContainer { 100 | func decode(_ type: [String: Any].Type) throws -> [String: Any] { 101 | var dictionary: [String: Any] = [:] 102 | for key in allKeys { 103 | if try decodeNil(forKey: key) { 104 | dictionary[key.stringValue] = NSNull() 105 | } else if let bool = try? decode(Bool.self, forKey: key) { 106 | dictionary[key.stringValue] = bool 107 | } else if let string = try? decode(String.self, forKey: key) { 108 | dictionary[key.stringValue] = string 109 | } else if let int = try? decode(Int.self, forKey: key) { 110 | dictionary[key.stringValue] = int 111 | } else if let double = try? decode(Double.self, forKey: key) { 112 | dictionary[key.stringValue] = double 113 | } else if let dict = try? decode([String: Any].self, forKey: key) { 114 | dictionary[key.stringValue] = dict 115 | } else if let array = try? decode([Any].self, forKey: key) { 116 | dictionary[key.stringValue] = array 117 | } 118 | } 119 | return dictionary 120 | } 121 | } 122 | 123 | private extension UnkeyedDecodingContainer { 124 | mutating func decode(_ type: [Any].Type) throws -> [Any] { 125 | var elements: [Any] = [] 126 | while !isAtEnd { 127 | if try decodeNil() { 128 | elements.append(NSNull()) 129 | } else if let int = try? decode(Int.self) { 130 | elements.append(int) 131 | } else if let bool = try? decode(Bool.self) { 132 | elements.append(bool) 133 | } else if let double = try? decode(Double.self) { 134 | elements.append(double) 135 | } else if let string = try? decode(String.self) { 136 | elements.append(string) 137 | } else if let values = try? nestedContainer(keyedBy: AnyCodingKey.self), 138 | let element = try? values.decode([String: Any].self) { 139 | elements.append(element) 140 | } else if var values = try? nestedUnkeyedContainer(), 141 | let element = try? values.decode([Any].self) { 142 | elements.append(element) 143 | } 144 | } 145 | return elements 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /AnyCodable/EncodingContainer+AnyCollection.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EncodingContainer+AnyCollection.swift 3 | // AnyDecodable 4 | // 5 | // Created by ShopBack on 1/19/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | extension KeyedEncodingContainer { 12 | /// Encodes the given value for the given key. 13 | /// 14 | /// - parameter value: The value to encode. 15 | /// - parameter key: The key to associate the value with. 16 | /// - throws: `EncodingError.invalidValue` if the given value is invalid in 17 | /// the current context for this format. 18 | public mutating func encode(_ value: [String: Any], forKey key: KeyedEncodingContainer.Key) throws { 19 | var container = nestedContainer(keyedBy: AnyCodingKey.self, forKey: key) 20 | try container.encode(value) 21 | } 22 | 23 | /// Encodes the given value for the given key. 24 | /// 25 | /// - parameter value: The value to encode. 26 | /// - parameter key: The key to associate the value with. 27 | /// - throws: `EncodingError.invalidValue` if the given value is invalid in 28 | /// the current context for this format. 29 | public mutating func encode(_ value: [Any], forKey key: KeyedEncodingContainer.Key) throws { 30 | var container = nestedUnkeyedContainer(forKey: key) 31 | try container.encode(value) 32 | } 33 | 34 | /// Encodes the given value for the given key if it is not `nil`. 35 | /// 36 | /// - parameter value: The value to encode. 37 | /// - parameter key: The key to associate the value with. 38 | /// - throws: `EncodingError.invalidValue` if the given value is invalid in 39 | /// the current context for this format. 40 | public mutating func encodeIfPresent(_ value: [String: Any]?, forKey key: KeyedEncodingContainer.Key) throws { 41 | if let value = value { 42 | var container = nestedContainer(keyedBy: AnyCodingKey.self, forKey: key) 43 | try container.encode(value) 44 | } else { 45 | try encodeNil(forKey: key) 46 | } 47 | } 48 | 49 | /// Encodes the given value for the given key if it is not `nil`. 50 | /// 51 | /// - parameter value: The value to encode. 52 | /// - parameter key: The key to associate the value with. 53 | /// - throws: `EncodingError.invalidValue` if the given value is invalid in 54 | /// the current context for this format. 55 | public mutating func encodeIfPresent(_ value: [Any]?, forKey key: KeyedEncodingContainer.Key) throws { 56 | if let value = value { 57 | var container = nestedUnkeyedContainer(forKey: key) 58 | try container.encode(value) 59 | } else { 60 | try encodeNil(forKey: key) 61 | } 62 | } 63 | } 64 | 65 | private extension KeyedEncodingContainer where K == AnyCodingKey { 66 | mutating func encode(_ value: [String: Any]) throws { 67 | for (k, v) in value { 68 | let key = AnyCodingKey(stringValue: k)! 69 | switch v { 70 | case is NSNull: 71 | try encodeNil(forKey: key) 72 | case let string as String: 73 | try encode(string, forKey: key) 74 | case let int as Int: 75 | try encode(int, forKey: key) 76 | case let bool as Bool: 77 | try encode(bool, forKey: key) 78 | case let double as Double: 79 | try encode(double, forKey: key) 80 | case let dict as [String: Any]: 81 | try encode(dict, forKey: key) 82 | case let array as [Any]: 83 | try encode(array, forKey: key) 84 | default: 85 | debugPrint("⚠️ Unsuported type!", v) 86 | continue 87 | } 88 | } 89 | } 90 | } 91 | 92 | private extension UnkeyedEncodingContainer { 93 | /// Encodes the given value. 94 | /// 95 | /// - parameter value: The value to encode. 96 | /// - throws: `EncodingError.invalidValue` if the given value is invalid in 97 | /// the current context for this format. 98 | mutating func encode(_ value: [Any]) throws { 99 | for v in value { 100 | switch v { 101 | case is NSNull: 102 | try encodeNil() 103 | case let string as String: 104 | try encode(string) 105 | case let int as Int: 106 | try encode(int) 107 | case let bool as Bool: 108 | try encode(bool) 109 | case let double as Double: 110 | try encode(double) 111 | case let dict as [String: Any]: 112 | try encode(dict) 113 | case let array as [Any]: 114 | var values = nestedUnkeyedContainer() 115 | try values.encode(array) 116 | default: 117 | debugPrint("⚠️ Unsuported type!", v) 118 | } 119 | } 120 | } 121 | 122 | /// Encodes the given value. 123 | /// 124 | /// - parameter value: The value to encode. 125 | /// - throws: `EncodingError.invalidValue` if the given value is invalid in 126 | /// the current context for this format. 127 | mutating func encode(_ value: [String: Any]) throws { 128 | var container = self.nestedContainer(keyedBy: AnyCodingKey.self) 129 | try container.encode(value) 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /AnyCodable/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 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | 22 | 23 | -------------------------------------------------------------------------------- /AnyCodableTests/AnyCodingKeyTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AnyCodingKeyTests.swift 3 | // AnyDecodableTests 4 | // 5 | // Created by ShopBack on 1/18/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import AnyCodable 11 | 12 | class AnyCodingKeyTests: XCTestCase { 13 | var sut: AnyCodingKey! 14 | 15 | func testInitStringValue() { 16 | sut = AnyCodingKey(stringValue: "Hello") 17 | XCTAssertEqual(sut.stringValue, "Hello") 18 | XCTAssertNil(sut.intValue) 19 | } 20 | 21 | func testInitIntValue() { 22 | sut = AnyCodingKey(intValue: 123) 23 | XCTAssertEqual(sut.stringValue, "123") 24 | XCTAssertEqual(sut.intValue, 123) 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /AnyCodableTests/DecodingContainer+AnyCollectionTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DecodingContainer+AnyCollectionTests.swift 3 | // AnyDecodableTests 4 | // 5 | // Created by ShopBack on 1/18/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import AnyCodable 11 | 12 | class DecodingContainer_AnyCollectionTests: XCTestCase { 13 | func testDecodeDict() { 14 | let data = """ 15 | {"dict": {"int": 123, "string": "string", "bool": true, "double": 873.436, "null":null, "array": [1, 2, 3, 4], "dict": {"string": "ok lah", "null": null}}, "array": [1, null, false, "string", 345.2346, ["1", "2", "4"], {"key": null}]} 16 | """.data(using: .utf8)! 17 | var sut: MockCodableObject! 18 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableObject.self, from: data)) 19 | XCTAssertEqual(sut.dict["int"] as? Int, 123) 20 | XCTAssertEqual(sut.dict["string"] as? String, "string") 21 | XCTAssertEqual(sut.dict["bool"] as? Bool, true) 22 | XCTAssertEqual(sut.dict["double"] as? Double, 873.436) 23 | XCTAssertTrue(sut.dict["null"] is NSNull) 24 | XCTAssertEqual(sut.dict["array"] as? [Int], [1, 2, 3, 4]) 25 | XCTAssertEqual((sut.dict["dict"] as? [String: Any])?["string"] as? String, "ok lah") 26 | XCTAssertEqual((sut.dict["dict"] as? [String: Any])?["null"] is NSNull, true) 27 | 28 | let array = sut.array 29 | XCTAssertNotNil(array) 30 | XCTAssertEqual(array.count, 7) 31 | XCTAssertTrue(array.contains { $0 is NSNull }) 32 | XCTAssertTrue(array.contains { $0 as? Int == 1 }) 33 | XCTAssertTrue(array.contains { $0 as? String == "string" }) 34 | XCTAssertTrue(array.contains { $0 as? Bool == false }) 35 | XCTAssertTrue(array.contains { $0 as? Double == 345.2346 }) 36 | XCTAssertTrue(array.contains { $0 as? [String] == ["1", "2", "4"] }) 37 | XCTAssertTrue(array.contains(where: { dict -> Bool in 38 | let dict = dict as? [String: Any] 39 | return dict?["key"] is NSNull 40 | })) 41 | } 42 | 43 | func testDecodeDictContainsDict() { 44 | let data = """ 45 | {"dict": {"nestedDict": {"array":[123, null, true, 456.789, "string", [1, 2, 3], {"string":"string", "int": 456, "array": ["9", "8", "7"]}]}}, "array": [1, null, false, "string", 345.2346, ["1", "2", "4"], {"key": null}]} 46 | """.data(using: .utf8)! 47 | var sut: MockCodableObject! 48 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableObject.self, from: data)) 49 | let nestedDict = sut.dict["nestedDict"] as? [String: Any] 50 | let nestedArray = nestedDict?["array"] as? [Any] ?? [] 51 | XCTAssertEqual(nestedArray.count, 7) 52 | XCTAssertTrue(nestedArray.contains { $0 is NSNull }) 53 | XCTAssertTrue(nestedArray.contains { $0 as? Int == 123 }) 54 | XCTAssertTrue(nestedArray.contains { $0 as? String == "string" }) 55 | XCTAssertTrue(nestedArray.contains { $0 as? Bool == true }) 56 | XCTAssertTrue(nestedArray.contains { $0 as? Double == 456.789 }) 57 | XCTAssertTrue(nestedArray.contains { $0 as? [Int] == [1, 2, 3] }) 58 | XCTAssertTrue(nestedArray.contains(where: { dict -> Bool in 59 | let dict = dict as? [String: Any] 60 | return dict?["string"] as? String == "string" 61 | && dict?["int"] as? Int == 456 62 | && dict?["array"] as? [String] == ["9", "8", "7"] 63 | })) 64 | 65 | let array = sut.array 66 | XCTAssertNotNil(array) 67 | XCTAssertEqual(array.count, 7) 68 | XCTAssertTrue(array.contains { $0 is NSNull }) 69 | XCTAssertTrue(array.contains { $0 as? Int == 1 }) 70 | XCTAssertTrue(array.contains { $0 as? String == "string" }) 71 | XCTAssertTrue(array.contains { $0 as? Bool == false }) 72 | XCTAssertTrue(array.contains { $0 as? Double == 345.2346 }) 73 | XCTAssertTrue(array.contains { $0 as? [String] == ["1", "2", "4"] }) 74 | XCTAssertTrue(array.contains(where: { dict -> Bool in 75 | let dict = dict as? [String: Any] 76 | return dict?["key"] is NSNull 77 | })) 78 | } 79 | 80 | func testDecodeDictContainsArray() { 81 | let data = """ 82 | {"dict": {"array": [123, null, true, 456.789, "string", [1, 2, 3], {"string":"string", "int": 456, "array": ["9", "8", "7"]}]}, "array": [1, null, false, "string", 345.2346, ["1", "2", "4"], {"key": null}]} 83 | """.data(using: .utf8)! 84 | var sut: MockCodableObject! 85 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableObject.self, from: data)) 86 | let nestedArray = sut.dict["array"] as? [Any] ?? [] 87 | XCTAssertEqual(nestedArray.count, 7) 88 | XCTAssertTrue(nestedArray.contains { $0 is NSNull }) 89 | XCTAssertTrue(nestedArray.contains { $0 as? Int == 123 }) 90 | XCTAssertTrue(nestedArray.contains { $0 as? String == "string" }) 91 | XCTAssertTrue(nestedArray.contains { $0 as? Bool == true }) 92 | XCTAssertTrue(nestedArray.contains { $0 as? Double == 456.789 }) 93 | XCTAssertTrue(nestedArray.contains { $0 as? [Int] == [1, 2, 3] }) 94 | XCTAssertTrue(nestedArray.contains(where: { dict -> Bool in 95 | let dict = dict as? [String: Any] 96 | return dict?["string"] as? String == "string" 97 | && dict?["int"] as? Int == 456 98 | && dict?["array"] as? [String] == ["9", "8", "7"] 99 | })) 100 | 101 | let array = sut.array 102 | XCTAssertNotNil(array) 103 | XCTAssertEqual(array.count, 7) 104 | XCTAssertTrue(array.contains { $0 is NSNull }) 105 | XCTAssertTrue(array.contains { $0 as? Int == 1 }) 106 | XCTAssertTrue(array.contains { $0 as? String == "string" }) 107 | XCTAssertTrue(array.contains { $0 as? Bool == false }) 108 | XCTAssertTrue(array.contains { $0 as? Double == 345.2346 }) 109 | XCTAssertTrue(array.contains { $0 as? [String] == ["1", "2", "4"] }) 110 | XCTAssertTrue(array.contains(where: { dict -> Bool in 111 | let dict = dict as? [String: Any] 112 | return dict?["key"] is NSNull 113 | })) 114 | } 115 | 116 | func testDecodeIfPresentDict() { 117 | let data = """ 118 | {"dict": {"int": 123, "string": "cool", "bool": true, "double": 873.436, "null": null, "array": [1, 2, 3, 4], "dict": {"string": "ok lah", "null": null}}} 119 | """.data(using: .utf8)! 120 | var sut: MockCodableIfPresentObject! 121 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableIfPresentObject.self, from: data)) 122 | XCTAssertEqual(sut.dict?["int"] as? Int, 123) 123 | XCTAssertEqual(sut.dict?["string"] as? String, "cool") 124 | XCTAssertEqual(sut.dict?["bool"] as? Bool, true) 125 | XCTAssertEqual(sut.dict?["double"] as? Double, 873.436) 126 | XCTAssertTrue(sut.dict?["null"] is NSNull) 127 | XCTAssertEqual(sut.dict?["array"] as? [Int], [1, 2, 3, 4]) 128 | XCTAssertEqual((sut.dict?["dict"] as? [String: Any])?["string"] as? String, "ok lah") 129 | } 130 | 131 | func testDecodeIfPresentDictIsNull() { 132 | let data = "{\"dict\": null, \"array\": null}".data(using: .utf8)! 133 | var sut: MockCodableIfPresentObject! 134 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableIfPresentObject.self, from: data)) 135 | XCTAssertNil(sut.dict) 136 | XCTAssertNil(sut.array) 137 | } 138 | 139 | func testDecodeIfPresentDictIsMissing() { 140 | let data = "{}".data(using: .utf8)! 141 | var sut: MockCodableIfPresentObject! 142 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableIfPresentObject.self, from: data)) 143 | XCTAssertNil(sut.dict) 144 | XCTAssertNil(sut.array) 145 | } 146 | 147 | func testDecodeIfPresentArray() { 148 | let data = """ 149 | {\"array\": [123, null, true, 456.789, "string", [1, 2, 3], {"string":"string", "int": 456, "array": ["9", "8", "7"]}]} 150 | """.data(using: .utf8)! 151 | var sut: MockCodableIfPresentObject! 152 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableIfPresentObject.self, from: data)) 153 | let array = sut.array 154 | XCTAssertEqual(array?.count, 7) 155 | XCTAssertEqual(array?.contains { $0 is NSNull }, true) 156 | XCTAssertEqual(array?.contains { $0 as? Int == 123 }, true) 157 | XCTAssertEqual(array?.contains { $0 as? String == "string" }, true) 158 | XCTAssertEqual(array?.contains { $0 as? Bool == true }, true) 159 | XCTAssertEqual(array?.contains { $0 as? Double == 456.789 }, true) 160 | XCTAssertEqual(array?.contains { $0 as? [Int] == [1, 2, 3] }, true) 161 | XCTAssertEqual(array?.contains(where: { dict -> Bool in 162 | let dict = dict as? [String: Any] 163 | return dict?["string"] as? String == "string" 164 | && dict?["int"] as? Int == 456 165 | && dict?["array"] as? [String] == ["9", "8", "7"] 166 | }), true) 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /AnyCodableTests/EncodingContainer+AnyCollectionTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EncodingContainer+AnyCollectionTests.swift 3 | // AnyDecodableTests 4 | // 5 | // Created by ShopBack on 1/19/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | 11 | class EncodingContainer_AnyCollectionTests: XCTestCase { 12 | func testEncodeDict() { 13 | let expectedSut = MockCodableObject(dict: ["int": 123, "string": "string", "bool": true, "double": 873.436, "null": NSNull(), "array": [1, 2, 3, 4], "dict": ["string": "ok lah", "null": NSNull()]], 14 | array: [1, NSNull(), false, "string", 345.2346, ["1", "2", "4"], ["key": NSNull()]]) 15 | var data: Data! 16 | var sut: MockCodableObject! 17 | XCTAssertNoThrow(data = try JSONEncoder().encode(expectedSut)) 18 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableObject.self, from: data)) 19 | XCTAssertEqual(sut.dict["int"] as? Int, 123) 20 | XCTAssertEqual(sut.dict["string"] as? String, "string") 21 | XCTAssertEqual(sut.dict["bool"] as? Bool, true) 22 | XCTAssertEqual(sut.dict["double"] as? Double, 873.436) 23 | XCTAssertTrue(sut.dict["null"] is NSNull) 24 | XCTAssertEqual(sut.dict["array"] as? [Int], [1, 2, 3, 4]) 25 | XCTAssertEqual((sut.dict["dict"] as? [String: Any])?["string"] as? String, "ok lah") 26 | XCTAssertEqual((sut.dict["dict"] as? [String: Any])?["null"] is NSNull, true) 27 | 28 | let array = sut.array 29 | XCTAssertNotNil(array) 30 | XCTAssertEqual(array.count, 7) 31 | XCTAssertTrue(array.contains { $0 is NSNull }) 32 | XCTAssertTrue(array.contains { $0 as? Int == 1 }) 33 | XCTAssertTrue(array.contains { $0 as? String == "string" }) 34 | XCTAssertTrue(array.contains { $0 as? Bool == false }) 35 | XCTAssertTrue(array.contains { $0 as? Double == 345.2346 }) 36 | XCTAssertTrue(array.contains { $0 as? [String] == ["1", "2", "4"] }) 37 | XCTAssertTrue(array.contains(where: { dict -> Bool in 38 | let dict = dict as? [String: Any] 39 | return dict?["key"] is NSNull 40 | })) 41 | } 42 | 43 | func testEncodeDictContainsDict() { 44 | let expectedSut = MockCodableObject(dict: ["nestedDict": ["array":[123, NSNull(), true, 456.789, "string", [1, 2, 3], ["string": "string", "int": 456, "array": ["9", "8", "7"]]]]], 45 | array: [1, NSNull(), false, "string", 345.2346, ["1", "2", "4"], ["key": NSNull()]]) 46 | var data: Data! 47 | var sut: MockCodableObject! 48 | XCTAssertNoThrow(data = try JSONEncoder().encode(expectedSut)) 49 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableObject.self, from: data)) 50 | let nestedDict = sut.dict["nestedDict"] as? [String: Any] 51 | let nestedArray = nestedDict?["array"] as? [Any] ?? [] 52 | XCTAssertEqual(nestedArray.count, 7) 53 | XCTAssertTrue(nestedArray.contains { $0 is NSNull }) 54 | XCTAssertTrue(nestedArray.contains { $0 as? Int == 123 }) 55 | XCTAssertTrue(nestedArray.contains { $0 as? String == "string" }) 56 | XCTAssertTrue(nestedArray.contains { $0 as? Bool == true }) 57 | XCTAssertTrue(nestedArray.contains { $0 as? Double == 456.789 }) 58 | XCTAssertTrue(nestedArray.contains { $0 as? [Int] == [1, 2, 3] }) 59 | XCTAssertTrue(nestedArray.contains(where: { dict -> Bool in 60 | let dict = dict as? [String: Any] 61 | return dict?["string"] as? String == "string" 62 | && dict?["int"] as? Int == 456 63 | && dict?["array"] as? [String] == ["9", "8", "7"] 64 | })) 65 | 66 | let array = sut.array 67 | XCTAssertNotNil(array) 68 | XCTAssertEqual(array.count, 7) 69 | XCTAssertTrue(array.contains { $0 is NSNull }) 70 | XCTAssertTrue(array.contains { $0 as? Int == 1 }) 71 | XCTAssertTrue(array.contains { $0 as? String == "string" }) 72 | XCTAssertTrue(array.contains { $0 as? Bool == false }) 73 | XCTAssertTrue(array.contains { $0 as? Double == 345.2346 }) 74 | XCTAssertTrue(array.contains { $0 as? [String] == ["1", "2", "4"] }) 75 | XCTAssertTrue(array.contains(where: { dict -> Bool in 76 | let dict = dict as? [String: Any] 77 | return dict?["key"] is NSNull 78 | })) 79 | } 80 | 81 | func testEncodeDictContainsArray() { 82 | let expectedSut = MockCodableObject(dict: ["array": [123, NSNull(), true, 456.789, "string", [1, 2, 3], ["string": "string", "int": 456, "array": ["9", "8", "7"]]]], 83 | array: [1, NSNull(), false, "string", 345.2346, ["1", "2", "4"], ["key": NSNull()]]) 84 | var data: Data! 85 | var sut: MockCodableObject! 86 | XCTAssertNoThrow(data = try JSONEncoder().encode(expectedSut)) 87 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableObject.self, from: data)) 88 | let nestedArray = sut.dict["array"] as? [Any] ?? [] 89 | XCTAssertEqual(nestedArray.count, 7) 90 | XCTAssertTrue(nestedArray.contains { $0 is NSNull }) 91 | XCTAssertTrue(nestedArray.contains { $0 as? Int == 123 }) 92 | XCTAssertTrue(nestedArray.contains { $0 as? String == "string" }) 93 | XCTAssertTrue(nestedArray.contains { $0 as? Bool == true }) 94 | XCTAssertTrue(nestedArray.contains { $0 as? Double == 456.789 }) 95 | XCTAssertTrue(nestedArray.contains { $0 as? [Int] == [1, 2, 3] }) 96 | XCTAssertTrue(nestedArray.contains(where: { dict -> Bool in 97 | let dict = dict as? [String: Any] 98 | return dict?["string"] as? String == "string" 99 | && dict?["int"] as? Int == 456 100 | && dict?["array"] as? [String] == ["9", "8", "7"] 101 | })) 102 | 103 | let array = sut.array 104 | XCTAssertNotNil(array) 105 | XCTAssertEqual(array.count, 7) 106 | XCTAssertTrue(array.contains { $0 is NSNull }) 107 | XCTAssertTrue(array.contains { $0 as? Int == 1 }) 108 | XCTAssertTrue(array.contains { $0 as? String == "string" }) 109 | XCTAssertTrue(array.contains { $0 as? Bool == false }) 110 | XCTAssertTrue(array.contains { $0 as? Double == 345.2346 }) 111 | XCTAssertTrue(array.contains { $0 as? [String] == ["1", "2", "4"] }) 112 | XCTAssertTrue(array.contains(where: { dict -> Bool in 113 | let dict = dict as? [String: Any] 114 | return dict?["key"] is NSNull 115 | })) 116 | } 117 | 118 | func testEncodeIfPresentDict() { 119 | let expectedSut = MockCodableIfPresentObject(dict: ["int": 123, "string": "cool", "bool": true, "double": 873.436, "null": NSNull(), "array": [1, 2, 3, 4], "dict": ["string": "ok lah", "null": NSNull()]], 120 | array: nil) 121 | var data: Data! 122 | var sut: MockCodableIfPresentObject! 123 | XCTAssertNoThrow(data = try JSONEncoder().encode(expectedSut)) 124 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableIfPresentObject.self, from: data)) 125 | XCTAssertEqual(sut.dict?["int"] as? Int, 123) 126 | XCTAssertEqual(sut.dict?["string"] as? String, "cool") 127 | XCTAssertEqual(sut.dict?["bool"] as? Bool, true) 128 | XCTAssertEqual(sut.dict?["double"] as? Double, 873.436) 129 | XCTAssertTrue(sut.dict?["null"] is NSNull) 130 | XCTAssertEqual(sut.dict?["array"] as? [Int], [1, 2, 3, 4]) 131 | XCTAssertEqual((sut.dict?["dict"] as? [String: Any])?["string"] as? String, "ok lah") 132 | } 133 | 134 | func testEncodeIfPresentNil() { 135 | let expectedSut = MockCodableIfPresentObject(dict: nil, array: nil) 136 | var data: Data! 137 | var sut: MockCodableIfPresentObject! 138 | XCTAssertNoThrow(data = try JSONEncoder().encode(expectedSut)) 139 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableIfPresentObject.self, from: data)) 140 | XCTAssertNil(sut.dict) 141 | XCTAssertNil(sut.array) 142 | } 143 | 144 | func testDecodeIfPresentArray() { 145 | let expectedSut = MockCodableIfPresentObject(dict: nil, array: [123, NSNull(), true, 456.789, "string", [1, 2, 3], ["string": "string", "int": 456, "array": ["9", "8", "7"]]]) 146 | var data: Data! 147 | var sut: MockCodableIfPresentObject! 148 | XCTAssertNoThrow(data = try JSONEncoder().encode(expectedSut)) 149 | XCTAssertNoThrow(sut = try JSONDecoder().decode(MockCodableIfPresentObject.self, from: data)) 150 | let array = sut.array 151 | XCTAssertEqual(array?.count, 7) 152 | XCTAssertEqual(array?.contains { $0 is NSNull }, true) 153 | XCTAssertEqual(array?.contains { $0 as? Int == 123 }, true) 154 | XCTAssertEqual(array?.contains { $0 as? String == "string" }, true) 155 | XCTAssertEqual(array?.contains { $0 as? Bool == true }, true) 156 | XCTAssertEqual(array?.contains { $0 as? Double == 456.789 }, true) 157 | XCTAssertEqual(array?.contains { $0 as? [Int] == [1, 2, 3] }, true) 158 | XCTAssertEqual(array?.contains(where: { dict -> Bool in 159 | let dict = dict as? [String: Any] 160 | return dict?["string"] as? String == "string" 161 | && dict?["int"] as? Int == 456 162 | && dict?["array"] as? [String] == ["9", "8", "7"] 163 | }), true) 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /AnyCodableTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /AnyCodableTests/MockCodableIfPresentObject.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MockCodableIfPresentObject.swift 3 | // AnyDecodableTests 4 | // 5 | // Created by ShopBack on 1/19/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct MockCodableIfPresentObject: Codable { 12 | var dict: [String: Any]? 13 | var array: [Any]? 14 | 15 | init(dict: [String: Any]?, array: [Any]?) { 16 | self.dict = dict 17 | self.array = array 18 | } 19 | 20 | enum CodingKeys: String, CodingKey { 21 | case dict 22 | case array 23 | } 24 | 25 | init(from decoder: Decoder) throws { 26 | let values = try decoder.container(keyedBy: CodingKeys.self) 27 | dict = try values.decodeIfPresent([String: Any].self, forKey: .dict) 28 | array = try values.decodeIfPresent([Any].self, forKey: .array) 29 | } 30 | 31 | func encode(to encoder: Encoder) throws { 32 | var container = encoder.container(keyedBy: CodingKeys.self) 33 | try container.encodeIfPresent(dict, forKey: .dict) 34 | try container.encodeIfPresent(array, forKey: .array) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /AnyCodableTests/MockCodableObject.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MockCodableObject.swift 3 | // AnyDecodableTests 4 | // 5 | // Created by ShopBack on 1/19/19. 6 | // Copyright © 2019 levantAJ. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct MockCodableObject: Codable { 12 | var dict: [String: Any] 13 | var array: [Any] 14 | 15 | enum CodingKeys: String, CodingKey { 16 | case dict 17 | case array 18 | } 19 | 20 | init(from decoder: Decoder) throws { 21 | let values = try decoder.container(keyedBy: CodingKeys.self) 22 | dict = try values.decode([String: Any].self, forKey: .dict) 23 | array = try values.decode([Any].self, forKey: .array) 24 | } 25 | 26 | init(dict: [String: Any], array: [Any]) { 27 | self.dict = dict 28 | self.array = array 29 | } 30 | 31 | func encode(to encoder: Encoder) throws { 32 | var container = encoder.container(keyedBy: CodingKeys.self) 33 | try container.encode(dict, forKey: .dict) 34 | try container.encode(array, forKey: .array) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /DynamicCodable.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.module_name = 'DynamicCodable' 3 | s.name = 'DynamicCodable' 4 | s.version = '1.0' 5 | s.license = 'MIT' 6 | s.summary = 'Encode & Decode [String: Any] and [Any]' 7 | s.homepage = 'https://github.com/levantAJ' 8 | s.authors = { 'Tai Le' => 'sirlevantai@gmail.com' } 9 | s.source = { :git => 'https://github.com/levantAJ/AnyCodable.git', :tag => s.version } 10 | s.source_files = 'AnyCodable/**/*.{h,swift}' 11 | s.platform = :ios 12 | s.ios.deployment_target = '8.0' 13 | s.requires_arc = true 14 | end 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 levantAJ 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 |

2 | 3 |

4 | 5 | [![CocoaPods](https://img.shields.io/cocoapods/p/AnyCodable.svg)](https://cocoapods.org/pods/AnyCodable) 6 | [![CocoaPods](https://img.shields.io/cocoapods/v/AnyCodable.svg)](http://cocoapods.org/pods/AnyCodable) 7 | [![Pod License](https://cocoapod-badges.herokuapp.com/l/AnyCodable/badge.png)](https://www.apache.org/licenses/LICENSE-2.0.html) 8 | [![Build Status](https://travis-ci.org/levantAJ/AnyCodable.svg?branch=master)](https://travis-ci.org/levantAJ/AnyCodable) 9 | 10 | # AnyCodable or DynamicCodable 😝 11 | This library to facilitate decode and encode `[String: Any]`, `[Any]` 12 | 13 | ## Requirements 14 | 15 | - iOS 8.0 or later 16 | - Xcode 10.0 or later 17 | 18 | ## Installation 19 | There is a way to use AnyCodable in your project: 20 | 21 | - using CocoaPods 22 | 23 | ### Installation with CocoaPods 24 | 25 | ``` 26 | pod 'DynamicCodable', '1.0' 27 | ``` 28 | ### Build Project 29 | 30 | At this point your workspace should build without error. If you are having problem, post to the Issue and the 31 | community can help you solve it. 32 | 33 | ## How To Use 34 | 35 | ```swift 36 | import DynamicCodable 37 | 38 | struct YourObject: Codable { 39 | var dict: [String: Any] 40 | var array: [Any] 41 | var optionalDict: [String: Any]? 42 | var optionalArray: [Any]? 43 | 44 | enum CodingKeys: String, CodingKey { 45 | case dict 46 | case array 47 | case optionalDict 48 | case optionalArray 49 | } 50 | 51 | init(from decoder: Decoder) throws { 52 | let values = try decoder.container(keyedBy: CodingKeys.self) 53 | dict = try values.decode([String: Any].self, forKey: .dict) 54 | array = try values.decode([Any].self, forKey: .array) 55 | optionalDict = try values.decodeIfPresent([String: Any].self, forKey: .optionalDict) 56 | optionalArray = try values.decodeIfPresent([Any].self, forKey: .optionalArray) 57 | } 58 | 59 | func encode(to encoder: Encoder) throws { 60 | var container = encoder.container(keyedBy: CodingKeys.self) 61 | try container.encode(dict, forKey: .dict) 62 | try container.encode(array, forKey: .array) 63 | try container.encodeIfPresent(optionalDict, forKey: .optionalDict) 64 | try container.encodeIfPresent(optionalArray, forKey: .optionalArray) 65 | } 66 | } 67 | 68 | ``` 69 | 70 | ## Author 71 | - [Tai Le](https://github.com/levantAJ) 72 | 73 | ## Communication 74 | - If you **found a bug**, open an issue. 75 | - If you **have a feature request**, open an issue. 76 | - If you **want to contribute**, submit a pull request. 77 | 78 | ## Licenses 79 | 80 | All source code is licensed under the [MIT License](https://raw.githubusercontent.com/levantAJ/AnyCodable/master/LICENSE). 81 | -------------------------------------------------------------------------------- /icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/levantAJ/AnyCodable/d15b0420338bf2245ee56510d3f9dbb26e65b94a/icon.png -------------------------------------------------------------------------------- /icon.sketch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/levantAJ/AnyCodable/d15b0420338bf2245ee56510d3f9dbb26e65b94a/icon.sketch --------------------------------------------------------------------------------