diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..1683ecc --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,19 @@ +name: Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: macos-latest + + steps: + - uses: actions/checkout@v2 + - name: Build + run: pod install + - name: Run iOS tests + run: xcodebuild test -workspace Alamofire-SwiftyJSON.xcworkspace -scheme AlamofireSwiftyJSON -destination platform="iOS Simulator,name=iPhone 11 Pro" diff --git a/.gitignore b/.gitignore index a3cd143..7b26fb7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,4 @@ DerivedData # you should judge for yourself, the pros and cons are mentioned at: # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control # -# Pods/ +Pods/ diff --git a/.gitmodules b/.gitmodules index a8f67ba..e69de29 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +0,0 @@ -[submodule "SwiftyJSON"] - path = SwiftyJSON - url = https://github.com/SwiftyJSON/SwiftyJSON.git -[submodule "Alamofire"] - path = Alamofire - url = https://github.com/Alamofire/Alamofire.git diff --git a/.swift-version b/.swift-version index 9f55b2c..ef425ca 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -3.0 +5.2 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index de64906..0000000 --- a/.travis.yml +++ /dev/null @@ -1,7 +0,0 @@ -language: objective-c -osx_image: xcode9 -xcode_sdk: iphonesimulator10.0 -env: - - PLATFORM="ios" SCHEME="AlamofireSwiftyJSON" DESTINATION="platform=iOS Simulator,name=iPhone SE,OS=10.0" -script: - - set -o pipefail && xcodebuild -project Alamofire-SwiftyJSON.xcodeproj -scheme $SCHEME -destination "$DESTINATION" build-for-testing test | xcpretty diff --git a/Alamofire b/Alamofire deleted file mode 160000 index 7fe7b91..0000000 --- a/Alamofire +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7fe7b918b746fbb4b7a7c2146bef7a88c7ddc54e diff --git a/Alamofire-SwiftyJSON.podspec b/Alamofire-SwiftyJSON.podspec index 5447dc7..66aa6ea 100644 --- a/Alamofire-SwiftyJSON.podspec +++ b/Alamofire-SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Alamofire-SwiftyJSON" - s.version = "3.0.0" + s.version = "5.0.0" s.summary = "Alamofire extension for serialize NSData to SwiftyJSON " s.homepage = "https://github.com/SwiftyJSON/Alamofire-SwiftyJSON" s.license = { :type => "MIT" } @@ -8,9 +8,9 @@ Pod::Spec.new do |s| s.requires_arc = true s.osx.deployment_target = "10.11" - s.ios.deployment_target = "9.0" + s.ios.deployment_target = "15.0" s.source = { :git => "https://github.com/SwiftyJSON/Alamofire-SwiftyJSON.git", :tag => s.version } s.source_files = "Source/*.swift" - s.dependency 'Alamofire', '~> 4.5' - s.dependency 'SwiftyJSON', '~> 4.0.0' + s.dependency 'Alamofire', '~> 5' + s.dependency 'SwiftyJSON', '~> 5' end diff --git a/Alamofire-SwiftyJSON.xcodeproj/project.pbxproj b/Alamofire-SwiftyJSON.xcodeproj/project.pbxproj index e703136..ce8a816 100644 --- a/Alamofire-SwiftyJSON.xcodeproj/project.pbxproj +++ b/Alamofire-SwiftyJSON.xcodeproj/project.pbxproj @@ -7,10 +7,8 @@ objects = { /* Begin PBXBuildFile section */ - A8A2DBBA1A23292000AF9EFC /* Alamofire.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A8AFB75A19D14A5C0070765E /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - A8A2DBBB1A23292000AF9EFC /* SwiftyJSON.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A8AFB76519D14A670070765E /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - A8A2DBC31A2329E700AF9EFC /* Alamofire.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A8AFB75A19D14A5C0070765E /* Alamofire.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - A8A2DBC41A2329E700AF9EFC /* SwiftyJSON.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A8AFB76519D14A670070765E /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 7E90058880628A8C474F3A68 /* Pods_AlamofireSwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8141A8B420D5792AA2B6AD79 /* Pods_AlamofireSwiftyJSON.framework */; }; + A1C24D21CC1605AB4DA90602 /* Pods_AlamofireSwiftyJSONTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 79F09BCD209A1D2946563E19 /* Pods_AlamofireSwiftyJSONTests.framework */; }; A8A2DBC51A2329E700AF9EFC /* AlamofireSwiftyJSON.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A8AFB70F19D1401D0070765E /* AlamofireSwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A8AFB71519D1401D0070765E /* Alamofire-SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = A8AFB71419D1401D0070765E /* Alamofire-SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; A8AFB71F19D1401D0070765E /* Alamofire_SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8AFB71E19D1401D0070765E /* Alamofire_SwiftyJSONTests.swift */; }; @@ -18,90 +16,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 4BC5E9F91BB7E15600A393DD /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 4DD67C0B1A5C55C900ED2280; - remoteInfo = "Alamofire OSX"; - }; - 4BC5E9FB1BB7E15600A393DD /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = E4202FE01B667AA100C997FB; - remoteInfo = "Alamofire watchOS"; - }; - 4BC5E9FD1BB7E15600A393DD /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = F829C6B21A7A94F100A2CD59; - remoteInfo = "Alamofire OSX Tests"; - }; - 4BC5EA031BB7E15600A393DD /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9C7DFC5B1A9102BD005AA3F7; - remoteInfo = "SwiftyJSON OSX"; - }; - 4BC5EA051BB7E15600A393DD /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9C7DFC651A9102BD005AA3F7; - remoteInfo = "SwiftyJSON OSX Tests"; - }; - 4BC5EA071BB7E15600A393DD /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = E4D7CCE81B9465A700EE7221; - remoteInfo = "SwiftyJSON watchOS"; - }; - A81D16431E59E90500C62C5F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 4CF626EF1BA7CB3E0011A099; - remoteInfo = "Alamofire tvOS"; - }; - A81D16451E59E90500C62C5F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 4CF626F81BA7CB3E0011A099; - remoteInfo = "Alamofire tvOS Tests"; - }; - A81D164D1E59E90500C62C5F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7236B4F61BAC14150020529B; - remoteInfo = "SwiftyJSON tvOS"; - }; - A81D164F1E59E90500C62C5F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = A8580F741BCF5C5B00DA927B; - remoteInfo = "SwiftyJSON tvOS Tests"; - }; - A8A2DBB61A23290100AF9EFC /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = F8111E3219A95C8B0040E7D1; - remoteInfo = Alamofire; - }; - A8A2DBB81A23290100AF9EFC /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 2E4FEFDA19575BE100351305; - remoteInfo = SwiftyJSON; - }; A8A2DBBC1A2329BD00AF9EFC /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = A8AFB70619D1401D0070765E /* Project object */; @@ -109,48 +23,6 @@ remoteGlobalIDString = A8AFB70E19D1401D0070765E; remoteInfo = AlamofireSwiftyJSON; }; - A8A2DBBE1A2329BD00AF9EFC /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = F8111E3219A95C8B0040E7D1; - remoteInfo = Alamofire; - }; - A8A2DBC01A2329BD00AF9EFC /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 2E4FEFDA19575BE100351305; - remoteInfo = SwiftyJSON; - }; - A8AFB75919D14A5C0070765E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = F8111E3319A95C8B0040E7D1; - remoteInfo = Alamofire; - }; - A8AFB75B19D14A5C0070765E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = F8111E3E19A95C8B0040E7D1; - remoteInfo = AlamofireTests; - }; - A8AFB76419D14A670070765E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFDB19575BE100351305; - remoteInfo = SwiftyJSON; - }; - A8AFB76619D14A670070765E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFE619575BE100351305; - remoteInfo = SwiftyJSONTests; - }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -160,8 +32,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - A8A2DBBA1A23292000AF9EFC /* Alamofire.framework in Copy Frameworks */, - A8A2DBBB1A23292000AF9EFC /* SwiftyJSON.framework in Copy Frameworks */, ); name = "Copy Frameworks"; runOnlyForDeploymentPostprocessing = 1; @@ -172,8 +42,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - A8A2DBC31A2329E700AF9EFC /* Alamofire.framework in Copy Frameworks */, - A8A2DBC41A2329E700AF9EFC /* SwiftyJSON.framework in Copy Frameworks */, A8A2DBC51A2329E700AF9EFC /* AlamofireSwiftyJSON.framework in Copy Frameworks */, ); name = "Copy Frameworks"; @@ -182,6 +50,12 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 25819AD76C0268FCBBA2FCBF /* Pods-AlamofireSwiftyJSON.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireSwiftyJSON.debug.xcconfig"; path = "Target Support Files/Pods-AlamofireSwiftyJSON/Pods-AlamofireSwiftyJSON.debug.xcconfig"; sourceTree = ""; }; + 349731602792B03E8212C8A5 /* Pods-AlamofireSwiftyJSONTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireSwiftyJSONTests.debug.xcconfig"; path = "Target Support Files/Pods-AlamofireSwiftyJSONTests/Pods-AlamofireSwiftyJSONTests.debug.xcconfig"; sourceTree = ""; }; + 79F09BCD209A1D2946563E19 /* Pods_AlamofireSwiftyJSONTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AlamofireSwiftyJSONTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 8141A8B420D5792AA2B6AD79 /* Pods_AlamofireSwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AlamofireSwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 85ED7618CB4A172FF8CBCFC0 /* Pods-AlamofireSwiftyJSON.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireSwiftyJSON.release.xcconfig"; path = "Target Support Files/Pods-AlamofireSwiftyJSON/Pods-AlamofireSwiftyJSON.release.xcconfig"; sourceTree = ""; }; + 8C8591497AFB78FD9E258AF7 /* Pods-AlamofireSwiftyJSONTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AlamofireSwiftyJSONTests.release.xcconfig"; path = "Target Support Files/Pods-AlamofireSwiftyJSONTests/Pods-AlamofireSwiftyJSONTests.release.xcconfig"; sourceTree = ""; }; A8AFB70F19D1401D0070765E /* AlamofireSwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AlamofireSwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A8AFB71319D1401D0070765E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8AFB71419D1401D0070765E /* Alamofire-SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Alamofire-SwiftyJSON.h"; sourceTree = ""; }; @@ -189,8 +63,6 @@ A8AFB71D19D1401D0070765E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8AFB71E19D1401D0070765E /* Alamofire_SwiftyJSONTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alamofire_SwiftyJSONTests.swift; sourceTree = ""; }; A8AFB72819D140BD0070765E /* Alamofire-SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Alamofire-SwiftyJSON.swift"; sourceTree = ""; }; - A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Alamofire.xcodeproj; path = Alamofire/Alamofire.xcodeproj; sourceTree = ""; }; - A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftyJSON.xcodeproj; path = SwiftyJSON/SwiftyJSON.xcodeproj; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -198,6 +70,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 7E90058880628A8C474F3A68 /* Pods_AlamofireSwiftyJSON.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -205,20 +78,30 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + A1C24D21CC1605AB4DA90602 /* Pods_AlamofireSwiftyJSONTests.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 53779D552335643B003021E2 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 8141A8B420D5792AA2B6AD79 /* Pods_AlamofireSwiftyJSON.framework */, + 79F09BCD209A1D2946563E19 /* Pods_AlamofireSwiftyJSONTests.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; A8AFB70519D1401D0070765E = { isa = PBXGroup; children = ( - A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */, - A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */, A8AFB71119D1401D0070765E /* Source */, A8AFB71B19D1401D0070765E /* Tests */, A8AFB71019D1401D0070765E /* Products */, + 53779D552335643B003021E2 /* Frameworks */, + E3AECADE183F7CACE275C5C4 /* Pods */, ); sourceTree = ""; }; @@ -266,32 +149,15 @@ name = "Supporting Files"; sourceTree = ""; }; - A8AFB75519D14A5C0070765E /* Products */ = { + E3AECADE183F7CACE275C5C4 /* Pods */ = { isa = PBXGroup; children = ( - A8AFB75A19D14A5C0070765E /* Alamofire.framework */, - A8AFB75C19D14A5C0070765E /* Alamofire iOS Tests.xctest */, - 4BC5E9FA1BB7E15600A393DD /* Alamofire.framework */, - 4BC5E9FE1BB7E15600A393DD /* Alamofire macOS Tests.xctest */, - A81D16441E59E90500C62C5F /* Alamofire.framework */, - A81D16461E59E90500C62C5F /* Alamofire tvOS Tests.xctest */, - 4BC5E9FC1BB7E15600A393DD /* Alamofire.framework */, + 25819AD76C0268FCBBA2FCBF /* Pods-AlamofireSwiftyJSON.debug.xcconfig */, + 85ED7618CB4A172FF8CBCFC0 /* Pods-AlamofireSwiftyJSON.release.xcconfig */, + 349731602792B03E8212C8A5 /* Pods-AlamofireSwiftyJSONTests.debug.xcconfig */, + 8C8591497AFB78FD9E258AF7 /* Pods-AlamofireSwiftyJSONTests.release.xcconfig */, ); - name = Products; - sourceTree = ""; - }; - A8AFB75E19D14A670070765E /* Products */ = { - isa = PBXGroup; - children = ( - A8AFB76519D14A670070765E /* SwiftyJSON.framework */, - A8AFB76719D14A670070765E /* SwiftyJSON iOS Tests.xctest */, - 4BC5EA041BB7E15600A393DD /* SwiftyJSON.framework */, - 4BC5EA061BB7E15600A393DD /* SwiftyJSON OSX Tests.xctest */, - 4BC5EA081BB7E15600A393DD /* SwiftyJSON.framework */, - A81D164E1E59E90500C62C5F /* SwiftyJSON.framework */, - A81D16501E59E90500C62C5F /* SwiftyJSON tvOS Tests.xctest */, - ); - name = Products; + path = Pods; sourceTree = ""; }; /* End PBXGroup section */ @@ -312,6 +178,7 @@ isa = PBXNativeTarget; buildConfigurationList = A8AFB72219D1401D0070765E /* Build configuration list for PBXNativeTarget "AlamofireSwiftyJSON" */; buildPhases = ( + 5B5000E549C2DD7FEB0EC983 /* [CP] Check Pods Manifest.lock */, A8AFB70A19D1401D0070765E /* Sources */, A8AFB70B19D1401D0070765E /* Frameworks */, A8AFB70C19D1401D0070765E /* Headers */, @@ -321,8 +188,6 @@ buildRules = ( ); dependencies = ( - A8A2DBB71A23290100AF9EFC /* PBXTargetDependency */, - A8A2DBB91A23290100AF9EFC /* PBXTargetDependency */, ); name = AlamofireSwiftyJSON; productName = "Alamofire-SwiftyJSON"; @@ -333,17 +198,17 @@ isa = PBXNativeTarget; buildConfigurationList = A8AFB72519D1401D0070765E /* Build configuration list for PBXNativeTarget "AlamofireSwiftyJSONTests" */; buildPhases = ( + 927EBAF7CC9A1E6D8A3F396D /* [CP] Check Pods Manifest.lock */, A8AFB71619D1401D0070765E /* Sources */, A8AFB71719D1401D0070765E /* Frameworks */, A8AFB71819D1401D0070765E /* Resources */, A8A2DBC21A2329CE00AF9EFC /* Copy Frameworks */, + B1172473D4268CDCF7B3B578 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); dependencies = ( A8A2DBBD1A2329BD00AF9EFC /* PBXTargetDependency */, - A8A2DBBF1A2329BD00AF9EFC /* PBXTargetDependency */, - A8A2DBC11A2329BD00AF9EFC /* PBXTargetDependency */, ); name = AlamofireSwiftyJSONTests; productName = "Alamofire-SwiftyJSONTests"; @@ -357,7 +222,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1100; ORGANIZATIONNAME = SwiftJSON; TargetAttributes = { A8AFB70E19D1401D0070765E = { @@ -375,21 +240,12 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = A8AFB70519D1401D0070765E; productRefGroup = A8AFB71019D1401D0070765E /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = A8AFB75519D14A5C0070765E /* Products */; - ProjectRef = A8AFB75419D14A5C0070765E /* Alamofire.xcodeproj */; - }, - { - ProductGroup = A8AFB75E19D14A670070765E /* Products */; - ProjectRef = A8AFB75D19D14A670070765E /* SwiftyJSON.xcodeproj */; - }, - ); projectRoot = ""; targets = ( A8AFB70E19D1401D0070765E /* AlamofireSwiftyJSON */, @@ -398,107 +254,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 4BC5E9FA1BB7E15600A393DD /* Alamofire.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = Alamofire.framework; - remoteRef = 4BC5E9F91BB7E15600A393DD /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 4BC5E9FC1BB7E15600A393DD /* Alamofire.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = Alamofire.framework; - remoteRef = 4BC5E9FB1BB7E15600A393DD /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 4BC5E9FE1BB7E15600A393DD /* Alamofire macOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "Alamofire macOS Tests.xctest"; - remoteRef = 4BC5E9FD1BB7E15600A393DD /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 4BC5EA041BB7E15600A393DD /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = 4BC5EA031BB7E15600A393DD /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 4BC5EA061BB7E15600A393DD /* SwiftyJSON OSX Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON OSX Tests.xctest"; - remoteRef = 4BC5EA051BB7E15600A393DD /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 4BC5EA081BB7E15600A393DD /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = 4BC5EA071BB7E15600A393DD /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A81D16441E59E90500C62C5F /* Alamofire.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = Alamofire.framework; - remoteRef = A81D16431E59E90500C62C5F /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A81D16461E59E90500C62C5F /* Alamofire tvOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "Alamofire tvOS Tests.xctest"; - remoteRef = A81D16451E59E90500C62C5F /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A81D164E1E59E90500C62C5F /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = A81D164D1E59E90500C62C5F /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A81D16501E59E90500C62C5F /* SwiftyJSON tvOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON tvOS Tests.xctest"; - remoteRef = A81D164F1E59E90500C62C5F /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8AFB75A19D14A5C0070765E /* Alamofire.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = Alamofire.framework; - remoteRef = A8AFB75919D14A5C0070765E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8AFB75C19D14A5C0070765E /* Alamofire iOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "Alamofire iOS Tests.xctest"; - remoteRef = A8AFB75B19D14A5C0070765E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8AFB76519D14A670070765E /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = A8AFB76419D14A670070765E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8AFB76719D14A670070765E /* SwiftyJSON iOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON iOS Tests.xctest"; - remoteRef = A8AFB76619D14A670070765E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ A8AFB70D19D1401D0070765E /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -516,6 +271,73 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + 5B5000E549C2DD7FEB0EC983 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-AlamofireSwiftyJSON-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + 927EBAF7CC9A1E6D8A3F396D /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-AlamofireSwiftyJSONTests-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; + B1172473D4268CDCF7B3B578 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-AlamofireSwiftyJSONTests/Pods-AlamofireSwiftyJSONTests-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Alamofire/Alamofire.framework", + "${BUILT_PRODUCTS_DIR}/SwiftyJSON/SwiftyJSON.framework", + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Alamofire.framework", + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/SwiftyJSON.framework", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-AlamofireSwiftyJSONTests/Pods-AlamofireSwiftyJSONTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ A8AFB70A19D1401D0070765E /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -536,31 +358,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - A8A2DBB71A23290100AF9EFC /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = Alamofire; - targetProxy = A8A2DBB61A23290100AF9EFC /* PBXContainerItemProxy */; - }; - A8A2DBB91A23290100AF9EFC /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = SwiftyJSON; - targetProxy = A8A2DBB81A23290100AF9EFC /* PBXContainerItemProxy */; - }; A8A2DBBD1A2329BD00AF9EFC /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = A8AFB70E19D1401D0070765E /* AlamofireSwiftyJSON */; targetProxy = A8A2DBBC1A2329BD00AF9EFC /* PBXContainerItemProxy */; }; - A8A2DBBF1A2329BD00AF9EFC /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = Alamofire; - targetProxy = A8A2DBBE1A2329BD00AF9EFC /* PBXContainerItemProxy */; - }; - A8A2DBC11A2329BD00AF9EFC /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = SwiftyJSON; - targetProxy = A8A2DBC01A2329BD00AF9EFC /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -568,6 +370,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -576,12 +379,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -609,7 +414,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -624,6 +429,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -632,12 +438,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -658,7 +466,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; @@ -671,6 +479,7 @@ }; A8AFB72319D1401D0070765E /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 25819AD76C0268FCBBA2FCBF /* Pods-AlamofireSwiftyJSON.debug.xcconfig */; buildSettings = { "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; @@ -683,12 +492,13 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; A8AFB72419D1401D0070765E /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 85ED7618CB4A172FF8CBCFC0 /* Pods-AlamofireSwiftyJSON.release.xcconfig */; buildSettings = { "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; @@ -701,12 +511,13 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; A8AFB72619D1401D0070765E /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 349731602792B03E8212C8A5 /* Pods-AlamofireSwiftyJSONTests.debug.xcconfig */; buildSettings = { GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -716,18 +527,19 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; A8AFB72719D1401D0070765E /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 8C8591497AFB78FD9E258AF7 /* Pods-AlamofireSwiftyJSONTests.release.xcconfig */; buildSettings = { INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Alamofire-SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Alamofire-SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Alamofire-SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Alamofire-SwiftyJSON.xcodeproj/xcshareddata/xcschemes/AlamofireSwiftyJSON.xcscheme b/Alamofire-SwiftyJSON.xcodeproj/xcshareddata/xcschemes/AlamofireSwiftyJSON.xcscheme index 45076c5..1edaab7 100644 --- a/Alamofire-SwiftyJSON.xcodeproj/xcshareddata/xcschemes/AlamofireSwiftyJSON.xcscheme +++ b/Alamofire-SwiftyJSON.xcodeproj/xcshareddata/xcschemes/AlamofireSwiftyJSON.xcscheme @@ -1,6 +1,6 @@ + + + + @@ -54,23 +62,11 @@ - - - - - - - - 5' + pod 'SwiftyJSON', '~> 5' +end + +target 'AlamofireSwiftyJSONTests' do + pod 'Alamofire', '~> 5' + pod 'SwiftyJSON', '~> 5' +end diff --git a/Podfile.lock b/Podfile.lock new file mode 100644 index 0000000..587878c --- /dev/null +++ b/Podfile.lock @@ -0,0 +1,20 @@ +PODS: + - Alamofire (5.2.2) + - SwiftyJSON (5.0.0) + +DEPENDENCIES: + - Alamofire (~> 5) + - SwiftyJSON (~> 5) + +SPEC REPOS: + https://github.com/CocoaPods/Specs.git: + - Alamofire + - SwiftyJSON + +SPEC CHECKSUMS: + Alamofire: 814429acc853c6c54ff123fc3d2ef66803823ce0 + SwiftyJSON: 36413e04c44ee145039d332b4f4e2d3e8d6c4db7 + +PODFILE CHECKSUM: 5175165036843bb0979dcfa0e46433202caf367a + +COCOAPODS: 1.10.0.beta.2 diff --git a/README.md b/README.md index 4a17848..dd656c1 100644 --- a/README.md +++ b/README.md @@ -6,12 +6,15 @@ An extension to make serializing [Alamofire](https://github.com/Alamofire/Alamof ⚠️ **To use with Swift 4.x please ensure you are using >= `3.0.0`** ⚠️ +⚠️ **To use with Swift 5.x please ensure you are using >= `5.0.0`** ⚠️ + ## Swift version Alamofire-SwiftyJSON | Swift version | Alamofire | SwiftyJSON ------------- | --------------| ----------| ---------- 2.x | Swift 3.x | 4.x | 3.x 3.x | Swift 4.x | 4.5.x | 4.x +5.x | Swift 5.x | 5.x | 5.x ## Requirements @@ -39,7 +42,7 @@ import Alamofire_SwiftyJSON ``` ```swift -Alamofire.request(URL, method: .get, parameters: parameters, encoding: URLEncoding.default) +AF.request(URL, method: .get, parameters: parameters, encoding: URLEncoding.default) .responseSwiftyJSON { dataResponse in print(dataResponse.request) print(dataResponse.response) diff --git a/Source/Alamofire-SwiftyJSON.swift b/Source/Alamofire-SwiftyJSON.swift index 84806fc..4f23a34 100644 --- a/Source/Alamofire-SwiftyJSON.swift +++ b/Source/Alamofire-SwiftyJSON.swift @@ -1,87 +1,70 @@ -// -// AlamofireSwiftyJSON.swift -// AlamofireSwiftyJSON -// -// Created by Pinglin Tang on 14-9-22. -// Copyright (c) 2014 SwiftyJSON. All rights reserved. -// - -import Foundation - import Alamofire +import Foundation import SwiftyJSON -// MARK: - Request for Swift JSON +public final class SwiftyJSONResponseSerializer: ResponseSerializer { + public let dataPreprocessor: DataPreprocessor + public let emptyResponseCodes: Set + public let emptyRequestMethods: Set + /// `JSONSerialization.ReadingOptions` used when serializing a response. + public let options: JSONSerialization.ReadingOptions -extension Request { - /// Returns a SwiftyJSON object contained in a result type constructed from the response data using `JSONSerialization` - /// with the specified reading options. + /// Creates an instance with the provided values. /// - /// - parameter options: The JSON serialization reading options. Defaults to `.allowFragments`. - /// - parameter response: The response from the server. - /// - parameter data: The data returned from the server. - /// - parameter error: The error already encountered if it exists. - /// - /// - returns: The result data type. - public static func serializeResponseSwiftyJSON( - options: JSONSerialization.ReadingOptions, - response: HTTPURLResponse?, - data: Data?, - error: Error?) - -> Result + /// - Parameters: + /// - dataPreprocessor: `DataPreprocessor` used to prepare the received `Data` for serialization. + /// - emptyResponseCodes: The HTTP response codes for which empty responses are allowed. `[204, 205]` by default. + /// - emptyRequestMethods: The HTTP request methods for which empty responses are allowed. `[.head]` by default. + /// - options: The options to use. `.allowFragments` by default. + public init(dataPreprocessor: DataPreprocessor = SwiftyJSONResponseSerializer.defaultDataPreprocessor, + emptyResponseCodes: Set = SwiftyJSONResponseSerializer.defaultEmptyResponseCodes, + emptyRequestMethods: Set = SwiftyJSONResponseSerializer.defaultEmptyRequestMethods, + options: JSONSerialization.ReadingOptions = .allowFragments) { - guard error == nil else { return .failure(error!) } + self.dataPreprocessor = dataPreprocessor + self.emptyResponseCodes = emptyResponseCodes + self.emptyRequestMethods = emptyRequestMethods + self.options = options + } - if let response = response, emptyDataStatusCodes.contains(response.statusCode) { return .success(JSON.null) } + public func serialize(request: URLRequest?, response: HTTPURLResponse?, data: Data?, error: Error?) throws -> JSON { + guard error == nil else { throw error! } - guard let validData = data, validData.count > 0 else { - return .failure(AFError.responseSerializationFailed(reason: .inputDataNilOrZeroLength)) + guard var data = data, !data.isEmpty else { + guard emptyResponseAllowed(forRequest: request, response: response) else { + throw AFError.responseSerializationFailed(reason: .inputDataNilOrZeroLength) + } + + return JSON(booleanLiteral: false) } + data = try dataPreprocessor.preprocess(data) + do { - let json = try JSONSerialization.jsonObject(with: validData, options: options) - return .success(JSON(json)) + let json = try JSONSerialization.jsonObject(with: data, options: options) + return JSON(json) } catch { - return .failure(AFError.responseSerializationFailed(reason: .jsonSerializationFailed(error: error))) + throw AFError.responseSerializationFailed(reason: .jsonSerializationFailed(error: error)) } } } extension DataRequest { - /// Creates a response serializer that returns a SwiftyJSON object result type constructed from the response data using - /// `JSONSerialization` with the specified reading options. - /// - /// - parameter options: The JSON serialization reading options. Defaults to `.allowFragments`. - /// - /// - returns: A JSON object response serializer. - public static func swiftyJSONResponseSerializer( - options: JSONSerialization.ReadingOptions = .allowFragments) - -> DataResponseSerializer - { - return DataResponseSerializer { _, response, data, error in - return Request.serializeResponseSwiftyJSON(options: options, response: response, data: data, error: error) - } - } - /// Adds a handler to be called once the request has finished. /// - /// - parameter options: The JSON serialization reading options. Defaults to `.allowFragments`. - /// - parameter completionHandler: A closure to be executed once the request has finished. + /// - Parameters: + /// - queue: The queue on which the completion handler is dispatched. `.main` by default. + /// - options: The JSON serialization reading options. `.allowFragments` by default. + /// - completionHandler: A closure to be executed once the request has finished. /// - /// - returns: The request. + /// - Returns: The request. @discardableResult - public func responseSwiftyJSON( - queue: DispatchQueue? = nil, - options: JSONSerialization.ReadingOptions = .allowFragments, - completionHandler: @escaping (DataResponse) -> Void) - -> Self + public func responseSwiftyJSON(queue: DispatchQueue = .main, + options: JSONSerialization.ReadingOptions = .allowFragments, + completionHandler: @escaping (AFDataResponse) -> Void) -> Self { - return response( - queue: queue, - responseSerializer: DataRequest.swiftyJSONResponseSerializer(options: options), - completionHandler: completionHandler - ) + response(queue: queue, + responseSerializer: SwiftyJSONResponseSerializer(options: options), + completionHandler: completionHandler) } } - -private let emptyDataStatusCodes: Set = [204, 205] diff --git a/SwiftyJSON b/SwiftyJSON deleted file mode 160000 index 6b9f11e..0000000 --- a/SwiftyJSON +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6b9f11e2bbd277f199b1c09fa65631bfc52d4a5d diff --git a/Tests/Alamofire_SwiftyJSONTests.swift b/Tests/Alamofire_SwiftyJSONTests.swift index 43731b0..cd65a46 100644 --- a/Tests/Alamofire_SwiftyJSONTests.swift +++ b/Tests/Alamofire_SwiftyJSONTests.swift @@ -6,18 +6,17 @@ // Copyright (c) 2014年 SwiftJSON. All rights reserved. // -import XCTest import Alamofire -import SwiftyJSON import AlamofireSwiftyJSON +import SwiftyJSON +import XCTest class Alamofire_SwiftyJSONTests: XCTestCase { - func testGETRequestJSONResponse() { let URL = "http://httpbin.org/get" let parameters: Parameters = ["foo": "bar"] let expect = expectation(description: "responseSwiftyJSON method should work") - Alamofire.request(URL, method: .get, parameters: parameters, encoding: URLEncoding.default) + AF.request(URL, method: .get, parameters: parameters, encoding: URLEncoding.default) .validate() .responseSwiftyJSON { response in XCTAssertNotNil(response.request, "request should not be nil") @@ -25,7 +24,7 @@ class Alamofire_SwiftyJSONTests: XCTestCase { XCTAssertNil(response.error, "result error should be nil") XCTAssertEqual(response.value?["args"], SwiftyJSON.JSON(["foo": "bar"] as NSDictionary), "args should be equal") expect.fulfill() - } + } waitForExpectations(timeout: 10.0, handler: nil) } }