From 082b1ecea54e4e8b9cd8b43173ff33f598bf9acc Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 29 Sep 2014 13:24:33 +0800 Subject: [PATCH 001/470] Change the file path --- {SwiftyJSON => Source}/Info.plist | 2 +- {SwiftyJSON => Source}/SwiftyJSON.h | 0 {SwiftyJSON => Source}/SwiftyJSON.swift | 0 SwiftyJSON.xcodeproj/project.pbxproj | 254 +----------------- {SwiftyJSONTests => Tests}/Info.plist | 2 +- .../SwiftyJSONTests.json | 0 .../SwiftyJSONTests.swift | 0 7 files changed, 16 insertions(+), 242 deletions(-) rename {SwiftyJSON => Source}/Info.plist (91%) rename {SwiftyJSON => Source}/SwiftyJSON.h (100%) rename {SwiftyJSON => Source}/SwiftyJSON.swift (100%) rename {SwiftyJSONTests => Tests}/Info.plist (91%) rename {SwiftyJSONTests => Tests}/SwiftyJSONTests.json (100%) rename {SwiftyJSONTests => Tests}/SwiftyJSONTests.swift (100%) diff --git a/SwiftyJSON/Info.plist b/Source/Info.plist similarity index 91% rename from SwiftyJSON/Info.plist rename to Source/Info.plist index 34eb412b..20511ffd 100644 --- a/SwiftyJSON/Info.plist +++ b/Source/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - Aemaeth.${PRODUCT_NAME:rfc1034identifier} + com.swiftyjson.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SwiftyJSON/SwiftyJSON.h b/Source/SwiftyJSON.h similarity index 100% rename from SwiftyJSON/SwiftyJSON.h rename to Source/SwiftyJSON.h diff --git a/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON.swift similarity index 100% rename from SwiftyJSON/SwiftyJSON.swift rename to Source/SwiftyJSON.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 4c795026..5e2d3b7a 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -9,14 +9,9 @@ /* Begin PBXBuildFile section */ 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; - 2E4FF00D19575CE600351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FF00219575CE600351305 /* SwiftyJSON.framework */; }; - 2E4FF01C19575D1100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; - A885D1D319CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; - A885D1D519CF223F002FD4C3 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; - A885D1DD19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -27,13 +22,6 @@ remoteGlobalIDString = 2E4FEFDA19575BE100351305; remoteInfo = SwiftyJSON; }; - 2E4FF00E19575CE600351305 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 2E4FEFD219575BE100351305 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 2E4FF00119575CE600351305; - remoteInfo = "SwiftyJSON-OSX"; - }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -41,9 +29,7 @@ 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 2E4FEFEC19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 2E4FF00219575CE600351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 2E4FF00C19575CE600351305 /* SwiftyJSON-OSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON-OSXTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; @@ -65,29 +51,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 2E4FEFFE19575CE600351305 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 2E4FF00919575CE600351305 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 2E4FF00D19575CE600351305 /* SwiftyJSON.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ 2E4FEFD119575BE100351305 = { isa = PBXGroup; children = ( - 2E4FEFDD19575BE100351305 /* SwiftyJSON */, - 2E4FEFEA19575BE100351305 /* SwiftyJSONTests */, + 2E4FEFDD19575BE100351305 /* Source */, + 2E4FEFEA19575BE100351305 /* Tests */, 2E4FEFDC19575BE100351305 /* Products */, ); sourceTree = ""; @@ -97,20 +68,18 @@ children = ( 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */, - 2E4FF00219575CE600351305 /* SwiftyJSON.framework */, - 2E4FF00C19575CE600351305 /* SwiftyJSON-OSXTests.xctest */, ); name = Products; sourceTree = ""; }; - 2E4FEFDD19575BE100351305 /* SwiftyJSON */ = { + 2E4FEFDD19575BE100351305 /* Source */ = { isa = PBXGroup; children = ( 2E4FEFE019575BE100351305 /* SwiftyJSON.h */, A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */, 2E4FEFDE19575BE100351305 /* Supporting Files */, ); - path = SwiftyJSON; + path = Source; sourceTree = ""; }; 2E4FEFDE19575BE100351305 /* Supporting Files */ = { @@ -121,20 +90,20 @@ name = "Supporting Files"; sourceTree = ""; }; - 2E4FEFEA19575BE100351305 /* SwiftyJSONTests */ = { + 2E4FEFEA19575BE100351305 /* Tests */ = { isa = PBXGroup; children = ( A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */, A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); - path = SwiftyJSONTests; + path = Tests; sourceTree = ""; }; 2E4FEFEB19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( - 2E4FEFEC19575BE100351305 /* Info.plist */, + A82A1C0D19D922DC009A653D /* Info.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -150,14 +119,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 2E4FEFFF19575CE600351305 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 2E4FF01C19575D1100351305 /* SwiftyJSON.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -197,42 +158,6 @@ productReference = 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 2E4FF00119575CE600351305 /* SwiftyJSON-OSX */ = { - isa = PBXNativeTarget; - buildConfigurationList = 2E4FF01519575CE600351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON-OSX" */; - buildPhases = ( - 2E4FEFFD19575CE600351305 /* Sources */, - 2E4FEFFE19575CE600351305 /* Frameworks */, - 2E4FEFFF19575CE600351305 /* Headers */, - 2E4FF00019575CE600351305 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "SwiftyJSON-OSX"; - productName = "SwiftyJSON-OSX"; - productReference = 2E4FF00219575CE600351305 /* SwiftyJSON.framework */; - productType = "com.apple.product-type.framework"; - }; - 2E4FF00B19575CE600351305 /* SwiftyJSON-OSXTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 2E4FF01819575CE600351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON-OSXTests" */; - buildPhases = ( - 2E4FF00819575CE600351305 /* Sources */, - 2E4FF00919575CE600351305 /* Frameworks */, - 2E4FF00A19575CE600351305 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 2E4FF00F19575CE600351305 /* PBXTargetDependency */, - ); - name = "SwiftyJSON-OSXTests"; - productName = "SwiftyJSON-OSXTests"; - productReference = 2E4FF00C19575CE600351305 /* SwiftyJSON-OSXTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -248,13 +173,6 @@ CreatedOnToolsVersion = 6.0; TestTargetID = 2E4FEFDA19575BE100351305; }; - 2E4FF00119575CE600351305 = { - CreatedOnToolsVersion = 6.0; - }; - 2E4FF00B19575CE600351305 = { - CreatedOnToolsVersion = 6.0; - TestTargetID = 2E4FF00119575CE600351305; - }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -271,8 +189,6 @@ targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON */, 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, - 2E4FF00119575CE600351305 /* SwiftyJSON-OSX */, - 2E4FF00B19575CE600351305 /* SwiftyJSON-OSXTests */, ); }; /* End PBXProject section */ @@ -293,21 +209,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 2E4FF00019575CE600351305 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 2E4FF00A19575CE600351305 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A885D1DD19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -327,22 +228,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 2E4FEFFD19575CE600351305 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A885D1D519CF223F002FD4C3 /* SwiftyJSON.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 2E4FF00819575CE600351305 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A885D1D319CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -351,11 +236,6 @@ target = 2E4FEFDA19575BE100351305 /* SwiftyJSON */; targetProxy = 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */; }; - 2E4FF00F19575CE600351305 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 2E4FF00119575CE600351305 /* SwiftyJSON-OSX */; - targetProxy = 2E4FF00E19575CE600351305 /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -394,7 +274,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 = 7.0; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -434,7 +314,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 = 7.0; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -451,9 +331,8 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = SwiftyJSON/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -467,9 +346,8 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = SwiftyJSON/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -487,7 +365,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = SwiftyJSONTests/Info.plist; + INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -501,99 +379,13 @@ "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", ); - INFOPLIST_FILE = SwiftyJSONTests/Info.plist; + INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; }; - 2E4FF01619575CE600351305 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = SwiftyJSON/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; - METAL_ENABLE_DEBUG_INFO = YES; - PRODUCT_MODULE_NAME = SwiftyJSON; - PRODUCT_NAME = SwiftyJSON; - SDKROOT = macosx; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 2E4FF01719575CE600351305 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = SwiftyJSON/Info.plist; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; - METAL_ENABLE_DEBUG_INFO = NO; - PRODUCT_MODULE_NAME = SwiftyJSON; - PRODUCT_NAME = SwiftyJSON; - SDKROOT = macosx; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 2E4FF01919575CE600351305 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = SwiftyJSONTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; - METAL_ENABLE_DEBUG_INFO = YES; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 2E4FF01A19575CE600351305 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); - INFOPLIST_FILE = SwiftyJSONTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.9; - METAL_ENABLE_DEBUG_INFO = NO; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -624,24 +416,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 2E4FF01519575CE600351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON-OSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 2E4FF01619575CE600351305 /* Debug */, - 2E4FF01719575CE600351305 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 2E4FF01819575CE600351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON-OSXTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 2E4FF01919575CE600351305 /* Debug */, - 2E4FF01A19575CE600351305 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; /* End XCConfigurationList section */ }; rootObject = 2E4FEFD219575BE100351305 /* Project object */; diff --git a/SwiftyJSONTests/Info.plist b/Tests/Info.plist similarity index 91% rename from SwiftyJSONTests/Info.plist rename to Tests/Info.plist index fe602613..84bb0558 100644 --- a/SwiftyJSONTests/Info.plist +++ b/Tests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - SwiftJSON.${PRODUCT_NAME:rfc1034identifier} + com.swiftyjson.${PRODUCT_NAME:rfc1034identifier} CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SwiftyJSONTests/SwiftyJSONTests.json b/Tests/SwiftyJSONTests.json similarity index 100% rename from SwiftyJSONTests/SwiftyJSONTests.json rename to Tests/SwiftyJSONTests.json diff --git a/SwiftyJSONTests/SwiftyJSONTests.swift b/Tests/SwiftyJSONTests.swift similarity index 100% rename from SwiftyJSONTests/SwiftyJSONTests.swift rename to Tests/SwiftyJSONTests.swift From bc6f3d8db38c481040a170da835f24ac5439616b Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 29 Sep 2014 13:30:08 +0800 Subject: [PATCH 002/470] Add SwiftyJSON.xcworkspace --- SwiftyJSON.xcworkspace/contents.xcworkspacedata | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 SwiftyJSON.xcworkspace/contents.xcworkspacedata diff --git a/SwiftyJSON.xcworkspace/contents.xcworkspacedata b/SwiftyJSON.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..64c28153 --- /dev/null +++ b/SwiftyJSON.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + From c8ae7fc641b2b8b25bf78034970a9da532289746 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 29 Sep 2014 22:54:12 +0800 Subject: [PATCH 003/470] Add iOS Example --- Example.xcodeproj/project.pbxproj | 392 ++++++++++++++++++ Example/AppDelegate.swift | 47 +++ Example/Base.lproj/LaunchScreen.xib | 41 ++ Example/Base.lproj/Main.storyboard | 71 ++++ .../AppIcon.appiconset/Contents.json | 68 +++ Example/Info.plist | 47 +++ Example/SwiftyJSONTests.json | 345 +++++++++++++++ Example/ViewController.swift | 92 ++++ .../contents.xcworkspacedata | 3 + 9 files changed, 1106 insertions(+) create mode 100644 Example.xcodeproj/project.pbxproj create mode 100644 Example/AppDelegate.swift create mode 100644 Example/Base.lproj/LaunchScreen.xib create mode 100644 Example/Base.lproj/Main.storyboard create mode 100644 Example/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 Example/Info.plist create mode 100644 Example/SwiftyJSONTests.json create mode 100644 Example/ViewController.swift diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj new file mode 100644 index 00000000..f94e3afb --- /dev/null +++ b/Example.xcodeproj/project.pbxproj @@ -0,0 +1,392 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + A82A1C1F19D926B8009A653D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C1E19D926B8009A653D /* AppDelegate.swift */; }; + A82A1C2419D926B8009A653D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2219D926B8009A653D /* Main.storyboard */; }; + A82A1C2619D926B8009A653D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2519D926B8009A653D /* Images.xcassets */; }; + A82A1C2919D926B8009A653D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2719D926B8009A653D /* LaunchScreen.xib */; }; + A82A1C4019D94AE5009A653D /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */; }; + A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; }; + A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + A82A1C5619D95606009A653D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C5519D95606009A653D /* ViewController.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 2E4FEFDB19575BE100351305; + remoteInfo = SwiftyJSON; + }; + A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 2E4FEFE619575BE100351305; + remoteInfo = SwiftyJSONTests; + }; + A82A1C5219D94E96009A653D /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 1; + remoteGlobalIDString = 2E4FEFDA19575BE100351305; + remoteInfo = SwiftyJSON; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + A82A1C5419D94E97009A653D /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + A82A1C1919D926B8009A653D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + A82A1C1D19D926B8009A653D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + A82A1C1E19D926B8009A653D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + A82A1C2319D926B8009A653D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + A82A1C2519D926B8009A653D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; + A82A1C2819D926B8009A653D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; + A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; + A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = SwiftyJSON.xcodeproj; sourceTree = ""; }; + A82A1C5519D95606009A653D /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + A82A1C1619D926B8009A653D /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + A82A1C1019D926B8009A653D = { + isa = PBXGroup; + children = ( + A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */, + A82A1C1B19D926B8009A653D /* Example */, + A82A1C1A19D926B8009A653D /* Products */, + ); + sourceTree = ""; + }; + A82A1C1A19D926B8009A653D /* Products */ = { + isa = PBXGroup; + children = ( + A82A1C1919D926B8009A653D /* Example.app */, + ); + name = Products; + sourceTree = ""; + }; + A82A1C1B19D926B8009A653D /* Example */ = { + isa = PBXGroup; + children = ( + A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */, + A82A1C1E19D926B8009A653D /* AppDelegate.swift */, + A82A1C5519D95606009A653D /* ViewController.swift */, + A82A1C2219D926B8009A653D /* Main.storyboard */, + A82A1C2519D926B8009A653D /* Images.xcassets */, + A82A1C2719D926B8009A653D /* LaunchScreen.xib */, + A82A1C1C19D926B8009A653D /* Supporting Files */, + ); + path = Example; + sourceTree = ""; + }; + A82A1C1C19D926B8009A653D /* Supporting Files */ = { + isa = PBXGroup; + children = ( + A82A1C1D19D926B8009A653D /* Info.plist */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; + A82A1C4819D94E86009A653D /* Products */ = { + isa = PBXGroup; + children = ( + A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */, + A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + A82A1C1819D926B8009A653D /* Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = A82A1C3819D926B8009A653D /* Build configuration list for PBXNativeTarget "Example" */; + buildPhases = ( + A82A1C1519D926B8009A653D /* Sources */, + A82A1C1619D926B8009A653D /* Frameworks */, + A82A1C1719D926B8009A653D /* Resources */, + A82A1C5419D94E97009A653D /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + A82A1C5319D94E96009A653D /* PBXTargetDependency */, + ); + name = Example; + productName = Example; + productReference = A82A1C1919D926B8009A653D /* Example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + A82A1C1119D926B8009A653D /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0600; + ORGANIZATIONNAME = swiftyjson; + TargetAttributes = { + A82A1C1819D926B8009A653D = { + CreatedOnToolsVersion = 6.0.1; + }; + }; + }; + buildConfigurationList = A82A1C1419D926B8009A653D /* Build configuration list for PBXProject "Example" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = A82A1C1019D926B8009A653D; + productRefGroup = A82A1C1A19D926B8009A653D /* Products */; + projectDirPath = ""; + projectReferences = ( + { + ProductGroup = A82A1C4819D94E86009A653D /* Products */; + ProjectRef = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + }, + ); + projectRoot = ""; + targets = ( + A82A1C1819D926B8009A653D /* Example */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXReferenceProxy section */ + A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftyJSON.framework; + remoteRef = A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = SwiftyJSONTests.xctest; + remoteRef = A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + +/* Begin PBXResourcesBuildPhase section */ + A82A1C1719D926B8009A653D /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A82A1C2419D926B8009A653D /* Main.storyboard in Resources */, + A82A1C2919D926B8009A653D /* LaunchScreen.xib in Resources */, + A82A1C2619D926B8009A653D /* Images.xcassets in Resources */, + A82A1C4019D94AE5009A653D /* SwiftyJSONTests.json in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + A82A1C1519D926B8009A653D /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A82A1C5619D95606009A653D /* ViewController.swift in Sources */, + A82A1C1F19D926B8009A653D /* AppDelegate.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + A82A1C5319D94E96009A653D /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + name = SwiftyJSON; + targetProxy = A82A1C5219D94E96009A653D /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + A82A1C2219D926B8009A653D /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + A82A1C2319D926B8009A653D /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + A82A1C2719D926B8009A653D /* LaunchScreen.xib */ = { + isa = PBXVariantGroup; + children = ( + A82A1C2819D926B8009A653D /* Base */, + ); + name = LaunchScreen.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + A82A1C3619D926B8009A653D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + A82A1C3719D926B8009A653D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + A82A1C3919D926B8009A653D /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/build/Debug-iphoneos", + ); + INFOPLIST_FILE = Example/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + A82A1C3A19D926B8009A653D /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/build/Debug-iphoneos", + ); + INFOPLIST_FILE = Example/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + A82A1C1419D926B8009A653D /* Build configuration list for PBXProject "Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A82A1C3619D926B8009A653D /* Debug */, + A82A1C3719D926B8009A653D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + A82A1C3819D926B8009A653D /* Build configuration list for PBXNativeTarget "Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A82A1C3919D926B8009A653D /* Debug */, + A82A1C3A19D926B8009A653D /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = A82A1C1119D926B8009A653D /* Project object */; +} diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift new file mode 100644 index 00000000..4c7a7884 --- /dev/null +++ b/Example/AppDelegate.swift @@ -0,0 +1,47 @@ +// SwiftyJSON.h +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import SwiftyJSON + +@UIApplicationMain +class AppDelegate: UIResponder, UIApplicationDelegate { + + var window: UIWindow? + + func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + + let navigationController = self.window?.rootViewController as UINavigationController + let viewController = navigationController.topViewController as ViewController + + if let file = NSBundle(forClass:AppDelegate.self).pathForResource("SwiftyJSONTests", ofType: "json") { + let data = NSData(contentsOfFile: file) + let json = JSON(data:data) + viewController.json = json + } else { + viewController.json = JSON.Null(nil) + } + + return true + } +} + diff --git a/Example/Base.lproj/LaunchScreen.xib b/Example/Base.lproj/LaunchScreen.xib new file mode 100644 index 00000000..0985c07c --- /dev/null +++ b/Example/Base.lproj/LaunchScreen.xib @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard new file mode 100644 index 00000000..57c3bd89 --- /dev/null +++ b/Example/Base.lproj/Main.storyboard @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/Images.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..36d2c80d --- /dev/null +++ b/Example/Images.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "76x76", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Info.plist b/Example/Info.plist new file mode 100644 index 00000000..55f9d4e3 --- /dev/null +++ b/Example/Info.plist @@ -0,0 +1,47 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/Example/SwiftyJSONTests.json b/Example/SwiftyJSONTests.json new file mode 100644 index 00000000..05190a8a --- /dev/null +++ b/Example/SwiftyJSONTests.json @@ -0,0 +1,345 @@ +[ + { + "coordinates":null, + "truncated":false, + "created_at":"Tue Aug 28 21:16:23 +0000 2012", + "favorited":false, + "id_str":"240558470661799936", + "in_reply_to_user_id_str":null, + "entities":{ + "urls":[ + + ], + "hashtags":[ + + ], + "user_mentions":[ + + ] + }, + "text":"just another test", + "contributors":null, + "id":240558470661799936, + "retweet_count":0, + "in_reply_to_status_id_str":null, + "geo":null, + "retweeted":false, + "in_reply_to_user_id":null, + "place":null, + "source":"<a href=\"//realitytechnicians.com\" rel=\"\"nofollow\"\">OAuth Dancer Reborn</a>", + "user":{ + "name":"OAuth Dancer", + "profile_sidebar_fill_color":"DDEEF6", + "profile_background_tile":true, + "profile_sidebar_border_color":"C0DEED", + "profile_image_url":"http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", + "created_at":"Wed Mar 03 19:37:35 +0000 2010", + "location":"San Francisco, CA", + "follow_request_sent":false, + "id_str":"119476949", + "is_translator":false, + "profile_link_color":"0084B4", + "entities":{ + "url":{ + "urls":[ + { + "expanded_url":null, + "url":"http://bit.ly/oauth-dancer", + "indices":[ + 0, + 26 + ], + "display_url":null + } + ] + }, + "description":null + }, + "default_profile":false, + "url":"http://bit.ly/oauth-dancer", + "contributors_enabled":false, + "favourites_count":7, + "utc_offset":null, + "profile_image_url_https":"https://si0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", + "id":119476949, + "listed_count":1, + "profile_use_background_image":true, + "profile_text_color":"333333", + "followers_count":28, + "lang":"en", + "protected":false, + "geo_enabled":true, + "notifications":false, + "description":"", + "profile_background_color":"C0DEED", + "verified":false, + "time_zone":null, + "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/80151733/oauth-dance.png", + "statuses_count":166, + "profile_background_image_url":"http://a0.twimg.com/profile_background_images/80151733/oauth-dance.png", + "default_profile_image":false, + "friends_count":14, + "following":false, + "show_all_inline_media":false, + "screen_name":"oauth_dancer" + }, + "in_reply_to_screen_name":null, + "in_reply_to_status_id":null + }, + { + "coordinates":{ + "coordinates":[ + -122.25831, + 37.871609 + ], + "type":"Point" + }, + "truncated":false, + "created_at":"Tue Aug 28 21:08:15 +0000 2012", + "favorited":false, + "id_str":"240556426106372096", + "in_reply_to_user_id_str":null, + "entities":{ + "urls":[ + { + "expanded_url":"http://blogs.ischool.berkeley.edu/i290-abdt-s12/", + "url":"http://t.co/bfj7zkDJ", + "indices":[ + 79, + 99 + ], + "display_url":"blogs.ischool.berkeley.edu/i290-abdt-s12/" + } + ], + "hashtags":[ + + ], + "user_mentions":[ + { + "name":"Cal", + "id_str":"17445752", + "id":17445752, + "indices":[ + 60, + 64 + ], + "screen_name":"Cal" + }, + { + "name":"Othman Laraki", + "id_str":"20495814", + "id":20495814, + "indices":[ + 70, + 77 + ], + "screen_name":"othman" + } + ] + }, + "text":"lecturing at the \"analyzing big data with twitter\" class at @cal with @othman http://t.co/bfj7zkDJ", + "contributors":null, + "id":240556426106372096, + "retweet_count":3, + "in_reply_to_status_id_str":null, + "geo":{ + "coordinates":[ + 37.871609, + -122.25831 + ], + "type":"Point" + }, + "retweeted":false, + "possibly_sensitive":false, + "in_reply_to_user_id":null, + "place":{ + "name":"Berkeley", + "country_code":"US", + "country":"United States", + "attributes":{ + + }, + "url":"http://api.twitter.com/1/geo/id/5ef5b7f391e30aff.json", + "id":"5ef5b7f391e30aff", + "bounding_box":{ + "coordinates":[ + [ + [ + -122.367781, + 37.835727 + ], + [ + -122.234185, + 37.835727 + ], + [ + -122.234185, + 37.905824 + ], + [ + -122.367781, + 37.905824 + ] + ] + ], + "type":"Polygon" + }, + "full_name":"Berkeley, CA", + "place_type":"city" + }, + "source":"<a href=\"//www.apple.com\"\" rel=\"\"nofollow\"\">Safari on iOS</a>", + "user":{ + "name":"Raffi Krikorian", + "profile_sidebar_fill_color":"DDEEF6", + "profile_background_tile":false, + "profile_sidebar_border_color":"C0DEED", + "profile_image_url":"http://a0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", + "created_at":"Sun Aug 19 14:24:06 +0000 2007", + "location":"San Francisco, California", + "follow_request_sent":false, + "id_str":"8285392", + "is_translator":false, + "profile_link_color":"0084B4", + "entities":{ + "url":{ + "urls":[ + { + "expanded_url":"http://about.me/raffi.krikorian", + "url":"http://t.co/eNmnM6q", + "indices":[ + 0, + 19 + ], + "display_url":"about.me/raffi.krikorian" + } + ] + }, + "description":{ + "urls":[ + + ] + } + }, + "default_profile":true, + "url":"http://t.co/eNmnM6q", + "contributors_enabled":false, + "favourites_count":724, + "utc_offset":-28800, + "profile_image_url_https":"https://si0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", + "id":8285392, + "listed_count":619, + "profile_use_background_image":true, + "profile_text_color":"333333", + "followers_count":18752, + "lang":"en", + "protected":false, + "geo_enabled":true, + "notifications":false, + "description":"Director of @twittereng's Platform Services. I break things.", + "profile_background_color":"C0DEED", + "verified":false, + "time_zone":"Pacific Time (US & Canada)", + "profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png", + "statuses_count":5007, + "profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png", + "default_profile_image":false, + "friends_count":701, + "following":true, + "show_all_inline_media":true, + "screen_name":"raffi" + }, + "in_reply_to_screen_name":null, + "in_reply_to_status_id":null + }, + { + "coordinates":null, + "truncated":false, + "created_at":"Tue Aug 28 19:59:34 +0000 2012", + "favorited":false, + "id_str":"240539141056638977", + "in_reply_to_user_id_str":null, + "entities":{ + "urls":[ + + ], + "hashtags":[ + + ], + "user_mentions":[ + + ] + }, + "text":"You'd be right more often if you thought you were wrong.", + "contributors":null, + "id":240539141056638977, + "retweet_count":1, + "in_reply_to_status_id_str":null, + "geo":null, + "retweeted":false, + "in_reply_to_user_id":null, + "place":null, + "source":"web", + "user":{ + "name":"Taylor Singletary", + "profile_sidebar_fill_color":"FBFBFB", + "profile_background_tile":true, + "profile_sidebar_border_color":"000000", + "profile_image_url":"http://a0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", + "created_at":"Wed Mar 07 22:23:19 +0000 2007", + "location":"San Francisco, CA", + "follow_request_sent":false, + "id_str":"819797", + "is_translator":false, + "profile_link_color":"c71818", + "entities":{ + "url":{ + "urls":[ + { + "expanded_url":"http://www.rebelmouse.com/episod/", + "url":"http://t.co/Lxw7upbN", + "indices":[ + 0, + 20 + ], + "display_url":"rebelmouse.com/episod/" + } + ] + }, + "description":{ + "urls":[ + + ] + } + }, + "default_profile":false, + "url":"http://t.co/Lxw7upbN", + "contributors_enabled":false, + "favourites_count":15990, + "utc_offset":-28800, + "profile_image_url_https":"https://si0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", + "id":819797, + "listed_count":340, + "profile_use_background_image":true, + "profile_text_color":"D20909", + "followers_count":7126, + "lang":"en", + "protected":false, + "geo_enabled":true, + "notifications":false, + "description":"Reality Technician, Twitter API team, synthesizer enthusiast; a most excellent adventure in timelines. I know it's hard to believe in something you can't see.", + "profile_background_color":"000000", + "verified":false, + "time_zone":"Pacific Time (US & Canada)", + "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", + "statuses_count":18076, + "profile_background_image_url":"http://a0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", + "default_profile_image":false, + "friends_count":5444, + "following":true, + "show_all_inline_media":true, + "screen_name":"episod" + }, + "in_reply_to_screen_name":null, + "in_reply_to_status_id":null + } + ] \ No newline at end of file diff --git a/Example/ViewController.swift b/Example/ViewController.swift new file mode 100644 index 00000000..02cf4918 --- /dev/null +++ b/Example/ViewController.swift @@ -0,0 +1,92 @@ +// SwiftyJSON.h +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import SwiftyJSON + +class ViewController: UITableViewController { + + var json: JSON = JSON.Null(nil) + + // MARK: - Table view data source + + override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + return 1 + } + + override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + switch self.json { + case .Sequence(let array): + return array.count + case .Mapping(let dictionary): + return dictionary.count + default: + return 1 + } + } + + override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCellWithIdentifier("JSONCell", forIndexPath: indexPath) as UITableViewCell + + var row = indexPath.row + + switch self.json { + case .Sequence(let array): + cell.textLabel?.text = "\(row)" + cell.detailTextLabel?.text = array[row].description + case .Mapping(let dictionary): + let key = dictionary.keys.array[row] + let value = dictionary[key] + cell.textLabel?.text = "\(key)" + cell.detailTextLabel?.text = value?.stringValue + default: + cell.detailTextLabel?.text = self.json.description + } + + return cell + } + + // MARK: - Navigation + + override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { + if let nextController = segue.destinationViewController.topViewController as? ViewController { + + if let indexPath = self.tableView.indexPathForSelectedRow() { + var row = indexPath.row + var nextJson: JSON = JSON.Null(nil) + + switch self.json { + case .Sequence: + nextJson = self.json[row] + case .Mapping where row < self.json.dictionaryValue.count: + let key = self.json.dictionaryValue.keys.array[row] + if let value = self.json.dictionary?[key] { + nextJson = value + } + default: + print("") + } + nextController.json = nextJson + } + } + } +} diff --git a/SwiftyJSON.xcworkspace/contents.xcworkspacedata b/SwiftyJSON.xcworkspace/contents.xcworkspacedata index 64c28153..4f20b228 100644 --- a/SwiftyJSON.xcworkspace/contents.xcworkspacedata +++ b/SwiftyJSON.xcworkspace/contents.xcworkspacedata @@ -4,4 +4,7 @@ + + From 80121e8f258617fcea0e5eb5c34580386b89e5e2 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 29 Sep 2014 22:54:59 +0800 Subject: [PATCH 004/470] Add Dictionary methods --- Source/SwiftyJSON.swift | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index caa25bc5..8624d9bd 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -158,13 +158,15 @@ extension JSON { // MARK: - Subscript extension JSON { - //if an array return the array[index]'s JSON else return .Null with error - public subscript(index: Int) -> JSON { + /** + If self is .Sequence return the array[index]'s json else return .Null with error + */ + public subscript(idx: Int) -> JSON { get { switch self { case .Sequence(let array): - if array.count > index { - return array[index] + if array.count > idx { + return array[idx] } else { return .Null(NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"])) } @@ -174,7 +176,23 @@ extension JSON { } } - //if an array return the dictionary[key]'s JSON else return .Null with error + /** + If self is .Mapping return the dictionary[i]'s (string, json) else return ("" , .Null(error)) + */ + public subscript(i: DictionaryIndex) -> (String, JSON) { + get { + switch self { + case .Mapping(let dictionary): + return dictionary[i] + default: + return ("", .Null(NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an dictionary"]))) + } + } + } + + /** + If self is .Sequence return the dictionary[key]'s JSON else return .Null with error + */ public subscript(key: String) -> JSON { get { switch self { @@ -283,6 +301,18 @@ extension JSON { return self.dictionary ?? [:] } } + + /** + If self is .Mapping return the dictionary.indexForKey(key) else return nil + */ + public func indexForKey(key: String) -> DictionaryIndex? { + switch self { + case .Mapping(let dictionary): + return dictionary.indexForKey(key) + default: + return nil + } + } } //MARK: - Scalar: Bool From 75eb0440d03bcf0ffc2f9fbe2aae60fa58c6f500 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 1 Oct 2014 10:10:29 +0800 Subject: [PATCH 005/470] Delete redundant code --- Source/SwiftyJSON.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 8624d9bd..ca4be8fc 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -43,7 +43,7 @@ public enum JSON { /** :param: data The NSData used to convert to json. :param: options The JSON serialization reading options. `.AllowFragments` by default. - :param: error The NSErrorPointer used to return the error. + :param: error The NSErrorPointer used to return the error. `nil` by default. */ public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error){ @@ -88,8 +88,6 @@ public enum JSON { } } self = .Mapping(jsonDictionary) - case let null as NSNull: - self = .Null(nil) default: self = .Null(NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"])) } From 54dc5d22efd3b0ec582be7c3a4666914b3215fb9 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 2 Oct 2014 00:58:01 +0800 Subject: [PATCH 006/470] =?UTF-8?q?Speedup=20initialization=EF=BC=8Cbut=20?= =?UTF-8?q?slow=20array=20and=20dictionary=20methods.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Example/ViewController.swift | 8 +-- Source/SwiftyJSON.swift | 125 +++++++++++++---------------------- 2 files changed, 51 insertions(+), 82 deletions(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 02cf4918..ad79e41b 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -52,12 +52,12 @@ class ViewController: UITableViewController { switch self.json { case .Sequence(let array): cell.textLabel?.text = "\(row)" - cell.detailTextLabel?.text = array[row].description + cell.detailTextLabel?.text = JSON(object:array[row]).description case .Mapping(let dictionary): - let key = dictionary.keys.array[row] - let value = dictionary[key] + let key: AnyObject = (dictionary as NSDictionary).allKeys[row] + let value = self.json[key as String] cell.textLabel?.text = "\(key)" - cell.detailTextLabel?.text = value?.stringValue + cell.detailTextLabel?.text = value.stringValue default: cell.detailTextLabel?.text = self.json.description } diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index ca4be8fc..46f7f52a 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -34,9 +34,9 @@ public enum JSON { //private type string case ScalarString(String) //private type sequence - case Sequence(Array) + case Sequence(Array) //private type mapping - case Mapping(Dictionary) + case Mapping(Dictionary) //private type null case Null(NSError?) @@ -54,7 +54,16 @@ public enum JSON { } /** - :param: object The JSON object following the JSON's definition + :param: object The object must have the following properties: + - Top level object is an NSArray or NSDictionary + - All objects are NSString, NSNumber, NSArray, NSDictionary, or NSNull + - All dictionary keys are NSStrings + - NSNumbers are not NaN or infinity + in swift + - String as NSString + - Bool, Int, Float, Double... as NSNumber + - Array as NSArray + - Dictionary as NSDictionary with NSString keys */ public init(object: AnyObject) { switch object { @@ -65,33 +74,21 @@ public enum JSON { case let null as NSNull: self = .Null(nil) case let array as Array: - var jsonArray = Array() - for object : AnyObject in array { - let json = JSON(object: object) - if let error = json.error { - self = json - return - } else { - jsonArray.append(json) - } - } - self = .Sequence(jsonArray) + self = .Sequence(array) case let dictionary as Dictionary: - var jsonDictionary = Dictionary() - for (key : String, value : AnyObject) in dictionary { - let json = JSON(object: value) - if let error = json.error { - self = json - return - } else { - jsonDictionary[key] = json - } - } - self = .Mapping(jsonDictionary) + self = .Mapping(dictionary) default: self = .Null(NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"])) } } + + private init(topObject:AnyObject) { + if !NSJSONSerialization.isValidJSONObject(topObject) { + self = .Null(NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"])) + return + } + self = JSON(object: topObject) + } } //MARK: - Return Error @@ -132,21 +129,9 @@ extension JSON { case .Null(let error) where error == nil: return NSNull() case .Sequence(let array): - var retArray = Array() - for json in array { - if let object: AnyObject = json.object { - retArray.append(object) - } - } - return retArray + return array case .Mapping(let dictionary): - var retDicitonary = Dictionary() - for (key : String, value : JSON) in dictionary { - if let object: AnyObject = value.object{ - retDicitonary[key] = object - } - } - return retDicitonary + return dictionary default: return nil } @@ -164,7 +149,7 @@ extension JSON { switch self { case .Sequence(let array): if array.count > idx { - return array[idx] + return JSON(object:array[idx]) } else { return .Null(NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"])) } @@ -174,20 +159,6 @@ extension JSON { } } - /** - If self is .Mapping return the dictionary[i]'s (string, json) else return ("" , .Null(error)) - */ - public subscript(i: DictionaryIndex) -> (String, JSON) { - get { - switch self { - case .Mapping(let dictionary): - return dictionary[i] - default: - return ("", .Null(NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an dictionary"]))) - } - } - } - /** If self is .Sequence return the dictionary[key]'s JSON else return .Null with error */ @@ -195,8 +166,8 @@ extension JSON { get { switch self { case .Mapping(let dictionary): - if let value = dictionary[key] { - return value + if let value: AnyObject = dictionary[key] { + return JSON(object:value) } else { return .Null(NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"])) } @@ -259,11 +230,16 @@ extension JSON: Printable, DebugPrintable { extension JSON { //Optional array + //It's slow public var array: Array? { get { switch self { case .Sequence(let array): - return array + var jsonArray = Array() + for object in array { + jsonArray.append(JSON(object: object)) + } + return jsonArray default: return nil } @@ -271,6 +247,7 @@ extension JSON { } //Non-optional array + //It's slow public var arrayValue: Array { get { return self.array ?? [] @@ -282,11 +259,16 @@ extension JSON { extension JSON { //Optional dictionary + //It's slow public var dictionary: Dictionary? { get { switch self { case .Mapping(let dictionary): - return dictionary + var jsonDictionary = Dictionary() + for (key, value) in dictionary { + jsonDictionary[key] = JSON(object: value) + } + return jsonDictionary default: return nil } @@ -294,23 +276,12 @@ extension JSON { } //Non-optional dictionary + //It's slow public var dictionaryValue: Dictionary { get { return self.dictionary ?? [:] } } - - /** - If self is .Mapping return the dictionary.indexForKey(key) else return nil - */ - public func indexForKey(key: String) -> DictionaryIndex? { - switch self { - case .Mapping(let dictionary): - return dictionary.indexForKey(key) - default: - return nil - } - } } //MARK: - Scalar: Bool @@ -649,11 +620,9 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { case (.ScalarString(let l), .ScalarString(let r)): return l == r case (.Sequence(let l), .Sequence(let r)): - return l == r - case (.Mapping(let l), .Mapping(let r)): - return l == r + return (l as NSArray) == (r as NSArray) case (.Mapping(let l), .Mapping(let r)): - return l == r + return (l as NSDictionary) == (r as NSDictionary) case (.Null(let l), .Null(let r)): let lcode = l?.code ?? 0 let rcode = l?.code ?? 0 @@ -675,9 +644,9 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { case (.ScalarString(let l), .ScalarString(let r)): return l <= r case (.Sequence(let l), .Sequence(let r)): - return l == r + return (l as NSArray) == (r as NSArray) case (.Mapping(let l), .Mapping(let r)): - return l == r + return (l as NSDictionary) == (r as NSDictionary) case (.Null(let l), .Null(let r)): let lcode = l?.code ?? 0 let rcode = l?.code ?? 0 @@ -695,9 +664,9 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { case (.ScalarString(let l), .ScalarString(let r)): return l >= r case (.Sequence(let l), .Sequence(let r)): - return l == r + return (l as NSArray) == (r as NSArray) case (.Mapping(let l), .Mapping(let r)): - return l == r + return (l as NSDictionary) == (r as NSDictionary) case (.Null(let l), .Null(let r)): let lcode = l?.code ?? 0 let rcode = l?.code ?? 0 From 919d4b6030c879532c2d2029e9930d14e8f3c885 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 2 Oct 2014 14:51:40 +0800 Subject: [PATCH 007/470] Add SequenceType methods --- Example.xcodeproj/project.pbxproj | 6 ++- Example/ViewController.swift | 5 +- Source/SwiftyJSON.swift | 84 ++++++++++++++++++++++++++++--- Tests/SwiftyJSONTests.swift | 17 +++++++ 4 files changed, 100 insertions(+), 12 deletions(-) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index f94e3afb..5a8bba51 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -275,6 +275,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -292,7 +293,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 = 7.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -318,6 +319,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; @@ -329,7 +331,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 = 7.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/Example/ViewController.swift b/Example/ViewController.swift index ad79e41b..fecb75e5 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -52,13 +52,14 @@ class ViewController: UITableViewController { switch self.json { case .Sequence(let array): cell.textLabel?.text = "\(row)" - cell.detailTextLabel?.text = JSON(object:array[row]).description + cell.detailTextLabel?.text = self.json.arrayValue.description case .Mapping(let dictionary): let key: AnyObject = (dictionary as NSDictionary).allKeys[row] let value = self.json[key as String] cell.textLabel?.text = "\(key)" - cell.detailTextLabel?.text = value.stringValue + cell.detailTextLabel?.text = value.description default: + cell.textLabel?.text = "" cell.detailTextLabel?.text = self.json.description } diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 46f7f52a..006cead9 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -138,6 +138,54 @@ extension JSON { } } +// MARK: - SequenceType +extension JSON: SequenceType{ + + public var count: Int { + get { + switch self { + case .Sequence(let array): + return array.count + case .Mapping(let dictionary): + return dictionary.count + default: + return 0 + } + } + } + /** + When .Sequence return GeneratorOf<(index, JSON(object:element))> + When .Mapping return GeneratorOf<(key, JSON(value))> + */ + public func generate() -> GeneratorOf <(String, JSON)> { + switch self { + case .Sequence(let array): + var generate = array.generate() + var index: Int = -1 + return GeneratorOf<(String, JSON)> { + if let element: AnyObject = generate.next() { + return ("\(index++)", JSON(object: element)) + } else { + return nil + } + } + case .Mapping(let dictionary): + var generate = dictionary.generate() + return GeneratorOf<(String, JSON)> { + if let (key: String, value: AnyObject) = generate.next() { + return (key, JSON(object: value)) + } else { + return nil + } + } + default: + return GeneratorOf<(String, JSON)> { + return nil + } + } + } +} + // MARK: - Subscript extension JSON { @@ -229,8 +277,7 @@ extension JSON: Printable, DebugPrintable { // MARK: - Sequence: Array extension JSON { - //Optional array - //It's slow + //Optional Array public var array: Array? { get { switch self { @@ -246,20 +293,30 @@ extension JSON { } } - //Non-optional array - //It's slow + //Non-optional Array public var arrayValue: Array { get { return self.array ?? [] } } + + //Optional Array + public var arrayObjects: Array? { + get { + switch self { + case .Sequence(let array): + return array + default: + return nil + } + } + } } // MARK: - Mapping: Dictionary extension JSON { - //Optional dictionary - //It's slow + //Optional Dictionary public var dictionary: Dictionary? { get { switch self { @@ -275,13 +332,24 @@ extension JSON { } } - //Non-optional dictionary - //It's slow + //Non-optional Dictionary public var dictionaryValue: Dictionary { get { return self.dictionary ?? [:] } } + + //Optional Dictionary + public var dictionaryObjects: Dictionary? { + get { + switch self { + case .Mapping(let dictionary): + return dictionary + default: + return nil + } + } + } } //MARK: - Scalar: Bool diff --git a/Tests/SwiftyJSONTests.swift b/Tests/SwiftyJSONTests.swift index d1b01ad1..2d676eab 100644 --- a/Tests/SwiftyJSONTests.swift +++ b/Tests/SwiftyJSONTests.swift @@ -129,6 +129,23 @@ class SwiftyJSONTests: XCTestCase { XCTAssert(user_dictionary_name_profile_image_url == NSURL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) } + func testSequenceType() { + let json = JSON(data:self.testData) + XCTAssertEqual(json.count, 3) + for (_, aJson) in json { + XCTAssertEqual(aJson, json[0]) + break + } + + var index = 0 + let keys = (json[1].dictionaryObjects! as NSDictionary).allKeys as Array + for (aKey, aJson) in json[1] { + XCTAssertEqual(aKey, keys[index]) + XCTAssertEqual(aJson, json[1][keys[index]]) + break + } + } + func testJSONNumberCompare() { XCTAssertEqual(JSON(object: 12376352.123321), JSON(object: 12376352.123321)) XCTAssertGreaterThan(JSON(object: 20.211), JSON(object: 20.112)) From 52486aaa4b6bd88a4e0a1ac33e05ae3871d1fd2e Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 2 Oct 2014 15:21:44 +0800 Subject: [PATCH 008/470] Update README.md --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60466ab1..67f021bf 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,20 @@ let json = JSON(data: dataFromNetworking) ```swift let json = JSON(object: jsonObject) ``` +####Loop +```swift +let json = JSON(data:dataFromNetworking) +//If json is .Mapping +for (key: String, subJson: JSON) in json { +//Do something you want +} + +//If json is .Sequence +//The `index` is 0.. = json["list"].arrayValue let user: Dictionary = json["user"].dictionaryValue ``` -###Get the raw object from JSON +####Get the raw object from JSON ```swift let json = JSON(data: dataFromNetworking) if let jsonObject: AnyObject = json.object { From 59996b25c38ed366209ad76d7a67eb08a7b2dff5 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 6 Oct 2014 23:24:08 +0800 Subject: [PATCH 009/470] Change enum JSON to strut JSON and Add literal convertible protocol --- Source/SwiftyJSON.swift | 962 ++++++++++++++++++++++++---------------- 1 file changed, 592 insertions(+), 370 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 006cead9..43e431f4 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -25,117 +25,102 @@ import Foundation @availability(*, unavailable, renamed="JSON") public typealias JSONValue = JSON +//MARK: - Return Error +//The SwiftyJSON's error domain +public let ErrorDomain: String! = "SwiftyJSONErrorDomain" +//The error code +public let ErrorUnsupportedType: Int! = 999 +public let ErrorIndexOutOfBounds: Int! = 900 +public let ErrorWrongType: Int! = 901 +public let ErrorNotExist: Int! = 500 + +public enum Type :Int{ + + case Number + case String + case Bool + case Array + case Dictionary + case Null + case Unknow +} + //MARK:- Base //http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf -public enum JSON { - - //private type number - case ScalarNumber(NSNumber) - //private type string - case ScalarString(String) - //private type sequence - case Sequence(Array) - //private type mapping - case Mapping(Dictionary) - //private type null - case Null(NSError?) +public struct JSON { + public var type: Type { + get { + return _type + } + set { + _type = newValue + } + } + public var object: AnyObject { + get { + return _object + } + set { + _object = newValue + switch newValue { + case let number as NSNumber: + switch String.fromCString(number.objCType)! { + case "c", "C": + _type = .Bool + default: + _type = .Number + } + case let string as NSString: + _type = .String + case let null as NSNull: + _type = .Null + case let array as Array: + _type = .Array + case let dictionary as Dictionary: + _type = .Dictionary + default: + _type = .Unknow + _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) + } + } + } + + public var error: NSError? { get { return self._error } } + public static var nullJSON: JSON { get { return JSON(NSNull()) } } + /** - :param: data The NSData used to convert to json. - :param: options The JSON serialization reading options. `.AllowFragments` by default. - :param: error The NSErrorPointer used to return the error. `nil` by default. + :param: data The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary + :param: options The JSON serialization reading options. `.AllowFragments` by default. + :param: error The NSErrorPointer used to return the error. `nil` by default. */ public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { - if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error){ - self = JSON(object: object) + if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error) { + self.init(object) } else { - self = .Null(nil) + self.init(NSNull()) } } /** - :param: object The object must have the following properties: - - Top level object is an NSArray or NSDictionary + :param: object The object must have the following properties: - All objects are NSString, NSNumber, NSArray, NSDictionary, or NSNull - All dictionary keys are NSStrings - NSNumbers are not NaN or infinity - in swift + In swift - String as NSString - Bool, Int, Float, Double... as NSNumber - Array as NSArray - Dictionary as NSDictionary with NSString keys */ - public init(object: AnyObject) { - switch object { - case let number as NSNumber: - self = .ScalarNumber(number) - case let string as NSString: - self = .ScalarString(string) - case let null as NSNull: - self = .Null(nil) - case let array as Array: - self = .Sequence(array) - case let dictionary as Dictionary: - self = .Mapping(dictionary) - default: - self = .Null(NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"])) - } - } - - private init(topObject:AnyObject) { - if !NSJSONSerialization.isValidJSONObject(topObject) { - self = .Null(NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"])) - return - } - self = JSON(object: topObject) - } -} - -//MARK: - Return Error -//The SwiftyJSON's error domain -public let ErrorDomain: String! = "SwiftyJSONErrorDomain" -//The error code -public var ErrorUnsupportedType: Int { get { return 999 }} -public var ErrorIndexOutOfBounds: Int { get { return 900 }} -public var ErrorWrongType: Int { get { return 901 }} -public var ErrorNotExist: Int { get { return 500 }} - -extension JSON { - - // The error in the .Null enmu - public var error: NSError? { - get { - switch self { - case .Null(let error) where error != nil: - return error - default: - return nil; - } - } + public init(_ object: AnyObject) { + self.object = object } -} + private var _object: AnyObject = NSNull() + private var _type: Type = .Null + private var _error: NSError? -//MARK:- Object -extension JSON { - - // The json object which is init(object:)'s parameter - public var object: AnyObject? { - switch self { - case .ScalarNumber(let number): - return number - case .ScalarString(let string): - return string - case .Null(let error) where error == nil: - return NSNull() - case .Sequence(let array): - return array - case .Mapping(let dictionary): - return dictionary - default: - return nil - } - } } // MARK: - SequenceType @@ -143,37 +128,37 @@ extension JSON: SequenceType{ public var count: Int { get { - switch self { - case .Sequence(let array): - return array.count - case .Mapping(let dictionary): - return dictionary.count + switch self.type { + case .Array, .Dictionary: + return self.object.count default: return 0 } } } /** - When .Sequence return GeneratorOf<(index, JSON(object:element))> + When .Sequence return GeneratorOf<(index, JSON(element))> When .Mapping return GeneratorOf<(key, JSON(value))> */ public func generate() -> GeneratorOf <(String, JSON)> { - switch self { - case .Sequence(let array): - var generate = array.generate() - var index: Int = -1 + switch self.type { + case .Array: + let array_ = object as Array + var generate_ = array_.generate() + var index_: Int = -1 return GeneratorOf<(String, JSON)> { - if let element: AnyObject = generate.next() { - return ("\(index++)", JSON(object: element)) + if let element_: AnyObject = generate_.next() { + return ("\(index_++)", JSON(element_)) } else { return nil } } - case .Mapping(let dictionary): - var generate = dictionary.generate() + case .Dictionary: + let dictionary_ = object as Dictionary + var generate_ = dictionary_.generate() return GeneratorOf<(String, JSON)> { - if let (key: String, value: AnyObject) = generate.next() { - return (key, JSON(object: value)) + if let (key_: String, value_: AnyObject) = generate_.next() { + return (key_, JSON(value_)) } else { return nil } @@ -194,81 +179,172 @@ extension JSON { */ public subscript(idx: Int) -> JSON { get { - switch self { - case .Sequence(let array): - if array.count > idx { - return JSON(object:array[idx]) + var returnJSON = JSON.nullJSON + if self.type == .Array { + let array_ = self.object as Array + if array_.count > idx { + returnJSON = JSON(array_[idx]) } else { - return .Null(NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"])) + returnJSON._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) + } + } else { + returnJSON._error = NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an array"]) + } + return returnJSON + + } + set { + if self.type == .Array { + var array_ = self.object as Array + if array_.count > idx { + array_[idx] = newValue.object + self.object = array_ } - default: - return .Null(NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an array"])) } } } - + /** If self is .Sequence return the dictionary[key]'s JSON else return .Null with error */ public subscript(key: String) -> JSON { get { - switch self { - case .Mapping(let dictionary): - if let value: AnyObject = dictionary[key] { - return JSON(object:value) + var returnJSON = JSON.nullJSON + if self.type == .Dictionary { + if let object_: AnyObject = self.object[key] { + returnJSON = JSON(object_) } else { - return .Null(NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"])) + returnJSON._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) } - default: - return .Null(NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an dictionary"])) + } else { + returnJSON._error = NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an dictionary"]) + } + return returnJSON + } + set { + if self.type == .Dictionary { + var dictionary_ = self.object as Dictionary + dictionary_[key] = newValue.object + self.object = dictionary_ } } } } +//MARK:- LiteralConvertible +extension JSON: StringLiteralConvertible { + + public static func convertFromStringLiteral(value: StringLiteralType) -> JSON { + return JSON(value) + } + + public static func convertFromExtendedGraphemeClusterLiteral(value: StringLiteralType) -> JSON { + return JSON(value) + } +} + +extension JSON: IntegerLiteralConvertible { + public static func convertFromIntegerLiteral(value: IntegerLiteralType) -> JSON { + return JSON(value) + } +} + +extension JSON: BooleanLiteralConvertible { + public static func convertFromBooleanLiteral(value: BooleanLiteralType) -> JSON { + return JSON(value) + } +} + +extension JSON: FloatLiteralConvertible { + public static func convertFromFloatLiteral(value: FloatLiteralType) -> JSON { + return JSON(value) + } +} + +extension JSON: DictionaryLiteralConvertible { + public static func convertFromDictionaryLiteral(elements: (String, AnyObject)...) -> JSON { + var dictionary_ = [String : AnyObject]() + for (key_, value) in elements { + dictionary_[key_] = value + } + return JSON(dictionary_) + } +} + +extension JSON: ArrayLiteralConvertible { + public static func convertFromArrayLiteral(elements: AnyObject...) -> JSON { + return JSON(elements) + } +} + +extension JSON: NilLiteralConvertible { + public static func convertFromNilLiteral() -> JSON { + return JSON(NSNull()) + } +} + +//MARK:- RawRepresentable +extension JSON: RawRepresentable { + + public static func fromRaw(raw: AnyObject) -> JSON? { + let json = JSON(raw) + if json.type == .Unknow { + return nil + } else { + return json + } + } + + public func toRaw() -> AnyObject { + return self.object + } +} + //MARK: - Printable, DebugPrintable extension JSON: Printable, DebugPrintable { public var description: String { - switch self { - case .ScalarNumber(let number): - if number.isBool { - return number.boolValue.description - } else { - return number.description - } - case .ScalarString(let string): - return string - case .Sequence(let array): - return array.description - case .Mapping(let dictionary): - return dictionary.description - case .Null(let error) where error != nil : - return error!.description - default: - return "null" + get { + switch type { + case .Number: + return self.object.description + case .String: + return self.object as String + case .Array: + return (self.object as Array).description + case .Dictionary: + return (self.object as Dictionary).description + case .Bool: + return (self.object as Bool).description + case .Null: + return self.error?.description ?? "null" + default: + return "unknown" + } } } public var debugDescription: String { get { - switch self { - case .ScalarNumber(let number): - if number.isBool { - return number.boolValue.description + switch type { + case .Number: + return (self.object as NSNumber).debugDescription + case .String: + return self.object as String + case .Array: + return (self.object as Array).debugDescription + case .Dictionary: + return (self.object as Dictionary).debugDescription + case .Bool: + return (self.object as Bool).description + case .Null: + if self.error != nil { + return self.error!.debugDescription } else { - return number.debugDescription + return "null" } - case .ScalarString(let string): - return string.debugDescription - case .Sequence(let array): - return array.debugDescription - case .Mapping(let dictionary): - return dictionary.debugDescription - case .Null(let error) where error != nil : - return error!.debugDescription default: - return "null" + return "unknown" } } } @@ -280,16 +356,15 @@ extension JSON { //Optional Array public var array: Array? { get { - switch self { - case .Sequence(let array): - var jsonArray = Array() - for object in array { - jsonArray.append(JSON(object: object)) + if self.type == .Array { + let array_ = self.object as Array + var returnArray_ = Array() + for subObject_ in array_ { + returnArray_.append(JSON(subObject_)) } - return jsonArray - default: - return nil + return returnArray_ } + return nil } } @@ -301,11 +376,11 @@ extension JSON { } //Optional Array - public var arrayObjects: Array? { + public var arrayObject: Array? { get { - switch self { - case .Sequence(let array): - return array + switch self.type { + case .Array: + return self.object as? Array default: return nil } @@ -319,13 +394,13 @@ extension JSON { //Optional Dictionary public var dictionary: Dictionary? { get { - switch self { - case .Mapping(let dictionary): - var jsonDictionary = Dictionary() - for (key, value) in dictionary { - jsonDictionary[key] = JSON(object: value) + switch self.type { + case .Dictionary: + var jsonDictionary_ = Dictionary() + for (key_, value_) in self.object as Dictionary { + jsonDictionary_[key_] = JSON( value_) } - return jsonDictionary + return jsonDictionary_ default: return nil } @@ -340,11 +415,11 @@ extension JSON { } //Optional Dictionary - public var dictionaryObjects: Dictionary? { + public var dictionaryObject: Dictionary? { get { - switch self { - case .Mapping(let dictionary): - return dictionary + switch self.type { + case .Dictionary: + return self.object as? Dictionary default: return nil } @@ -358,9 +433,9 @@ extension JSON: BooleanType { //Optional bool public var bool: Bool? { get { - switch self { - case .ScalarNumber(let number) where number.isBool: - return number.boolValue + switch self.type { + case .Bool: + return self.object.boolValue default: return nil } @@ -369,19 +444,15 @@ extension JSON: BooleanType { //Non-optional bool public var boolValue: Bool { - switch self { - case .ScalarNumber(let number): - return number.boolValue - case .ScalarString(let string): - return (string as NSString).boolValue - case .Sequence(let array): - return array.count > 0 - case .Mapping(let dictionary): - return dictionary.count > 0 + switch self.type { + case .Bool, .Number, .String: + return self.object.boolValue + case .Array, .Dictionary: + return self.object.count > 0 case .Null: return false default: - return true + return false } } } @@ -392,9 +463,9 @@ extension JSON { //Optional string public var string: String? { get { - switch self { - case .ScalarString(let string): - return string + switch self.type { + case .String: + return self.object as? String default: return nil } @@ -404,15 +475,13 @@ extension JSON { //Non-optional string public var stringValue: String { get { - switch self { - case .ScalarString(let string): - return string - case .ScalarNumber(let number): - if number.isBool { - return number.boolValue.description - } else { - return number.stringValue - } + switch self.type { + case .String: + return self.object as String + case .Number: + return self.object.stringValue + case .Bool: + return (self.object as Bool).description default: return "" } @@ -426,9 +495,9 @@ extension JSON { //Optional number public var number: NSNumber? { get { - switch self { - case .ScalarNumber(let number): - return number + switch self.type { + case .Number, .Bool: + return self.object as? NSNumber default: return nil } @@ -438,17 +507,17 @@ extension JSON { //Non-optional number public var numberValue: NSNumber { get { - switch self { - case .ScalarString(let string): - let scanner = NSScanner(string: string) + switch self.type { + case .String: + let scanner = NSScanner(string: self.object as String) if scanner.scanDouble(nil){ if (scanner.atEnd) { - return NSNumber(double:(string as NSString).doubleValue) + return NSNumber(double:(self.object as NSString).doubleValue) } } return NSNumber(double: 0.0) - case .ScalarNumber(let number): - return number + case .Number, .Bool: + return self.object as NSNumber default: return NSNumber(double: 0.0) } @@ -461,8 +530,8 @@ extension JSON { public var null: NSNull? { get { - switch self { - case .Null(let error) where error == nil: + switch self.type { + case .Null: return NSNull() default: return nil @@ -477,10 +546,10 @@ extension JSON { //Optional URL public var URL: NSURL? { get { - switch self { - case .ScalarString(let string): - if let encodedString = string.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { - return NSURL(string: encodedString) + switch self.type { + case .String: + if let encodedString_ = self.object.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { + return NSURL(string: encodedString_) } else { return nil } @@ -494,185 +563,183 @@ extension JSON { //MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 extension JSON { - //Optional Int8 - public var char: Int8? { + public var double: Double? { get { - return self.number?.charValue + if self.type == .Number { + return self.object.doubleValue + } + return nil } } - - //Optional Int8 - public var charValue: Int8 { + + public var doubleValue: Double { get { - return self.numberValue.charValue + return self.double ?? 0.0 } } - //Optional UInt8 - public var unsignedChar: UInt8? { - get{ - return self.number?.unsignedCharValue + public var float: Float? { + get { + if self.type == .Number { + return self.object.floatValue + } + return nil } } - //Non-optional UInt8 - public var unsignedCharValue: UInt8 { - get{ - return self.numberValue.unsignedCharValue + public var floatValue: Float { + get { + return self.float ?? 0.0 } } - //Optional Int16 - public var short: Int16? { - get{ - return self.number?.shortValue + public var int: Int? { + get { + if self.type == .Number { + return self.object.longValue + } + return nil } } - //Non-optional UInt8 - public var shortValue: Int16 { - get{ - return self.numberValue.shortValue + public var intValue: Int { + get { + return self.int ?? 0 } } - //Optional UInt16 - public var unsignedShort: UInt16? { - get{ - return self.number?.unsignedShortValue + public var uInt: UInt? { + get { + if self.type == .Number { + return self.object.unsignedLongValue + } + return nil } } - //Non-optional UInt16 - public var unsignedShortValue: UInt16 { - get{ - return self.numberValue.unsignedShortValue + public var uIntValue: UInt { + get { + return self.uInt ?? 0 } } - - //Optional Int - public var long: Int? { - get{ - return self.number?.longValue + + public var int8: Int8? { + get { + if self.type == .Number { + return self.object.charValue + } + return nil } } - //Non-optional Int - public var longValue: Int { - get{ - return self.numberValue.longValue + public var int8Value: Int8 { + get { + return self.int8 ?? 0 } } - //Optional UInt - public var unsignedLong: UInt? { - get{ - return self.number?.unsignedLongValue + public var uInt8: UInt8? { + get { + if self.type == .Number { + return self.object.unsignedCharValue + } + return nil } } - //Non-optional UInt - public var unsignedLongValue: UInt { - get{ - return self.numberValue.unsignedLongValue + public var uInt8Value: UInt8 { + get { + return self.uInt8 ?? 0 } } - //Optional Int64 - public var longLong: Int64? { - get{ - return self.number?.longLongValue - } - } - - //Non-optional Int64 - public var longLongValue: Int64 { - get{ - return self.numberValue.longLongValue + public var int16: Int16? { + get { + if self.type == .Number { + return self.object.shortValue + } + return nil } } - //Optional UInt64 - public var unsignedLongLong: UInt64? { - get{ - return self.number?.unsignedLongLongValue - } - } - - //Non-optional UInt64 - public var unsignedLongLongValue: UInt64 { - get{ - return self.numberValue.unsignedLongLongValue + public var int16Value: Int16 { + get { + return self.int16 ?? 0 } } - //Optional Float - public var float: Float? { + public var uInt16: UInt16? { get { - return self.number?.floatValue + if self.type == .Number { + return self.object.unsignedShortValue + } + return nil } } - //Non-optional Float - public var floatValue: Float { + public var uInt16Value: UInt16 { get { - return self.numberValue.floatValue + return self.uInt16 ?? 0 } } - - //Optional Double - public var double: Double? { + + public var int32: Int32? { get { - return self.number?.doubleValue + if self.type == .Number { + return self.object.intValue + } + return nil } } - - //Non-optional Double - public var doubleValue: Double { + + public var int32Value: Int32 { get { - return self.numberValue.doubleValue + return self.int32 ?? 0 } } - - //Optional Int - public var integer: Int? { + + public var uInt32: UInt32? { get { - return self.number?.integerValue + if self.type == .Number { + return self.object.unsignedIntValue + } + return nil } } - - //Non-optional Int - public var integerValue: Int { + + public var uInt32Value: UInt32 { get { - return self.numberValue.integerValue + return self.uInt32 ?? 0 } } - //Optional Int - public var unsignedInteger: Int? { + public var int64: Int64? { get { - return self.number?.unsignedIntegerValue + if self.type == .Number { + return self.object.longLongValue + } + return nil } } - //Non-optional Int - public var unsignedIntegerValue: Int { + public var int64Value: Int64 { get { - return self.numberValue.unsignedIntegerValue + return self.int64 ?? 0 } } - //Optional Int32 - public var int: Int32? { + public var uInt64: UInt64? { get { - return self.number?.intValue + if self.type == .Number { + return self.object.unsignedLongLongValue + } + return nil } } - //non-optional Int32 - public var intValue: Int32 { + public var uInt64Value: UInt64 { get { - return self.numberValue.intValue + return self.uInt64 ?? 0 } } } @@ -682,43 +749,39 @@ extension JSON: Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { - switch (lhs, rhs) { - case (.ScalarNumber(let l), .ScalarNumber(let r)): - return l == r - case (.ScalarString(let l), .ScalarString(let r)): - return l == r - case (.Sequence(let l), .Sequence(let r)): - return (l as NSArray) == (r as NSArray) - case (.Mapping(let l), .Mapping(let r)): - return (l as NSDictionary) == (r as NSDictionary) - case (.Null(let l), .Null(let r)): - let lcode = l?.code ?? 0 - let rcode = l?.code ?? 0 - return lcode == rcode + switch (lhs.type, rhs.type) { + case (.Number, .Number): + return (lhs.object as NSNumber) == (rhs.object as NSNumber) + case (.String, .String): + return (lhs.object as String) == (rhs.object as String) + case (.Bool, .Bool): + return (lhs.object as Bool) == (rhs.object as Bool) + case (.Array, .Array): + return (lhs.object as NSArray) == (rhs.object as NSArray) + case (.Dictionary, .Dictionary): + return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) + case (.Null, .Null): + return true default: return false } } -public func !=(lhs: JSON, rhs: JSON) -> Bool { - return !(lhs == rhs) -} - public func <=(lhs: JSON, rhs: JSON) -> Bool { - switch (lhs, rhs) { - case (.ScalarNumber(let l), .ScalarNumber(let r)): - return l <= r - case (.ScalarString(let l), .ScalarString(let r)): - return l <= r - case (.Sequence(let l), .Sequence(let r)): - return (l as NSArray) == (r as NSArray) - case (.Mapping(let l), .Mapping(let r)): - return (l as NSDictionary) == (r as NSDictionary) - case (.Null(let l), .Null(let r)): - let lcode = l?.code ?? 0 - let rcode = l?.code ?? 0 - return lcode == rcode + switch (lhs.type, rhs.type) { + case (.Number, .Number): + return (lhs.object as NSNumber) <= (rhs.object as NSNumber) + case (.String, .String): + return (lhs.object as String) <= (rhs.object as String) + case (.Bool, .Bool): + return (lhs.object as Bool) == (rhs.object as Bool) + case (.Array, .Array): + return (lhs.object as NSArray) == (rhs.object as NSArray) + case (.Dictionary, .Dictionary): + return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) + case (.Null, .Null): + return true default: return false } @@ -726,19 +789,19 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { public func >=(lhs: JSON, rhs: JSON) -> Bool { - switch (lhs, rhs) { - case (.ScalarNumber(let l), .ScalarNumber(let r)): - return l >= r - case (.ScalarString(let l), .ScalarString(let r)): - return l >= r - case (.Sequence(let l), .Sequence(let r)): - return (l as NSArray) == (r as NSArray) - case (.Mapping(let l), .Mapping(let r)): - return (l as NSDictionary) == (r as NSDictionary) - case (.Null(let l), .Null(let r)): - let lcode = l?.code ?? 0 - let rcode = l?.code ?? 0 - return lcode == rcode + switch (lhs.type, rhs.type) { + case (.Number, .Number): + return (lhs.object as NSNumber) >= (rhs.object as NSNumber) + case (.String, .String): + return (lhs.object as String) >= (rhs.object as String) + case (.Bool, .Bool): + return (lhs.object as Bool) == (rhs.object as Bool) + case (.Array, .Array): + return (lhs.object as NSArray) == (rhs.object as NSArray) + case (.Dictionary, .Dictionary): + return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) + case (.Null, .Null): + return true default: return false } @@ -746,11 +809,11 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { public func >(lhs: JSON, rhs: JSON) -> Bool { - switch (lhs, rhs) { - case (.ScalarNumber(let l), .ScalarNumber(let r)): - return l > r - case (.ScalarString(let l), .ScalarString(let r)): - return l > r + switch (lhs.type, rhs.type) { + case (.Number, .Number): + return (lhs.object as NSNumber) > (rhs.object as NSNumber) + case (.String, .String): + return (lhs.object as String) > (rhs.object as String) default: return false } @@ -758,11 +821,11 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { public func <(lhs: JSON, rhs: JSON) -> Bool { - switch (lhs, rhs) { - case (.ScalarNumber(let l), .ScalarNumber(let r)): - return l < r - case (.ScalarString(let l), .ScalarString(let r)): - return l < r + switch (lhs.type, rhs.type) { + case (.Number, .Number): + return (lhs.object as NSNumber) < (rhs.object as NSNumber) + case (.String, .String): + return (lhs.object as String) < (rhs.object as String) default: return false } @@ -843,4 +906,163 @@ public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { default: return lhs.compare(rhs) != NSComparisonResult.OrderedAscending } +} + +//MARK:- Unavailable +extension JSON { + + @availability(*, unavailable, message="use 'init(_ object:AnyObject)' instead") + public init(object: AnyObject) { + self = JSON(object) + } + + @availability(*, unavailable, renamed="dictionaryObject") + public var dictionaryObjects: Dictionary? { + get { return self.dictionaryObject } + } + + @availability(*, unavailable, renamed="arrayObject") + public var arrayObjects: Array? { + get { return self.arrayObject } + } + + @availability(*, unavailable, renamed="int8") + public var char: Int8? { + get { + return self.number?.charValue + } + } + + @availability(*, unavailable, renamed="int8Value") + public var charValue: Int8 { + get { + return self.numberValue.charValue + } + } + + @availability(*, unavailable, renamed="uInt8") + public var unsignedChar: UInt8? { + get{ + return self.number?.unsignedCharValue + } + } + + @availability(*, unavailable, renamed="uInt8Value") + public var unsignedCharValue: UInt8 { + get{ + return self.numberValue.unsignedCharValue + } + } + + @availability(*, unavailable, renamed="int16") + public var short: Int16? { + get{ + return self.number?.shortValue + } + } + + @availability(*, unavailable, renamed="int16Value") + public var shortValue: Int16 { + get{ + return self.numberValue.shortValue + } + } + + @availability(*, unavailable, renamed="uInt16") + public var unsignedShort: UInt16? { + get{ + return self.number?.unsignedShortValue + } + } + + @availability(*, unavailable, renamed="uInt16Value") + public var unsignedShortValue: UInt16 { + get{ + return self.numberValue.unsignedShortValue + } + } + + @availability(*, unavailable, renamed="int") + public var long: Int? { + get{ + return self.number?.longValue + } + } + + @availability(*, unavailable, renamed="intValue") + public var longValue: Int { + get{ + return self.numberValue.longValue + } + } + + @availability(*, unavailable, renamed="uInt") + public var unsignedLong: UInt? { + get{ + return self.number?.unsignedLongValue + } + } + + @availability(*, unavailable, renamed="uIntValue") + public var unsignedLongValue: UInt { + get{ + return self.numberValue.unsignedLongValue + } + } + + @availability(*, unavailable, renamed="int64") + public var longLong: Int64? { + get{ + return self.number?.longLongValue + } + } + + @availability(*, unavailable, renamed="int64Value") + public var longLongValue: Int64 { + get{ + return self.numberValue.longLongValue + } + } + + @availability(*, unavailable, renamed="uInt64") + public var unsignedLongLong: UInt64? { + get{ + return self.number?.unsignedLongLongValue + } + } + + @availability(*, unavailable, renamed="uInt64Value") + public var unsignedLongLongValue: UInt64 { + get{ + return self.numberValue.unsignedLongLongValue + } + } + + @availability(*, unavailable, renamed="int") + public var integer: Int? { + get { + return self.number?.integerValue + } + } + + @availability(*, unavailable, renamed="intValue") + public var integerValue: Int { + get { + return self.numberValue.integerValue + } + } + + @availability(*, unavailable, renamed="uInt") + public var unsignedInteger: Int? { + get { + return self.number?.unsignedIntegerValue + } + } + + @availability(*, unavailable, renamed="uIntValue") + public var unsignedIntegerValue: Int { + get { + return self.numberValue.unsignedIntegerValue + } + } } \ No newline at end of file From 748ef28c3792c6e2f06ec57b1ea8c2fa9ef26b88 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 6 Oct 2014 23:25:13 +0800 Subject: [PATCH 010/470] Update the test case and Add literal convertible tests --- SwiftyJSON.xcodeproj/project.pbxproj | 8 ++ Tests/LiteralConvertibleTests.swift | 74 ++++++++++++ Tests/RawRepresentableTests.swift | 99 +++++++++++++++ Tests/SwiftyJSONTests.swift | 173 ++++++++++++++------------- 4 files changed, 272 insertions(+), 82 deletions(-) create mode 100644 Tests/LiteralConvertibleTests.swift create mode 100644 Tests/RawRepresentableTests.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 5e2d3b7a..205c4ca4 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; + A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; + A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; @@ -29,6 +31,8 @@ 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; + A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; @@ -95,6 +99,8 @@ children = ( A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */, A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */, + A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */, + A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); path = Tests; @@ -224,7 +230,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, + A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift new file mode 100644 index 00000000..eadfe948 --- /dev/null +++ b/Tests/LiteralConvertibleTests.swift @@ -0,0 +1,74 @@ +// SwiftyJSONTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class LiteralConvertibleTests: XCTestCase { + + func testNumber() { + var json:JSON = 1234567890.876623 + XCTAssertEqual(json.int!, 1234567890) + XCTAssertEqual(json.intValue, 1234567890) + XCTAssertEqual(json.double!, 1234567890.876623) + XCTAssertEqual(json.doubleValue, 1234567890.876623) + XCTAssertEqual(json.float!, 1234567890.876623) + XCTAssertEqual(json.floatValue, 1234567890.876623) + } + + func testBool() { + var jsonTrue:JSON = true + XCTAssertEqual(jsonTrue.bool!, true) + XCTAssertEqual(jsonTrue.boolValue, true) + var jsonFalse:JSON = false + XCTAssertEqual(jsonFalse.bool!, false) + XCTAssertEqual(jsonFalse.boolValue, false) + } + + func testString() { + var json:JSON = "abcd efg, HIJK;LMn" + XCTAssertEqual(json.string!, "abcd efg, HIJK;LMn") + XCTAssertEqual(json.stringValue, "abcd efg, HIJK;LMn") + } + + func testNil() { + var jsonNil_1:JSON = nil + XCTAssert(jsonNil_1 == nil) + var jsonNil_2:JSON = JSON(NSNull) + XCTAssert(jsonNil_2 != nil) + var jsonNil_3:JSON = JSON([1:2]) + XCTAssert(jsonNil_3 != nil) + } + + func testArray() { + var json:JSON = [1,2,"4",5,"6"] + XCTAssertEqual(json.array!, [1,2,"4",5,"6"]) + XCTAssertEqual(json.arrayValue, [1,2,"4",5,"6"]) + } + + func testDictionary() { + var json:JSON = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] + XCTAssertEqual(json.dictionary!, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) + XCTAssertEqual(json.dictionaryValue, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) + } +} diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift new file mode 100644 index 00000000..dc5ab5ec --- /dev/null +++ b/Tests/RawRepresentableTests.swift @@ -0,0 +1,99 @@ +// +// RawRepresentable.swift +// SwiftyJSON +// +// Created by Pinglin Tang on 14-10-6. +// +// + +import UIKit +import XCTest +import SwiftyJSON + +class RawRepresentableTests: XCTestCase { + + func testNumber() { + var json:JSON = JSON.fromRaw(948394394.347384 as NSNumber)! + XCTAssertEqual(json.int!, 948394394) + XCTAssertEqual(json.intValue, 948394394) + XCTAssertEqual(json.double!, 948394394.347384) + XCTAssertEqual(json.doubleValue, 948394394.347384) + XCTAssertEqual(json.float!, 948394394.347384) + XCTAssertEqual(json.floatValue, 948394394.347384) + + var object: AnyObject = json.toRaw() + XCTAssertEqual(object as Int, 948394394) + XCTAssertEqual(object as Double, 948394394.347384) + XCTAssertEqual(object as Float, 948394394.347384) + XCTAssertEqual(object as NSNumber, 948394394.347384) + } + + func testBool() { + var jsonTrue:JSON = JSON.fromRaw(true as NSNumber)! + XCTAssertEqual(jsonTrue.bool!, true) + XCTAssertEqual(jsonTrue.boolValue, true) + + var jsonFalse:JSON = JSON.fromRaw(false)! + XCTAssertEqual(jsonFalse.bool!, false) + XCTAssertEqual(jsonFalse.boolValue, false) + + var objectTrue: AnyObject = jsonTrue.toRaw() + XCTAssertEqual(objectTrue as Int, 1) + XCTAssertEqual(objectTrue as Double, 1.0) + XCTAssertEqual(objectTrue as Float, 1.0) + XCTAssertEqual(objectTrue as Bool, true) + XCTAssertEqual(objectTrue as NSNumber, NSNumber(bool: true)) + + var objectFalse: AnyObject = jsonFalse.toRaw() + XCTAssertEqual(objectFalse as Int, 0) + XCTAssertEqual(objectFalse as Double, 0.0) + XCTAssertEqual(objectFalse as Float, 0.0) + XCTAssertEqual(objectFalse as Bool, false) + XCTAssertEqual(objectFalse as NSNumber, NSNumber(bool: false)) + } + + func testString() { + let string = "The better way to deal with JSON data in Swift." + if let json:JSON = JSON.fromRaw(string) { + XCTAssertEqual(json.string!, string) + XCTAssertEqual(json.stringValue, string) + XCTAssertTrue(json.array == nil) + XCTAssertTrue(json.dictionary == nil) + XCTAssertTrue(json.null == nil) + XCTAssertTrue(json.error == nil) + XCTAssertTrue(json.type == .String) + XCTAssertEqual(json.object as String, string) + } else { + XCTFail("Should not run into here") + } + + let object: AnyObject = JSON.fromRaw(string)!.toRaw() + XCTAssertEqual(object as String, string) + } + + func testNil() { + if let json = JSON.fromRaw(NSObject()) { + XCTFail("Should not run into here") + } + } + + func testArray() { + let array = [1,2,"3",4102,"5632", "abocde", "!@# $%^&*()"] as NSArray + if let json:JSON = JSON.fromRaw(array) { + XCTAssertEqual(json, JSON(array)) + } + + let object: AnyObject = JSON.fromRaw(array)!.toRaw() + XCTAssertTrue(array == object as NSArray) + } + + func testDictionary() { + let dictionary = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] as NSDictionary + if let json:JSON = JSON.fromRaw(dictionary) { + XCTAssertEqual(json, JSON(dictionary)) + } + + let object: AnyObject = JSON.fromRaw(dictionary)!.toRaw() + XCTAssertTrue(dictionary == object as NSDictionary) + } +} diff --git a/Tests/SwiftyJSONTests.swift b/Tests/SwiftyJSONTests.swift index 2d676eab..bd059b30 100644 --- a/Tests/SwiftyJSONTests.swift +++ b/Tests/SwiftyJSONTests.swift @@ -46,31 +46,36 @@ class SwiftyJSONTests: XCTestCase { func testInit() { let json0 = JSON(data:self.testData) XCTAssertEqual(json0.array!.count, 3) - XCTAssertEqual(JSON(object: "123").description, "123") - XCTAssertEqual(JSON(object: ["1":"2"]).description, ["1":"2"].description) + XCTAssertEqual(JSON("123").description, "123") + XCTAssertEqual(JSON(["1":"2"]).description, ["1":"2"].description) var dictionary = NSMutableDictionary() dictionary.setObject(NSNumber(double: 1.0), forKey: "number" as NSString) dictionary.setObject(NSNull(), forKey: "null" as NSString) - let json1 = JSON(object: dictionary) + let json1 = JSON(dictionary) if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(self.testData, options: nil, error: nil){ - let json2 = JSON(object: object) + let json2 = JSON(object) XCTAssertEqual(json0, json2) } } + + func testCompare2() { + let json = JSON("32.1234567890") + + } func testCompare() { - XCTAssertNotEqual(JSON(object: "32.1234567890"), JSON(object: 32.1234567890)) - XCTAssertNotEqual(JSON(object: "9876543210987654321"),JSON(object: NSNumber(unsignedLongLong:9876543210987654321))) - XCTAssertNotEqual(JSON(object: "9876543210987654321.12345678901234567890"), JSON(object: 9876543210987654321.12345678901234567890)) - XCTAssertEqual(JSON(object: "😊"), JSON(object: "😊")) - XCTAssertNotEqual(JSON(object: "😱"), JSON(object: "😁")) - XCTAssertEqual(JSON(object: [123,321,456]), JSON(object: [123,321,456])) - XCTAssertNotEqual(JSON(object: [123,321,456]), JSON(object: 123456789)) - XCTAssertNotEqual(JSON(object: [123,321,456]), JSON(object: "string")) - XCTAssertNotEqual(JSON(object: ["1":123,"2":321,"3":456]), JSON(object: "string")) - XCTAssertEqual(JSON(object: ["1":123,"2":321,"3":456]), JSON(object: ["2":321,"1":123,"3":456])) - XCTAssertEqual(JSON(object: NSNull()),JSON(object: NSNull())) - XCTAssertNotEqual(JSON(object: NSNull()), JSON(object: 123)) + XCTAssertNotEqual(JSON("32.1234567890"), JSON(32.1234567890)) + XCTAssertNotEqual(JSON("9876543210987654321"),JSON(NSNumber(unsignedLongLong:9876543210987654321))) + XCTAssertNotEqual(JSON("9876543210987654321.12345678901234567890"), JSON(9876543210987654321.12345678901234567890)) + XCTAssertEqual(JSON("😊"), JSON("😊")) + XCTAssertNotEqual(JSON("😱"), JSON("😁")) + XCTAssertEqual(JSON([123,321,456]), JSON([123,321,456])) + XCTAssertNotEqual(JSON([123,321,456]), JSON(123456789)) + XCTAssertNotEqual(JSON([123,321,456]), JSON("string")) + XCTAssertNotEqual(JSON(["1":123,"2":321,"3":456]), JSON("string")) + XCTAssertEqual(JSON(["1":123,"2":321,"3":456]), JSON(["2":321,"1":123,"3":456])) + XCTAssertEqual(JSON(NSNull()),JSON(NSNull())) + XCTAssertNotEqual(JSON(NSNull()), JSON(123)) } func testJSONDoesProduceValidWithCorrectKeyPath() { @@ -82,17 +87,17 @@ class SwiftyJSONTests: XCTestCase { let tweets_array_1 = tweets_1[1] let tweets_1_user_name = tweets_1["user"]["name"] let tweets_1_user_name_string = tweets_1["user"]["name"].string - XCTAssertNotEqual(tweets, JSON.Null(nil)) + XCTAssertNotEqual(tweets.type, Type.Null) XCTAssert(tweets_array != nil) - XCTAssertNotEqual(tweets_1, JSON.Null(nil)) - XCTAssertEqual(tweets_1_user_name, JSON(object:"Raffi Krikorian")) + XCTAssertNotEqual(tweets_1.type, Type.Null) + XCTAssertEqual(tweets_1_user_name, JSON("Raffi Krikorian")) XCTAssertEqual(tweets_1_user_name_string!, "Raffi Krikorian") let tweets_1_coordinates = tweets_1["coordinates"] let tweets_1_coordinates_coordinates = tweets_1_coordinates["coordinates"] let tweets_1_coordinates_coordinates_point_0_double = tweets_1_coordinates_coordinates[0].double let tweets_1_coordinates_coordinates_point_1_float = tweets_1_coordinates_coordinates[1].float - let new_tweets_1_coordinates_coordinates = JSON(object:[-122.25831,37.871609]) + let new_tweets_1_coordinates_coordinates = JSON([-122.25831,37.871609]) XCTAssertEqual(tweets_1_coordinates_coordinates, new_tweets_1_coordinates_coordinates) XCTAssertEqual(tweets_1_coordinates_coordinates_point_0_double!, -122.25831) XCTAssertEqual(tweets_1_coordinates_coordinates_point_1_float!, 37.871609) @@ -102,19 +107,19 @@ class SwiftyJSONTests: XCTestCase { XCTAssertEqual(tweets_1_coordinates_coordinates_point_1_string, "37.871609") let tweets_1_coordinates_coordinates_point_0 = tweets_1_coordinates_coordinates[0] let tweets_1_coordinates_coordinates_point_1 = tweets_1_coordinates_coordinates[1] - XCTAssertEqual(tweets_1_coordinates_coordinates_point_0, JSON(object:-122.25831)) - XCTAssertEqual(tweets_1_coordinates_coordinates_point_1, JSON(object:37.871609)) + XCTAssertEqual(tweets_1_coordinates_coordinates_point_0, JSON(-122.25831)) + XCTAssertEqual(tweets_1_coordinates_coordinates_point_1, JSON(37.871609)) let created_at = json[0]["created_at"].string let id_str = json[0]["id_str"].string let favorited = json[0]["favorited"].bool - let id = json[0]["id"].longLong + let id = json[0]["id"].int let in_reply_to_user_id_str = json[0]["in_reply_to_user_id_str"] XCTAssertEqual(created_at!, "Tue Aug 28 21:16:23 +0000 2012") XCTAssertEqual(id_str!,"240558470661799936") XCTAssertFalse(favorited!) XCTAssertEqual(id!,240558470661799936) - XCTAssertEqual(in_reply_to_user_id_str,JSON.Null(nil)) + XCTAssertEqual(in_reply_to_user_id_str.type, Type.Null) let user = json[0]["user"] let user_name = user["name"].string @@ -138,7 +143,7 @@ class SwiftyJSONTests: XCTestCase { } var index = 0 - let keys = (json[1].dictionaryObjects! as NSDictionary).allKeys as Array + let keys = (json[1].dictionaryObject! as NSDictionary).allKeys as Array for (aKey, aJson) in json[1] { XCTAssertEqual(aKey, keys[index]) XCTAssertEqual(aJson, json[1][keys[index]]) @@ -147,75 +152,80 @@ class SwiftyJSONTests: XCTestCase { } func testJSONNumberCompare() { - XCTAssertEqual(JSON(object: 12376352.123321), JSON(object: 12376352.123321)) - XCTAssertGreaterThan(JSON(object: 20.211), JSON(object: 20.112)) - XCTAssertGreaterThanOrEqual(JSON(object: 30.211), JSON(object: 20.112)) - XCTAssertGreaterThanOrEqual(JSON(object: 65232), JSON(object: 65232)) - XCTAssertLessThan(JSON(object: -82320.211), JSON(object: 20.112)) - XCTAssertLessThanOrEqual(JSON(object: -320.211), JSON(object: 123.1)) - XCTAssertLessThanOrEqual(JSON(object: -8763), JSON(object: -8763)) + XCTAssertEqual(JSON(12376352.123321), JSON(12376352.123321)) + XCTAssertGreaterThan(JSON(20.211), JSON(20.112)) + XCTAssertGreaterThanOrEqual(JSON(30.211), JSON(20.112)) + XCTAssertGreaterThanOrEqual(JSON(65232), JSON(65232)) + XCTAssertLessThan(JSON(-82320.211), JSON(20.112)) + XCTAssertLessThanOrEqual(JSON(-320.211), JSON(123.1)) + XCTAssertLessThanOrEqual(JSON(-8763), JSON(-8763)) - XCTAssertEqual(JSON(object: 12376352.123321), JSON(object: 12376352.123321)) - XCTAssertGreaterThan(JSON(object: 20.211), JSON(object: 20.112)) - XCTAssertGreaterThanOrEqual(JSON(object: 30.211), JSON(object: 20.112)) - XCTAssertGreaterThanOrEqual(JSON(object: 65232), JSON(object: 65232)) - XCTAssertLessThan(JSON(object: -82320.211), JSON(object: 20.112)) - XCTAssertLessThanOrEqual(JSON(object: -320.211), JSON(object: 123.1)) - XCTAssertLessThanOrEqual(JSON(object: -8763), JSON(object: -8763)) + XCTAssertEqual(JSON(12376352.123321), JSON(12376352.123321)) + XCTAssertGreaterThan(JSON(20.211), JSON(20.112)) + XCTAssertGreaterThanOrEqual(JSON(30.211), JSON(20.112)) + XCTAssertGreaterThanOrEqual(JSON(65232), JSON(65232)) + XCTAssertLessThan(JSON(-82320.211), JSON(20.112)) + XCTAssertLessThanOrEqual(JSON(-320.211), JSON(123.1)) + XCTAssertLessThanOrEqual(JSON(-8763), JSON(-8763)) } func testNumberConverToString(){ - XCTAssertEqual(JSON(object: true).stringValue, "true") - XCTAssertEqual(JSON(object: 999.9823).stringValue, "999.9823") - - XCTAssertEqual(JSON(object: true).number!.stringValue, "1") - XCTAssertEqual(JSON(object: false).number!.stringValue, "0") - XCTAssertEqual(JSON(object: "hello").numberValue.stringValue, "0") - XCTAssertEqual(JSON(object: NSNull()).numberValue.stringValue, "0") - XCTAssertEqual(JSON(object: ["a","b","c","d"]).numberValue.stringValue, "0") - XCTAssertEqual(JSON(object: ["a":"b","c":"d"]).numberValue.stringValue, "0") + XCTAssertEqual(JSON(true).stringValue, "true") + XCTAssertEqual(JSON(999.9823).stringValue, "999.9823") + XCTAssertEqual(JSON(true).number!.stringValue, "1") + XCTAssertEqual(JSON(false).number!.stringValue, "0") + XCTAssertEqual(JSON("hello").numberValue.stringValue, "0") + XCTAssertEqual(JSON(NSNull()).numberValue.stringValue, "0") + XCTAssertEqual(JSON(["a","b","c","d"]).numberValue.stringValue, "0") + XCTAssertEqual(JSON(["a":"b","c":"d"]).numberValue.stringValue, "0") } func testNumberPrint(){ - XCTAssertEqual(JSON(object: false).description,"false") - XCTAssertEqual(JSON(object: true).description,"true") + XCTAssertEqual(JSON(false).description,"false") + XCTAssertEqual(JSON(true).description,"true") - XCTAssertEqual(JSON(object: 1).description,"1") - XCTAssertEqual(JSON(object: 22).description,"22") - XCTAssertEqual(JSON(object: 2147483647).description,"2147483647") - XCTAssertEqual(JSON(object: 2147483648).description,"2147483648") + XCTAssertEqual(JSON(1).description,"1") + XCTAssertEqual(JSON(22).description,"22") + XCTAssertEqual(JSON(2147483647).description,"2147483647") + XCTAssertEqual(JSON(2147483648).description,"2147483648") - XCTAssertEqual(JSON(object: -1).description,"-1") - XCTAssertEqual(JSON(object: -934834834).description,"-934834834") - XCTAssertEqual(JSON(object: -2147483648).description,"-2147483648") + XCTAssertEqual(JSON(-1).description,"-1") + XCTAssertEqual(JSON(-934834834).description,"-934834834") + XCTAssertEqual(JSON(-2147483648).description,"-2147483648") - XCTAssertEqual(JSON(object: 1.5555).description,"1.5555") - XCTAssertEqual(JSON(object: -9.123456789).description,"-9.123456789") - XCTAssertEqual(JSON(object: -0.00000000000000001).description,"-1e-17") - XCTAssertEqual(JSON(object: -999999999999999999999999.000000000000000000000001).description,"-1e+24") - XCTAssertEqual(JSON(object: -9999999991999999999999999.88888883433343439438493483483943948341).stringValue,"-9.999999991999999e+24") + XCTAssertEqual(JSON(1.5555).description,"1.5555") + XCTAssertEqual(JSON(-9.123456789).description,"-9.123456789") + XCTAssertEqual(JSON(-0.00000000000000001).description,"-1e-17") + XCTAssertEqual(JSON(-999999999999999999999999.000000000000000000000001).description,"-1e+24") + XCTAssertEqual(JSON(-9999999991999999999999999.88888883433343439438493483483943948341).stringValue,"-9.999999991999999e+24") - XCTAssertEqual(JSON(object: Int(Int.max)).description,"\(Int.max)") - XCTAssertEqual(JSON(object: NSNumber(long: Int.min)).description,"\(Int.min)") - XCTAssertEqual(JSON(object: NSNumber(unsignedLong: ULONG_MAX)).description,"\(ULONG_MAX)") - XCTAssertEqual(JSON(object: NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") - XCTAssertEqual(JSON(object: NSNumber(longLong: Int64.max)).description,"\(Int64.max)") - XCTAssertEqual(JSON(object: NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") + XCTAssertEqual(JSON(Int(Int.max)).description,"\(Int.max)") + XCTAssertEqual(JSON(NSNumber(long: Int.min)).description,"\(Int.min)") + XCTAssertEqual(JSON(NSNumber(unsignedLong: ULONG_MAX)).description,"\(ULONG_MAX)") + XCTAssertEqual(JSON(NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") + XCTAssertEqual(JSON(NSNumber(longLong: Int64.max)).description,"\(Int64.max)") + XCTAssertEqual(JSON(NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") - XCTAssertEqual(JSON(object: Double.infinity).description,"inf") - XCTAssertEqual(JSON(object: -Double.infinity).description,"-inf") - XCTAssertEqual(JSON(object: Double.NaN).description,"nan") + XCTAssertEqual(JSON(Double.infinity).description,"inf") + XCTAssertEqual(JSON(-Double.infinity).description,"-inf") + XCTAssertEqual(JSON(Double.NaN).description,"nan") - XCTAssertEqual(JSON(object: 1.0/0.0).description,"inf") - XCTAssertEqual(JSON(object: -1.0/0.0).description,"-inf") - XCTAssertEqual(JSON(object: 0.0/0.0).description,"nan") + XCTAssertEqual(JSON(1.0/0.0).description,"inf") + XCTAssertEqual(JSON(-1.0/0.0).description,"-inf") + XCTAssertEqual(JSON(0.0/0.0).description,"nan") } - func testNullPrint() { - XCTAssertEqual(JSON.Null(nil).debugDescription,"null") - let error = NSError(domain: SwiftyJSON.ErrorDomain, code: SwiftyJSON.ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "hello world"]) - XCTAssertEqual(JSON.Null(error).description,"\(error)") + func testNullJSON() { + XCTAssertEqual(JSON(NSNull()).debugDescription,"null") + + let json:JSON = nil + XCTAssertEqual(json.debugDescription,"null") + XCTAssertNil(json.error) + let json1:JSON = JSON(NSNull()) + if json1 != nil { + XCTFail("json1 should be nil") + } } func testErrorHandle() { @@ -232,7 +242,7 @@ class SwiftyJSONTests: XCTestCase { XCTAssertEqual(json[0]["not-exist"].error!.code, SwiftyJSON.ErrorNotExist) } - let wrongJSON = JSON(object: NSObject()) + let wrongJSON = JSON(NSObject()) if let error = wrongJSON.error { XCTAssertEqual(error.code, SwiftyJSON.ErrorUnsupportedType) } @@ -240,7 +250,6 @@ class SwiftyJSONTests: XCTestCase { func testReturnObject() { let json = JSON(data:self.testData) - println(json.object) XCTAssertNotNil(json.object) } @@ -249,7 +258,7 @@ class SwiftyJSONTests: XCTestCase { let urlString = "http://examble.com/unencoded" + emDash + "string" let encodedURLString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) - let json = JSON(object: urlString) + let json = JSON(urlString) XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!), "Wrong unpacked ") } @@ -286,7 +295,7 @@ class SwiftyJSONTests: XCTestCase { if t == 100 { break } - json.object + let object:AnyObject? = json.object t++ } } From eb7cc54fec4597da11ffd52d3e8c23944ab47636 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 6 Oct 2014 23:25:37 +0800 Subject: [PATCH 011/470] Update example --- Example/AppDelegate.swift | 2 +- Example/ViewController.swift | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 4c7a7884..391ab66b 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let json = JSON(data:data) viewController.json = json } else { - viewController.json = JSON.Null(nil) + viewController.json = JSON.nullJSON } return true diff --git a/Example/ViewController.swift b/Example/ViewController.swift index fecb75e5..bd59a56e 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -25,7 +25,7 @@ import SwiftyJSON class ViewController: UITableViewController { - var json: JSON = JSON.Null(nil) + var json: JSON = JSON.nullJSON // MARK: - Table view data source @@ -34,11 +34,9 @@ class ViewController: UITableViewController { } override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - switch self.json { - case .Sequence(let array): - return array.count - case .Mapping(let dictionary): - return dictionary.count + switch self.json.type { + case Type.Array, Type.Dictionary: + return self.json.count default: return 1 } @@ -49,12 +47,12 @@ class ViewController: UITableViewController { var row = indexPath.row - switch self.json { - case .Sequence(let array): + switch self.json.type { + case .Array: cell.textLabel?.text = "\(row)" cell.detailTextLabel?.text = self.json.arrayValue.description - case .Mapping(let dictionary): - let key: AnyObject = (dictionary as NSDictionary).allKeys[row] + case .Dictionary: + let key: AnyObject = (self.json.object as NSDictionary).allKeys[row] let value = self.json[key as String] cell.textLabel?.text = "\(key)" cell.detailTextLabel?.text = value.description @@ -73,12 +71,12 @@ class ViewController: UITableViewController { if let indexPath = self.tableView.indexPathForSelectedRow() { var row = indexPath.row - var nextJson: JSON = JSON.Null(nil) + var nextJson: JSON = JSON.nullJSON - switch self.json { - case .Sequence: + switch self.json.type { + case .Array: nextJson = self.json[row] - case .Mapping where row < self.json.dictionaryValue.count: + case .Dictionary where row < self.json.dictionaryValue.count: let key = self.json.dictionaryValue.keys.array[row] if let value = self.json.dictionary?[key] { nextJson = value From dd2dd463befcd3bf903d8e89a7ef349d4f3ec7f9 Mon Sep 17 00:00:00 2001 From: tangplin Date: Tue, 7 Oct 2014 00:52:49 +0800 Subject: [PATCH 012/470] Add subscript tests --- Source/SwiftyJSON.swift | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 4 + Tests/LiteralConvertibleTests.swift | 2 +- Tests/RawRepresentableTests.swift | 20 ++- Tests/SubscriptTests.swift | 182 +++++++++++++++++++++++++++ 5 files changed, 205 insertions(+), 5 deletions(-) create mode 100644 Tests/SubscriptTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 43e431f4..108a79ae 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1,4 +1,4 @@ -// JSON.swift +// SwiftyJSON.swift // // Copyright (c) 2014 Ruoyu Fu, Pinglin Tang // diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 205c4ca4..205182da 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; + A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; @@ -33,6 +34,7 @@ 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; + A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; @@ -99,6 +101,7 @@ children = ( A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */, A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */, + A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */, A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */, A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, @@ -231,6 +234,7 @@ buildActionMask = 2147483647; files = ( A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, + A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */, ); diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift index eadfe948..2db8f561 100644 --- a/Tests/LiteralConvertibleTests.swift +++ b/Tests/LiteralConvertibleTests.swift @@ -1,4 +1,4 @@ -// SwiftyJSONTests.swift +// LiteralConvertibleTests.swift // // Copyright (c) 2014 Pinglin Tang // diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index dc5ab5ec..926612b2 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -1,10 +1,24 @@ +// RawRepresentableTests.swift // -// RawRepresentable.swift -// SwiftyJSON +// Copyright (c) 2014 Pinglin Tang // -// Created by Pinglin Tang on 14-10-6. +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. import UIKit import XCTest diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift new file mode 100644 index 00000000..85cdf530 --- /dev/null +++ b/Tests/SubscriptTests.swift @@ -0,0 +1,182 @@ +// SubscriptTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class SubscriptTests: XCTestCase { + + func testArrayAllNumber() { + var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] + XCTAssertEqual(json, [1,2.0,3.3,123456789,987654321.123456789]) + XCTAssertEqual(json[0], 1) + XCTAssertEqual(json[1].double!, 2.0) + XCTAssertEqual(json[2].floatValue, 3.3) + XCTAssertEqual(json[3].int!, 123456789) + XCTAssertEqual(json[4].doubleValue, 987654321.123456789) + + json[0] = 1.9 + json[1] = 2.899 + json[2] = 3.567 + json[3] = 0.999 + json[4] = 98732 + + XCTAssertEqual(json[0], 1.9) + XCTAssertEqual(json[1].doubleValue, 2.899) + XCTAssertEqual(json[2], 3.567) + XCTAssertEqual(json[3].float!, 0.999) + XCTAssertEqual(json[4].intValue, 98732) + } + + func testArrayAllBool() { + var json:JSON = [true, false, false, true, true] + XCTAssertEqual(json, [true, false, false, true, true]) + XCTAssertEqual(json[0], true) + XCTAssertEqual(json[1], false) + XCTAssertEqual(json[2], false) + XCTAssertEqual(json[3], true) + XCTAssertEqual(json[4], true) + + json[0] = false + json[4] = true + XCTAssertEqual(json[0], false) + XCTAssertEqual(json[4], true) + } + + func testArrayAllString() { + var json:JSON = JSON.fromRaw(["aoo","bpp","zoo"] as NSArray)! + XCTAssertEqual(json, ["aoo","bpp","zoo"]) + XCTAssertEqual(json[0], "aoo") + XCTAssertEqual(json[1], "bpp") + XCTAssertEqual(json[2], "zoo") + + json[1] = "update" + XCTAssertEqual(json[0], "aoo") + XCTAssertEqual(json[1], "update") + XCTAssertEqual(json[2], "zoo") + } + + func testArrayWithNull() { + var json:JSON = JSON.fromRaw(["aoo","bpp", NSNull() ,"zoo"] as NSArray)! + XCTAssertEqual(json[0], "aoo") + XCTAssertEqual(json[1], "bpp") + XCTAssertNil(json[2].string) + XCTAssertNotNil(json[2].null) + XCTAssertEqual(json[3], "zoo") + + json[2] = "update" + json[3] = JSON(NSNull()) + XCTAssertEqual(json[0], "aoo") + XCTAssertEqual(json[1], "bpp") + XCTAssertEqual(json[2], "update") + XCTAssertNil(json[3].string) + XCTAssertNotNil(json[3].null) + } + + func testArrayAllDictionary() { + var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] + XCTAssertEqual(json[0], ["1":1, "2":2]) + XCTAssertEqual(json[1].dictionary!, ["a":"A", "b":"B"]) + XCTAssertEqual(json[2], JSON(["null":NSNull()])) + XCTAssertEqual(json[0]["1"], 1) + XCTAssertEqual(json[0]["2"], 2) + XCTAssertEqual(json[1]["a"], JSON.fromRaw("A")!) + XCTAssertEqual(json[1]["b"], JSON("B")) + XCTAssertNotNil(json[2]["null"].null) + } + + func testDictionaryAllNumber() { + var json:JSON = ["double":1.11111, "int":987654321] + XCTAssertEqual(json["double"].double!, 1.11111) + XCTAssertEqual(json["int"], 987654321) + + json["double"] = 2.2222 + json["int"] = 123456789 + json["add"] = 7890 + XCTAssertEqual(json["double"], 2.2222) + XCTAssertEqual(json["int"].doubleValue, 123456789.0) + XCTAssertEqual(json["add"].intValue, 7890) + } + + func testDictionaryAllBool() { + var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] + XCTAssertEqual(json["t"], true) + XCTAssertEqual(json["f"], false) + XCTAssertEqual(json["false"], false) + XCTAssertEqual(json["tr"], true) + XCTAssertEqual(json["true"], true) + + json["f"] = true + json["tr"] = false + XCTAssertEqual(json["f"], true) + XCTAssertEqual(json["tr"], JSON(false)) + } + + func testDictionaryAllString() { + var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! + XCTAssertEqual(json["a"], "aoo") + XCTAssertEqual(json["bb"], JSON("bpp")) + XCTAssertEqual(json["z"], "zoo") + + json["bb"] = "update" + XCTAssertEqual(json["a"], "aoo") + XCTAssertEqual(json["bb"], "update") + XCTAssertEqual(json["z"], "zoo") + } + + func testDictionaryWithNull() { + var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! + XCTAssertEqual(json["a"], "aoo") + XCTAssertEqual(json["bb"], JSON("bpp")) + XCTAssertEqual(json["null"], JSON(NSNull())) + XCTAssertEqual(json["z"], "zoo") + + json["null"] = "update" + XCTAssertEqual(json["a"], "aoo") + XCTAssertEqual(json["null"], "update") + XCTAssertEqual(json["z"], "zoo") + } + + func testDictionaryAllArray() { + //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) + var json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let array = NSArray(objects: NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)) + XCTAssertEqual(json[0], [1,2.123456,123456789]) + XCTAssertEqual(json[0][1].double!, 2.123456) + XCTAssertEqual(json[0][2], 123456789) + XCTAssertEqual(json[1][0], "aa") + XCTAssertEqual(json[1], ["aa","bbb","cccc"]) + XCTAssertEqual(json[2][0], true) + XCTAssertEqual(json[2][1], "766") + XCTAssertEqual(json[2][2], JSON(NSNull())) + XCTAssertEqual(json[2][3], JSON(655231.9823)) + } + + func testOutOfBounds() { + var json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + XCTAssertEqual(json[9], JSON.nullJSON) + XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) + XCTAssertEqual(json[9][8], JSON.nullJSON) + XCTAssertEqual(json[8][7].error!.code, ErrorWrongType) + } +} From 6a4dbdf8cd8a02560bfa192fa0d9f4ccbd1c8765 Mon Sep 17 00:00:00 2001 From: tangplin Date: Tue, 7 Oct 2014 10:10:04 +0800 Subject: [PATCH 013/470] Add printable tests --- Source/SwiftyJSON.swift | 82 ++++++++++++++++++++++------ SwiftyJSON.xcodeproj/project.pbxproj | 4 ++ Tests/PrintableTests.swift | 69 +++++++++++++++++++++++ 3 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 Tests/PrintableTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 108a79ae..a035b082 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -126,6 +126,21 @@ public struct JSON { // MARK: - SequenceType extension JSON: SequenceType{ + /// `true` if and only if self's type is `.Array` or `.Dictionary` and it is empty + var isEmpty: Bool { + get { + switch self.type { + case .Array: + return (self.object as Array).isEmpty + case .Dictionary: + return (self.object as Dictionary).isEmpty + default: + return false + } + } + } + + /// `count` value if self's type is `.Array` or `.Dictionary` otherwise is `0` public var count: Int { get { switch self.type { @@ -136,10 +151,9 @@ extension JSON: SequenceType{ } } } - /** - When .Sequence return GeneratorOf<(index, JSON(element))> - When .Mapping return GeneratorOf<(key, JSON(value))> - */ + + /// - If self's type is .Array return GeneratorOf<(index, JSON(element))> otherwise return `nil` + /// - If self's type is .Dictionary return GeneratorOf<(index, JSON(element))> otherwise return `nil` public func generate() -> GeneratorOf <(String, JSON)> { switch self.type { case .Array: @@ -350,7 +364,7 @@ extension JSON: Printable, DebugPrintable { } } -// MARK: - Sequence: Array +// MARK: - Array extension JSON { //Optional Array @@ -385,10 +399,13 @@ extension JSON { return nil } } + set { + self.object = newValue ?? NSNull() + } } } -// MARK: - Mapping: Dictionary +// MARK: - Dictionary extension JSON { //Optional Dictionary @@ -424,10 +441,13 @@ extension JSON { return nil } } + set { + self.object = newValue ?? NSNull() + } } } -//MARK: - Scalar: Bool +//MARK: - Bool extension JSON: BooleanType { //Optional bool @@ -440,24 +460,29 @@ extension JSON: BooleanType { return nil } } + set { + self.object = newValue ?? NSNull() + } } //Non-optional bool public var boolValue: Bool { - switch self.type { - case .Bool, .Number, .String: - return self.object.boolValue - case .Array, .Dictionary: - return self.object.count > 0 - case .Null: - return false - default: - return false + get { + switch self.type { + case .Bool, .Number, .String: + return self.object.boolValue + case .Array, .Dictionary: + return self.object.count > 0 + case .Null: + return false + default: + return false + } } } } -//MARK: - Scalar: String +//MARK: - String extension JSON { //Optional string @@ -470,6 +495,9 @@ extension JSON { return nil } } + set { + self.object = newValue ?? NSNull() + } } //Non-optional string @@ -489,7 +517,7 @@ extension JSON { } } -//MARK: - Scalar: Number +//MARK: - Number extension JSON { //Optional number @@ -502,6 +530,9 @@ extension JSON { return nil } } + set { + self.object = newValue ?? NSNull() + } } //Non-optional number @@ -537,6 +568,9 @@ extension JSON { return nil } } + set { + self.object = NSNull() + } } } @@ -570,6 +604,9 @@ extension JSON { } return nil } + set { + self.object = newValue ?? NSNull() + } } public var doubleValue: Double { @@ -585,6 +622,9 @@ extension JSON { } return nil } + set { + self.object = newValue ?? NSNull() + } } public var floatValue: Float { @@ -600,6 +640,9 @@ extension JSON { } return nil } + set { + self.object = newValue ?? NSNull() + } } public var intValue: Int { @@ -615,6 +658,9 @@ extension JSON { } return nil } + set { + self.object = newValue ?? NSNull() + } } public var uIntValue: UInt { diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 205182da..77094cac 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; + A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; @@ -35,6 +36,7 @@ A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; + A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; @@ -101,6 +103,7 @@ children = ( A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */, A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */, + A819C4A019E37FC600ADCC3D /* PrintableTests.swift */, A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */, A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */, A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */, @@ -236,6 +239,7 @@ A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, + A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */, A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift new file mode 100644 index 00000000..f2ddcb9a --- /dev/null +++ b/Tests/PrintableTests.swift @@ -0,0 +1,69 @@ +// PrintableTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class PrintableTests: XCTestCase { + func testNumber() { + var json:JSON = 1234567890.876623 + XCTAssertEqual(json.description, "1234567890.876623") + XCTAssertEqual(json.debugDescription, "1234567890.876623") + } + + func testBool() { + var jsonTrue:JSON = true + XCTAssertEqual(jsonTrue.description, "true") + XCTAssertEqual(jsonTrue.debugDescription, "true") + var jsonFalse:JSON = false + XCTAssertEqual(jsonFalse.description, "false") + XCTAssertEqual(jsonFalse.debugDescription, "false") + } + + func testString() { + var json:JSON = "abcd efg, HIJK;LMn" + XCTAssertEqual(json.description, "abcd efg, HIJK;LMn") + XCTAssertEqual(json.debugDescription, "abcd efg, HIJK;LMn") + } + + func testNil() { + var jsonNil_1:JSON = nil + XCTAssertEqual(jsonNil_1.description, "null") + XCTAssertEqual(jsonNil_1.debugDescription, "null") + var jsonNil_2:JSON = JSON(NSNull()) + XCTAssertEqual(jsonNil_2.description, "null") + XCTAssertEqual(jsonNil_2.debugDescription, "null") + } + + func testArray() { + var json:JSON = [1,2,"4",5,"6"] + XCTAssertEqual(json.description, "[1, 2, 4, 5, 6]") + XCTAssertEqual(json.debugDescription, "[1, 2, 4, 5, 6]") + } + + func testDictionary() { + var json:JSON = ["1":2,"2":2, "3":3] + XCTAssertEqual(json.description, "[2: 2, 3: 3, 1: 2]") + XCTAssertEqual(json.debugDescription, "[\"2\": 2, \"3\": 3, \"1\": 2]") + } +} From 397f6ddcc3d1c3a4037a6904f32e789f50e11ab8 Mon Sep 17 00:00:00 2001 From: tangplin Date: Tue, 7 Oct 2014 16:31:51 +0800 Subject: [PATCH 014/470] Add sequence type tests --- Source/SwiftyJSON.swift | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 4 + Tests/SequenceTypeTests.swift | 206 +++++++++++++++++++++++++++ Tests/SubscriptTests.swift | 1 - 4 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 Tests/SequenceTypeTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a035b082..d6b814a1 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -159,7 +159,7 @@ extension JSON: SequenceType{ case .Array: let array_ = object as Array var generate_ = array_.generate() - var index_: Int = -1 + var index_: Int = 0 return GeneratorOf<(String, JSON)> { if let element_: AnyObject = generate_.next() { return ("\(index_++)", JSON(element_)) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 77094cac..e505bc4b 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; /* End PBXBuildFile section */ @@ -39,6 +40,7 @@ A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; + A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; /* End PBXFileReference section */ @@ -103,6 +105,7 @@ children = ( A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */, A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */, + A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */, A819C4A019E37FC600ADCC3D /* PrintableTests.swift */, A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */, A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */, @@ -236,6 +239,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */, A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift new file mode 100644 index 00000000..17c48cd8 --- /dev/null +++ b/Tests/SequenceTypeTests.swift @@ -0,0 +1,206 @@ +// +// SequenceTypeTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class SequenceTypeTests: XCTestCase { + + func testArrayAllNumber() { + var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] + XCTAssertEqual(json.count, 5) + + var index = 0 + var array = [NSNumber]() + for (i, sub) in json { + XCTAssertEqual(sub, json[index]) + XCTAssertEqual(i, "\(index)") + array.append(sub.number!) + index++ + } + XCTAssertEqual(index, 5) + XCTAssertEqual(array, [1,2.0,3.3,123456789,987654321.123456789]) + } + + func testArrayAllBool() { + var json:JSON = JSON([true, false, false, true, true]) + XCTAssertEqual(json.count, 5) + + var index = 0 + var array = [Bool]() + for (i, sub) in json { + XCTAssertEqual(sub, json[index]) + XCTAssertEqual(i, "\(index)") + array.append(sub.bool!) + index++ + } + XCTAssertEqual(index, 5) + XCTAssertEqual(array, [true, false, false, true, true]) + } + + func testArrayAllString() { + var json:JSON = JSON.fromRaw(["aoo","bpp","zoo"] as NSArray)! + XCTAssertEqual(json.count, 3) + + var index = 0 + var array = [String]() + for (i, sub) in json { + XCTAssertEqual(sub, json[index]) + XCTAssertEqual(i, "\(index)") + array.append(sub.string!) + index++ + } + XCTAssertEqual(index, 3) + XCTAssertEqual(array, ["aoo","bpp","zoo"]) + } + + func testArrayWithNull() { + var json:JSON = JSON.fromRaw(["aoo","bpp", NSNull() ,"zoo"] as NSArray)! + XCTAssertEqual(json.count, 4) + + var index = 0 + var array = [AnyObject]() + for (i, sub) in json { + XCTAssertEqual(sub, json[index]) + XCTAssertEqual(i, "\(index)") + array.append(sub.object) + index++ + } + XCTAssertEqual(index, 4) + XCTAssertEqual(array[0] as String, "aoo") + XCTAssertEqual(array[2] as NSNull, NSNull()) + } + + func testArrayAllDictionary() { + var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] + XCTAssertEqual(json.count, 3) + + var index = 0 + var array = [AnyObject]() + for (i, sub) in json { + XCTAssertEqual(sub, json[index]) + XCTAssertEqual(i, "\(index)") + array.append(sub.object) + index++ + } + XCTAssertEqual(index, 3) + XCTAssertEqual((array[0] as Dictionary)["1"]!, 1) + XCTAssertEqual((array[0] as Dictionary)["2"]!, 2) + XCTAssertEqual((array[1] as Dictionary)["a"]!, "A") + XCTAssertEqual((array[1] as Dictionary)["b"]!, "B") + XCTAssertEqual((array[2] as Dictionary)["null"]!, NSNull()) + } + + func testDictionaryAllNumber() { + var json:JSON = ["double":1.11111, "int":987654321] + XCTAssertEqual(json.count, 2) + + var index = 0 + var dictionary = [String:NSNumber]() + for (key, sub) in json { + XCTAssertEqual(sub, json[key]) + dictionary[key] = sub.number! + index++ + } + + XCTAssertEqual(index, 2) + XCTAssertEqual(dictionary["double"]! as NSNumber, 1.11111) + XCTAssertEqual(dictionary["int"]! as NSNumber, 987654321) + } + + func testDictionaryAllBool() { + var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] + XCTAssertEqual(json.count, 5) + + var index = 0 + var dictionary = [String:Bool]() + for (key, sub) in json { + XCTAssertEqual(sub, json[key]) + dictionary[key] = sub.bool! + index++ + } + + XCTAssertEqual(index, 5) + XCTAssertEqual(dictionary["t"]! as Bool, true) + XCTAssertEqual(dictionary["false"]! as Bool, false) + } + + func testDictionaryAllString() { + var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! + XCTAssertEqual(json.count, 3) + + var index = 0 + var dictionary = [String:String]() + for (key, sub) in json { + XCTAssertEqual(sub, json[key]) + dictionary[key] = sub.string! + index++ + } + + XCTAssertEqual(index, 3) + XCTAssertEqual(dictionary["a"]! as String, "aoo") + XCTAssertEqual(dictionary["bb"]! as String, "bpp") + } + + func testDictionaryWithNull() { + var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! + XCTAssertEqual(json.count, 4) + + var index = 0 + var dictionary = [String:AnyObject]() + for (key, sub) in json { + XCTAssertEqual(sub, json[key]) + dictionary[key] = sub.object + index++ + } + + XCTAssertEqual(index, 4) + XCTAssertEqual(dictionary["a"]! as String, "aoo") + XCTAssertEqual(dictionary["bb"]! as String, "bpp") + XCTAssertEqual(dictionary["null"]! as NSNull, NSNull()) + } + + func testDictionaryAllArray() { + var json:JSON = JSON (["Number":[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], "String":["aa","bbb","cccc"], "Mix":[true, "766", NSNull(), 655231.9823]]) + + XCTAssertEqual(json.count, 3) + + var index = 0 + var dictionary = [String:AnyObject]() + for (key, sub) in json { + XCTAssertEqual(sub, json[key]) + dictionary[key] = sub.object + index++ + } + + XCTAssertEqual(index, 3) + XCTAssertEqual((dictionary["Number"] as NSArray)[0] as Int, 1) + XCTAssertEqual((dictionary["Number"] as NSArray)[1] as Double, 2.123456) + XCTAssertEqual((dictionary["String"] as NSArray)[0] as String, "aa") + XCTAssertEqual((dictionary["Mix"] as NSArray)[0] as Bool, true) + XCTAssertEqual((dictionary["Mix"] as NSArray)[1] as String, "766") + XCTAssertEqual((dictionary["Mix"] as NSArray)[2] as NSNull, NSNull()) + XCTAssertEqual((dictionary["Mix"] as NSArray)[3] as Double, 655231.9823) + } +} diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 85cdf530..3be94a5a 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -160,7 +160,6 @@ class SubscriptTests: XCTestCase { func testDictionaryAllArray() { //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) var json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) - let array = NSArray(objects: NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)) XCTAssertEqual(json[0], [1,2.123456,123456789]) XCTAssertEqual(json[0][1].double!, 2.123456) XCTAssertEqual(json[0][2], 123456789) From 0507ea70f0377a1731f3833c9762f11c3f419f6a Mon Sep 17 00:00:00 2001 From: tangplin Date: Tue, 7 Oct 2014 17:51:30 +0800 Subject: [PATCH 015/470] Add comparable tests --- SwiftyJSON.xcodeproj/project.pbxproj | 4 + Tests/ComparableTests.swift | 340 +++++++++++++++++++++++++++ 2 files changed, 344 insertions(+) create mode 100644 Tests/ComparableTests.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index e505bc4b..c80223e8 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; + A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; /* End PBXBuildFile section */ @@ -41,6 +42,7 @@ A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; + A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; /* End PBXFileReference section */ @@ -110,6 +112,7 @@ A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */, A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */, A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */, + A87080E519E3DF7800CDE086 /* ComparableTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); path = Tests; @@ -245,6 +248,7 @@ A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */, A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */, + A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Tests/ComparableTests.swift b/Tests/ComparableTests.swift new file mode 100644 index 00000000..e57f3b33 --- /dev/null +++ b/Tests/ComparableTests.swift @@ -0,0 +1,340 @@ +// +// ComparableTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class ComparableTests: XCTestCase { + + func testNumberEqual() { + var jsonL1:JSON = 1234567890.876623 + var jsonR1:JSON = JSON(1234567890.876623) + XCTAssertEqual(jsonL1, jsonR1) + XCTAssertEqual(jsonL1, 1234567890.876623) + + var jsonL2:JSON = 987654321 + var jsonR2:JSON = JSON(987654321) + XCTAssertEqual(jsonL2, jsonR2) + XCTAssertEqual(jsonR2, 987654321) + + + var jsonL3:JSON = JSON(NSNumber(double:87654321.12345678)) + var jsonR3:JSON = JSON(NSNumber(double:87654321.12345678)) + XCTAssertEqual(jsonL3, jsonR3) + XCTAssertEqual(jsonR3, 87654321.12345678) + } + + func testNumberNotEqual() { + var jsonL1:JSON = 1234567890.876623 + var jsonR1:JSON = JSON(123.123) + XCTAssertNotEqual(jsonL1, jsonR1) + XCTAssertNotEqual(jsonL1, 34343) + + var jsonL2:JSON = 8773 + var jsonR2:JSON = JSON(123.23) + XCTAssertNotEqual(jsonL2, jsonR2) + XCTAssertNotEqual(jsonR1, 454352) + + var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + var jsonR3:JSON = JSON(NSNumber(double:87654321.45678)) + XCTAssertNotEqual(jsonL3, jsonR3) + XCTAssertNotEqual(jsonL3, 4545.232) + } + + func testNumberGreaterThanOrEqual() { + var jsonL1:JSON = 1234567890.876623 + var jsonR1:JSON = JSON(123.123) + XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) + XCTAssertTrue(jsonL1 >= -37434) + + var jsonL2:JSON = 8773 + var jsonR2:JSON = JSON(-87343) + XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) + XCTAssertTrue(jsonR2 >= -988343) + + var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + var jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) + XCTAssertGreaterThanOrEqual(jsonL3, jsonR3) + XCTAssertTrue(jsonR3 >= 0.3232) + } + + func testNumberLessThanOrEqual() { + var jsonL1:JSON = 1234567890.876623 + var jsonR1:JSON = JSON(123.123) + XCTAssertLessThanOrEqual(jsonR1, jsonL1) + XCTAssertFalse(83487343.3493 <= jsonR1) + + var jsonL2:JSON = 8773 + var jsonR2:JSON = JSON(-123.23) + XCTAssertLessThanOrEqual(jsonR2, jsonL2) + XCTAssertFalse(9348343 <= jsonR2) + + var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + var jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) + XCTAssertLessThanOrEqual(jsonR3, jsonL3) + XCTAssertTrue(87621.12345678 <= jsonR3) + } + + func testNumberGreaterThan() { + var jsonL1:JSON = 1234567890.876623 + var jsonR1:JSON = JSON(123.123) + XCTAssertGreaterThan(jsonL1, jsonR1) + XCTAssertFalse(jsonR1 > 192388843.0988) + + var jsonL2:JSON = 8773 + var jsonR2:JSON = JSON(123.23) + XCTAssertGreaterThan(jsonL2, jsonR2) + XCTAssertFalse(jsonR2 > 877434) + + var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + var jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) + XCTAssertGreaterThan(jsonL3, jsonR3) + XCTAssertFalse(-7799 > jsonR3) + } + + func testNumberLessThan() { + var jsonL1:JSON = 1234567890.876623 + var jsonR1:JSON = JSON(123.123) + XCTAssertLessThan(jsonR1, jsonL1) + XCTAssertTrue(jsonR1 < 192388843.0988) + + var jsonL2:JSON = 8773 + var jsonR2:JSON = JSON(123.23) + XCTAssertLessThan(jsonR2, jsonL2) + XCTAssertTrue(jsonR2 < 877434) + + var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + var jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) + XCTAssertLessThan(jsonR3, jsonL3) + XCTAssertTrue(-7799 < jsonR3) + } + + func testBoolEqual() { + var jsonL1:JSON = true + var jsonR1:JSON = JSON(true) + XCTAssertEqual(jsonL1, jsonR1) + XCTAssertEqual(jsonL1, true) + + var jsonL2:JSON = false + var jsonR2:JSON = JSON(false) + XCTAssertEqual(jsonL2, jsonR2) + XCTAssertTrue(jsonL2 == false) + } + + func testBoolNotEqual() { + var jsonL1:JSON = true + var jsonR1:JSON = JSON(false) + XCTAssertNotEqual(jsonL1, jsonR1) + XCTAssertNotEqual(jsonL1, false) + + var jsonL2:JSON = false + var jsonR2:JSON = JSON(true) + XCTAssertNotEqual(jsonL2, jsonR2) + XCTAssertTrue(jsonL2 != true) + } + + func testBoolGreaterThanOrEqual() { + var jsonL1:JSON = true + var jsonR1:JSON = JSON(true) + XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) + XCTAssertGreaterThanOrEqual(jsonL1,true) + + var jsonL2:JSON = false + var jsonR2:JSON = JSON(false) + XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) + XCTAssertFalse(jsonL2 >= true) + } + + func testBoolLessThanOrEqual() { + var jsonL1:JSON = true + var jsonR1:JSON = JSON(true) + XCTAssertLessThanOrEqual(jsonL1, jsonR1) + XCTAssertLessThanOrEqual(true, jsonR1) + + var jsonL2:JSON = false + var jsonR2:JSON = JSON(false) + XCTAssertLessThanOrEqual(jsonL2, jsonR2) + XCTAssertFalse(jsonL2 <= true) + } + + func testBoolGreaterThan() { + var jsonL1:JSON = true + var jsonR1:JSON = JSON(true) + XCTAssertFalse(jsonL1 > jsonR1) + XCTAssertFalse(jsonL1 > true) + XCTAssertFalse(jsonR1 > false) + + var jsonL2:JSON = false + var jsonR2:JSON = JSON(false) + XCTAssertFalse(jsonL2 > jsonR2) + XCTAssertFalse(jsonL2 > false) + XCTAssertFalse(jsonR2 > true) + + var jsonL3:JSON = true + var jsonR3:JSON = JSON(false) + XCTAssertFalse(jsonL3 > jsonR3) + XCTAssertFalse(jsonL3 > false) + XCTAssertFalse(jsonR3 > true) + + var jsonL4:JSON = false + var jsonR4:JSON = JSON(true) + XCTAssertFalse(jsonL4 > jsonR4) + XCTAssertFalse(jsonL4 > false) + XCTAssertFalse(jsonR4 > true) + } + + func testBoolLessThan() { + var jsonL1:JSON = true + var jsonR1:JSON = JSON(true) + XCTAssertFalse(jsonL1 < jsonR1) + XCTAssertFalse(jsonL1 < true) + XCTAssertFalse(jsonR1 < false) + + var jsonL2:JSON = false + var jsonR2:JSON = JSON(false) + XCTAssertFalse(jsonL2 < jsonR2) + XCTAssertFalse(jsonL2 < false) + XCTAssertFalse(jsonR2 < true) + + var jsonL3:JSON = true + var jsonR3:JSON = JSON(false) + XCTAssertFalse(jsonL3 < jsonR3) + XCTAssertFalse(jsonL3 < false) + XCTAssertFalse(jsonR3 < true) + + var jsonL4:JSON = false + var jsonR4:JSON = JSON(true) + XCTAssertFalse(jsonL4 < jsonR4) + XCTAssertFalse(jsonL4 < false) + XCTAssertFalse(true < jsonR4) + } + + func testStringEqual() { + var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + + XCTAssertEqual(jsonL1, jsonR1) + XCTAssertEqual(jsonL1, "abcdefg 123456789 !@#$%^&*()") + } + + func testStringNotEqual() { + var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + var jsonR1:JSON = JSON("-=[]\\\"987654321") + + XCTAssertNotEqual(jsonL1, jsonR1) + XCTAssertNotEqual(jsonL1, "not equal") + } + + func testStringGreaterThanOrEqual() { + var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + + XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) + XCTAssertGreaterThanOrEqual(jsonL1, "abcdefg 123456789 !@#$%^&*()") + + var jsonL2:JSON = "z-+{}:" + var jsonR2:JSON = JSON("a<>?:") + XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) + XCTAssertGreaterThanOrEqual(jsonL2, "mnbvcxz") + } + + func testStringLessThanOrEqual() { + var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + + XCTAssertLessThanOrEqual(jsonL1, jsonR1) + XCTAssertLessThanOrEqual(jsonL1, "abcdefg 123456789 !@#$%^&*()") + + var jsonL2:JSON = "z-+{}:" + var jsonR2:JSON = JSON("a<>?:") + XCTAssertLessThanOrEqual(jsonR2, jsonL2) + XCTAssertLessThanOrEqual("mnbvcxz", jsonL2) + } + + func testStringGreaterThan() { + var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + + XCTAssertFalse(jsonL1 > jsonR1) + XCTAssertFalse(jsonL1 > "abcdefg 123456789 !@#$%^&*()") + + var jsonL2:JSON = "z-+{}:" + var jsonR2:JSON = JSON("a<>?:") + XCTAssertGreaterThan(jsonL2, jsonR2) + XCTAssertFalse("87663434" > jsonL2) + } + + func testStringLessThan() { + var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + + XCTAssertFalse(jsonL1 < jsonR1) + XCTAssertFalse(jsonL1 < "abcdefg 123456789 !@#$%^&*()") + + var jsonL2:JSON = "98774" + var jsonR2:JSON = JSON("123456") + XCTAssertLessThan(jsonR2, jsonL2) + XCTAssertFalse(jsonL2 < "09") + } + + func testNil() { + var jsonL1:JSON = nil + var jsonR1:JSON = JSON(NSNull()) + XCTAssertEqual(jsonL1, jsonR1) + XCTAssertNotEqual(jsonL1, "123") + XCTAssertFalse(jsonL1 > "abcd") + XCTAssertFalse(jsonR1 < "*&^") + XCTAssertFalse(jsonL1 >= "jhfid") + XCTAssertFalse(jsonR1 <= "你好") + XCTAssertTrue(jsonL1 >= jsonR1) + XCTAssertTrue(jsonL1 <= jsonR1) + } + + func testArray() { + var jsonL1:JSON = [1,2,"4",5,"6"] + var jsonR1:JSON = JSON([1,2,"4",5,"6"]) + XCTAssertEqual(jsonL1, jsonR1) + XCTAssertEqual(jsonL1, [1,2,"4",5,"6"]) + XCTAssertNotEqual(jsonL1, ["abcd","efg"]) + XCTAssertTrue(jsonL1 >= jsonR1) + XCTAssertTrue(jsonL1 <= jsonR1) + XCTAssertFalse(jsonL1 > ["abcd",""]) + XCTAssertFalse(jsonR1 < []) + XCTAssertFalse(jsonL1 >= [:]) + } + + func testDictionary() { + var jsonL1:JSON = ["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]] + var jsonR1:JSON = JSON(["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]]) + + XCTAssertEqual(jsonL1, jsonR1) + XCTAssertTrue(jsonL1 != ["1":2,"Hello":"World","Koo":"Foo"]) + XCTAssertTrue(jsonL1 >= jsonR1) + XCTAssertTrue(jsonL1 <= jsonR1) + XCTAssertFalse(jsonL1 >= [:]) + XCTAssertFalse(jsonR1 <= ["999":"aaaa"]) + XCTAssertFalse(jsonL1 > [")(*&^":1234567]) + XCTAssertFalse(jsonR1 < ["MNHH":"JUYTR"]) + } +} From d3ecc49e4a21577095420e2c3a5a8be5fa05c302 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 15:04:28 +0800 Subject: [PATCH 016/470] Add number setter --- Source/SwiftyJSON.swift | 226 +++++++++++++++++++++++++++++----------- 1 file changed, 163 insertions(+), 63 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index d6b814a1..916dac70 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -65,10 +65,9 @@ public struct JSON { _object = newValue switch newValue { case let number as NSNumber: - switch String.fromCString(number.objCType)! { - case "c", "C": + if number.isBool { _type = .Bool - default: + } else { _type = .Number } case let string as NSString: @@ -81,6 +80,7 @@ public struct JSON { _type = .Dictionary default: _type = .Unknow + _object = NSNull() _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) } } @@ -461,7 +461,11 @@ extension JSON: BooleanType { } } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSNumber(bool: newValue!) + } else { + self.object = NSNull() + } } } @@ -479,6 +483,9 @@ extension JSON: BooleanType { return false } } + set { + self.object = NSNumber(bool: newValue) + } } } @@ -496,7 +503,11 @@ extension JSON { } } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSString(string:newValue!) + } else { + self.object = NSNull() + } } } @@ -514,6 +525,9 @@ extension JSON { return "" } } + set { + self.object = NSString(string:newValue) + } } } @@ -531,7 +545,11 @@ extension JSON { } } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = newValue!.copy() + } else { + self.object = NSNull() + } } } @@ -553,6 +571,9 @@ extension JSON { return NSNumber(double: 0.0) } } + set { + self.object = newValue.copy() + } } } @@ -591,6 +612,9 @@ extension JSON { return nil } } + set { + self.object = newValue?.absoluteString ?? NSNull() + } } } @@ -599,193 +623,265 @@ extension JSON { public var double: Double? { get { - if self.type == .Number { - return self.object.doubleValue - } - return nil + return self.number?.doubleValue } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSNumber(double: newValue!) + } else { + self.object = NSNull() + } } } public var doubleValue: Double { get { - return self.double ?? 0.0 + return self.numberValue.doubleValue + } + set { + self.object = NSNumber(double: newValue) } } public var float: Float? { get { - if self.type == .Number { - return self.object.floatValue - } - return nil + return self.number?.floatValue } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSNumber(float: newValue!) + } else { + self.object = NSNull() + } } } public var floatValue: Float { get { - return self.float ?? 0.0 + return self.numberValue.floatValue + } + set { + self.object = NSNumber(float: newValue) } } public var int: Int? { get { - if self.type == .Number { - return self.object.longValue - } - return nil + return self.number?.longValue } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSNumber(integer: newValue!) + } else { + self.object = NSNull() + } } } public var intValue: Int { get { - return self.int ?? 0 + return self.numberValue.integerValue + } + set { + self.object = NSNumber(integer: newValue) } } public var uInt: UInt? { get { - if self.type == .Number { - return self.object.unsignedLongValue - } - return nil + return self.number?.unsignedLongValue } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSNumber(unsignedLong: newValue!) + } else { + self.object = NSNull() + } } } public var uIntValue: UInt { get { - return self.uInt ?? 0 + return self.numberValue.unsignedLongValue + } + set { + self.object = NSNumber(unsignedLong: newValue) } } public var int8: Int8? { get { - if self.type == .Number { - return self.object.charValue + return self.number?.charValue + } + set { + if newValue != nil { + self.object = NSNumber(char: newValue!) + } else { + self.object = NSNull() } - return nil } } public var int8Value: Int8 { get { - return self.int8 ?? 0 + return self.numberValue.charValue + } + set { + self.object = NSNumber(char: newValue) } } public var uInt8: UInt8? { get { - if self.type == .Number { - return self.object.unsignedCharValue + return self.number?.unsignedCharValue + } + set { + if newValue != nil { + self.object = NSNumber(unsignedChar: newValue!) + } else { + self.object = NSNull() } - return nil } } public var uInt8Value: UInt8 { get { - return self.uInt8 ?? 0 + return self.numberValue.unsignedCharValue + } + set { + self.object = NSNumber(unsignedChar: newValue) } } public var int16: Int16? { get { - if self.type == .Number { - return self.object.shortValue + return self.number?.shortValue + } + set { + if newValue != nil { + self.object = NSNumber(short: newValue!) + } else { + self.object = NSNull() } - return nil } } public var int16Value: Int16 { get { - return self.int16 ?? 0 + return self.numberValue.shortValue + } + set { + self.object = NSNumber(short: newValue) } } public var uInt16: UInt16? { get { - if self.type == .Number { - return self.object.unsignedShortValue + return self.number?.unsignedShortValue + } + set { + if newValue != nil { + self.object = NSNumber(unsignedShort: newValue!) + } else { + self.object = NSNull() } - return nil } } public var uInt16Value: UInt16 { get { - return self.uInt16 ?? 0 + return self.numberValue.unsignedShortValue + } + set { + self.object = NSNumber(unsignedShort: newValue) } } public var int32: Int32? { get { - if self.type == .Number { - return self.object.intValue + return self.number?.intValue + } + set { + if newValue != nil { + self.object = NSNumber(int: newValue!) + } else { + self.object = NSNull() } - return nil } } public var int32Value: Int32 { get { - return self.int32 ?? 0 + return self.numberValue.intValue + } + set { + self.object = NSNumber(int: newValue) } } public var uInt32: UInt32? { get { - if self.type == .Number { - return self.object.unsignedIntValue + return self.number?.unsignedIntValue + } + set { + if newValue != nil { + self.object = NSNumber(unsignedInt: newValue!) + } else { + self.object = NSNull() } - return nil } } public var uInt32Value: UInt32 { get { - return self.uInt32 ?? 0 + return self.numberValue.unsignedIntValue + } + set { + self.object = NSNumber(unsignedInt: newValue) } } public var int64: Int64? { get { - if self.type == .Number { - return self.object.longLongValue + return self.number?.longLongValue + } + set { + if newValue != nil { + self.object = NSNumber(longLong: newValue!) + } else { + self.object = NSNull() } - return nil } } public var int64Value: Int64 { get { - return self.int64 ?? 0 + return self.numberValue.longLongValue + } + set { + self.object = NSNumber(longLong: newValue) } } public var uInt64: UInt64? { get { - if self.type == .Number { - return self.object.unsignedLongLongValue + return self.number?.unsignedLongLongValue + } + set { + if newValue != nil { + self.object = NSNumber(unsignedLongLong: newValue!) + } else { + self.object = NSNull() } - return nil } } public var uInt64Value: UInt64 { get { - return self.uInt64 ?? 0 + return self.numberValue.unsignedLongLongValue + } + set { + self.object = NSNumber(unsignedLongLong: newValue) } } } @@ -883,7 +979,11 @@ extension NSNumber: Comparable { get { switch String.fromCString(self.objCType)! { case "c", "C": - return true + if self.compare(NSNumber(bool: true)) == NSComparisonResult.OrderedSame || self.compare(NSNumber(bool: false)) == NSComparisonResult.OrderedSame { + return true + } else { + return false + } default: return false } From 87d26a56277d74cff941345b4ea51ed879c5c9e6 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 15:04:58 +0800 Subject: [PATCH 017/470] Add number and string tests --- SwiftyJSON.xcodeproj/project.pbxproj | 8 + Tests/NumberTests.swift | 364 +++++++++++++++++++++++++++ Tests/StringTests.swift | 38 +++ Tests/SwiftyJSONTests.swift | 10 - 4 files changed, 410 insertions(+), 10 deletions(-) create mode 100644 Tests/NumberTests.swift create mode 100644 Tests/StringTests.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index c80223e8..52e8aad6 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -16,6 +16,8 @@ A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; + A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; + A87080EA19E43C0700CDE086 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; /* End PBXBuildFile section */ @@ -43,6 +45,8 @@ A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = ""; }; + A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberTests.swift; sourceTree = ""; }; + A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; /* End PBXFileReference section */ @@ -113,6 +117,8 @@ A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */, A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */, A87080E519E3DF7800CDE086 /* ComparableTests.swift */, + A87080E919E43C0700CDE086 /* StringTests.swift */, + A87080E719E439DA00CDE086 /* NumberTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); path = Tests; @@ -242,12 +248,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */, A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */, A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */, A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */, + A87080EA19E43C0700CDE086 /* StringTests.swift in Sources */, A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift new file mode 100644 index 00000000..4ec3cd2a --- /dev/null +++ b/Tests/NumberTests.swift @@ -0,0 +1,364 @@ +// +// NumberTests.swift +// SwiftyJSON +// +// Created by Pinglin Tang on 14-10-7. +// +// + +import UIKit +import XCTest +import SwiftyJSON +class NumberTests: XCTestCase { + + func testNumber() { + //getter + var json = JSON(NSNumber(double: 9876543210.123456789)) + XCTAssertEqual(json.number!, 9876543210.123456789) + XCTAssertEqual(json.numberValue, 9876543210.123456789) + XCTAssertEqual(json.stringValue, "9876543210.123457") + + //setter + json.number = NSNumber(double: 123456789.0987654321) + XCTAssertEqual(json.number!, 123456789.0987654321) + XCTAssertEqual(json.numberValue, 123456789.0987654321) + json.number = nil + XCTAssertEqual(json.numberValue, 0) + json.numberValue = 2.9876 + XCTAssertEqual(json.number!, 2.9876) + } + + func testBool() { + var json = JSON(true) + XCTAssertEqual(json.bool!, true) + XCTAssertEqual(json.boolValue, true) + XCTAssertEqual(json.numberValue, true as NSNumber) + XCTAssertEqual(json.stringValue, "true") + + json.bool = false + XCTAssertEqual(json.bool!, false) + XCTAssertEqual(json.boolValue, false) + XCTAssertEqual(json.numberValue, false as NSNumber) + + json.bool = nil + XCTAssertEqual(json.boolValue, false) + XCTAssertEqual(json.numberValue, 0) + + json.boolValue = true + XCTAssertEqual(json.bool!, true) + XCTAssertEqual(json.boolValue, true) + XCTAssertEqual(json.numberValue, true as NSNumber) + } + + func testDouble() { + var json = JSON(9876543210.123456789) + XCTAssertEqual(json.double!, 9876543210.123456789) + XCTAssertEqual(json.doubleValue, 9876543210.123456789) + XCTAssertEqual(json.numberValue, 9876543210.123456789) + XCTAssertEqual(json.stringValue, "9876543210.123457") + + json.double = 2.8765432 + XCTAssertEqual(json.double!, 2.8765432) + XCTAssertEqual(json.doubleValue, 2.8765432) + XCTAssertEqual(json.numberValue, 2.8765432) + + json.doubleValue = 89.0987654 + XCTAssertEqual(json.double!, 89.0987654) + XCTAssertEqual(json.doubleValue, 89.0987654) + XCTAssertEqual(json.numberValue, 89.0987654) + + json.double = nil + XCTAssertEqual(json.boolValue, false) + XCTAssertEqual(json.doubleValue, 0.0) + XCTAssertEqual(json.numberValue, 0) + } + + func testFloat() { + var json = JSON(54321.12345) + XCTAssertEqual(json.float!, 54321.12345) + XCTAssertEqual(json.floatValue, 54321.12345) + println(json.numberValue.doubleValue) + XCTAssertEqual(json.numberValue, 54321.12345) + XCTAssertEqual(json.stringValue, "54321.12345") + + json.float = 23231.65 + XCTAssertEqual(json.float!, 23231.65) + XCTAssertEqual(json.floatValue, 23231.65) + XCTAssertEqual(json.numberValue, NSNumber(float:23231.65)) + + json.floatValue = -98766.23 + XCTAssertEqual(json.float!, -98766.23) + XCTAssertEqual(json.floatValue, -98766.23) + XCTAssertEqual(json.numberValue, NSNumber(float:-98766.23)) + } + + func testInt() { + var json = JSON(123456789) + XCTAssertEqual(json.int!, 123456789) + XCTAssertEqual(json.intValue, 123456789) + XCTAssertEqual(json.numberValue, NSNumber(integer: 123456789)) + XCTAssertEqual(json.stringValue, "123456789") + + json.int = nil + XCTAssertEqual(json.boolValue, false) + XCTAssertEqual(json.intValue, 0.0) + XCTAssertEqual(json.numberValue, 0) + XCTAssertEqual(json.object as NSNull, NSNull()) + XCTAssertTrue(json.int == nil) + + json.intValue = 76543 + XCTAssertEqual(json.int!, 76543) + XCTAssertEqual(json.intValue, 76543) + XCTAssertEqual(json.numberValue, NSNumber(integer: 76543)) + + json.intValue = 98765421 + XCTAssertEqual(json.int!, 98765421) + XCTAssertEqual(json.intValue, 98765421) + XCTAssertEqual(json.numberValue, NSNumber(integer: 98765421)) + } + + func testUInt() { + var json = JSON(123456789) + XCTAssertEqual(json.uInt!, 123456789) + XCTAssertEqual(json.uIntValue, 123456789) + XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 123456789)) + XCTAssertEqual(json.stringValue, "123456789") + + json.uInt = nil + XCTAssertEqual(json.boolValue, false) + XCTAssertEqual(json.uIntValue, 0.0) + XCTAssertEqual(json.numberValue, 0) + XCTAssertEqual(json.object as NSNull, NSNull()) + XCTAssertTrue(json.uInt == nil) + + json.uIntValue = 76543 + XCTAssertEqual(json.uInt!, 76543) + XCTAssertEqual(json.uIntValue, 76543) + XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 76543)) + + json.uIntValue = 98765421 + XCTAssertEqual(json.uInt!, 98765421) + XCTAssertEqual(json.uIntValue, 98765421) + XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 98765421)) + } + + func testInt8() { + let n127 = NSNumber(char: 127) + var json = JSON(n127) + XCTAssertTrue(json.int8! == n127.charValue) + XCTAssertTrue(json.int8Value == n127.charValue) + XCTAssertTrue(json.number! == n127) + XCTAssertEqual(json.numberValue, n127) + XCTAssertEqual(json.stringValue, "127") + + let nm128 = NSNumber(char: -128) + json.int8Value = nm128.charValue + XCTAssertTrue(json.int8! == nm128.charValue) + XCTAssertTrue(json.int8Value == nm128.charValue) + XCTAssertTrue(json.number! == nm128) + XCTAssertEqual(json.numberValue, nm128) + XCTAssertEqual(json.stringValue, "-128") + + let n0 = NSNumber(char: 0) + json.int8Value = n0.charValue + XCTAssertTrue(json.int8! == n0.charValue) + XCTAssertTrue(json.int8Value == n0.charValue) + println(json.number) + XCTAssertTrue(json.number! == n0) + XCTAssertEqual(json.numberValue, n0) + XCTAssertEqual(json.stringValue, "false") + + let n1 = NSNumber(char: 1) + json.int8Value = n1.charValue + XCTAssertTrue(json.int8! == n1.charValue) + XCTAssertTrue(json.int8Value == n1.charValue) + XCTAssertTrue(json.number! == n1) + XCTAssertEqual(json.numberValue, n1) + XCTAssertEqual(json.stringValue, "true") + } + + func testUInt8() { + let n255 = NSNumber(unsignedChar: 255) + var json = JSON(n255) + XCTAssertTrue(json.uInt8! == n255.unsignedCharValue) + XCTAssertTrue(json.uInt8Value == n255.unsignedCharValue) + XCTAssertTrue(json.number! == n255) + XCTAssertEqual(json.numberValue, n255) + XCTAssertEqual(json.stringValue, "255") + + let nm2 = NSNumber(unsignedChar: 2) + json.uInt8Value = nm2.unsignedCharValue + XCTAssertTrue(json.uInt8! == nm2.unsignedCharValue) + XCTAssertTrue(json.uInt8Value == nm2.unsignedCharValue) + XCTAssertTrue(json.number! == nm2) + XCTAssertEqual(json.numberValue, nm2) + XCTAssertEqual(json.stringValue, "2") + + let nm0 = NSNumber(unsignedChar: 0) + json.uInt8Value = nm0.unsignedCharValue + XCTAssertTrue(json.uInt8! == nm0.unsignedCharValue) + XCTAssertTrue(json.uInt8Value == nm0.unsignedCharValue) + XCTAssertTrue(json.number! == nm0) + XCTAssertEqual(json.numberValue, nm0) + XCTAssertEqual(json.stringValue, "0") + + let nm1 = NSNumber(unsignedChar: 1) + json.uInt8 = nm1.unsignedCharValue + XCTAssertTrue(json.uInt8! == nm1.unsignedCharValue) + XCTAssertTrue(json.uInt8Value == nm1.unsignedCharValue) + XCTAssertTrue(json.number! == nm1) + XCTAssertEqual(json.numberValue, nm1) + XCTAssertEqual(json.stringValue, "1") + } + + func testInt16() { + + let n32767 = NSNumber(short: 32767) + var json = JSON(n32767) + XCTAssertTrue(json.int16! == n32767.shortValue) + XCTAssertTrue(json.int16Value == n32767.shortValue) + XCTAssertTrue(json.number! == n32767) + XCTAssertEqual(json.numberValue, n32767) + XCTAssertEqual(json.stringValue, "32767") + + let nm32768 = NSNumber(short: -32768) + json.int16Value = nm32768.shortValue + XCTAssertTrue(json.int16! == nm32768.shortValue) + XCTAssertTrue(json.int16Value == nm32768.shortValue) + XCTAssertTrue(json.number! == nm32768) + XCTAssertEqual(json.numberValue, nm32768) + XCTAssertEqual(json.stringValue, "-32768") + + let n0 = NSNumber(short: 0) + json.int16Value = n0.shortValue + XCTAssertTrue(json.int16! == n0.shortValue) + XCTAssertTrue(json.int16Value == n0.shortValue) + println(json.number) + XCTAssertTrue(json.number! == n0) + XCTAssertEqual(json.numberValue, n0) + XCTAssertEqual(json.stringValue, "0") + + let n1 = NSNumber(short: 1) + json.int16 = n1.shortValue + XCTAssertTrue(json.int16! == n1.shortValue) + XCTAssertTrue(json.int16Value == n1.shortValue) + XCTAssertTrue(json.number! == n1) + XCTAssertEqual(json.numberValue, n1) + XCTAssertEqual(json.stringValue, "1") + } + + func testUInt16() { + + let n65535 = NSNumber(unsignedInteger: 65535) + var json = JSON(n65535) + XCTAssertTrue(json.uInt16! == n65535.unsignedShortValue) + XCTAssertTrue(json.uInt16Value == n65535.unsignedShortValue) + XCTAssertTrue(json.number! == n65535) + XCTAssertEqual(json.numberValue, n65535) + XCTAssertEqual(json.stringValue, "65535") + + let n32767 = NSNumber(unsignedInteger: 32767) + json.uInt16 = n32767.unsignedShortValue + XCTAssertTrue(json.uInt16! == n32767.unsignedShortValue) + XCTAssertTrue(json.uInt16Value == n32767.unsignedShortValue) + XCTAssertTrue(json.number! == n32767) + XCTAssertEqual(json.numberValue, n32767) + XCTAssertEqual(json.stringValue, "32767") + } + + func testInt32() { + let n2147483647 = NSNumber(int: 2147483647) + var json = JSON(n2147483647) + XCTAssertTrue(json.int32! == n2147483647.intValue) + XCTAssertTrue(json.int32Value == n2147483647.intValue) + XCTAssertTrue(json.number! == n2147483647) + XCTAssertEqual(json.numberValue, n2147483647) + XCTAssertEqual(json.stringValue, "2147483647") + + let n32767 = NSNumber(int: 32767) + json.int32 = n32767.intValue + XCTAssertTrue(json.int32! == n32767.intValue) + XCTAssertTrue(json.int32Value == n32767.intValue) + XCTAssertTrue(json.number! == n32767) + XCTAssertEqual(json.numberValue, n32767) + XCTAssertEqual(json.stringValue, "32767") + + let nm2147483648 = NSNumber(int: -2147483648) + json.int32Value = nm2147483648.intValue + XCTAssertTrue(json.int32! == nm2147483648.intValue) + XCTAssertTrue(json.int32Value == nm2147483648.intValue) + XCTAssertTrue(json.number! == nm2147483648) + XCTAssertEqual(json.numberValue, nm2147483648) + XCTAssertEqual(json.stringValue, "-2147483648") + } + + func testUInt32() { + let n2147483648 = NSNumber(unsignedInt: 2147483648) + var json = JSON(n2147483648) + XCTAssertTrue(json.uInt32! == n2147483648.unsignedIntValue) + XCTAssertTrue(json.uInt32Value == n2147483648.unsignedIntValue) + XCTAssertTrue(json.number! == n2147483648) + XCTAssertEqual(json.numberValue, n2147483648) + XCTAssertEqual(json.stringValue, "2147483648") + + let n32767 = NSNumber(unsignedInt: 32767) + json.uInt32 = n32767.unsignedIntValue + XCTAssertTrue(json.uInt32! == n32767.unsignedIntValue) + XCTAssertTrue(json.uInt32Value == n32767.unsignedIntValue) + XCTAssertTrue(json.number! == n32767) + XCTAssertEqual(json.numberValue, n32767) + XCTAssertEqual(json.stringValue, "32767") + + let n0 = NSNumber(unsignedInt: 0) + json.uInt32Value = n0.unsignedIntValue + XCTAssertTrue(json.uInt32! == n0.unsignedIntValue) + XCTAssertTrue(json.uInt32Value == n0.unsignedIntValue) + XCTAssertTrue(json.number! == n0) + XCTAssertEqual(json.numberValue, n0) + XCTAssertEqual(json.stringValue, "0") + } + + func testInt64() { + let int64Max = NSNumber(longLong: INT64_MAX) + var json = JSON(int64Max) + XCTAssertTrue(json.int64! == int64Max.longLongValue) + XCTAssertTrue(json.int64Value == int64Max.longLongValue) + XCTAssertTrue(json.number! == int64Max) + XCTAssertEqual(json.numberValue, int64Max) + XCTAssertEqual(json.stringValue, int64Max.stringValue) + + let n32767 = NSNumber(longLong: 32767) + json.int64 = n32767.longLongValue + XCTAssertTrue(json.int64! == n32767.longLongValue) + XCTAssertTrue(json.int64Value == n32767.longLongValue) + XCTAssertTrue(json.number! == n32767) + XCTAssertEqual(json.numberValue, n32767) + XCTAssertEqual(json.stringValue, "32767") + + let int64Min = NSNumber(longLong: (INT64_MAX-1) * -1) + json.int64Value = int64Min.longLongValue + XCTAssertTrue(json.int64! == int64Min.longLongValue) + XCTAssertTrue(json.int64Value == int64Min.longLongValue) + XCTAssertTrue(json.number! == int64Min) + XCTAssertEqual(json.numberValue, int64Min) + XCTAssertEqual(json.stringValue, int64Min.stringValue) + } + + func testUInt64() { + let uInt64Max = NSNumber(unsignedLongLong: UINT64_MAX) + var json = JSON(uInt64Max) + XCTAssertTrue(json.uInt64! == uInt64Max.unsignedLongLongValue) + XCTAssertTrue(json.uInt64Value == uInt64Max.unsignedLongLongValue) + XCTAssertTrue(json.number! == uInt64Max) + XCTAssertEqual(json.numberValue, uInt64Max) + XCTAssertEqual(json.stringValue, uInt64Max.stringValue) + + let n32767 = NSNumber(longLong: 32767) + json.int64 = n32767.longLongValue + XCTAssertTrue(json.int64! == n32767.longLongValue) + XCTAssertTrue(json.int64Value == n32767.longLongValue) + XCTAssertTrue(json.number! == n32767) + XCTAssertEqual(json.numberValue, n32767) + XCTAssertEqual(json.stringValue, "32767") + } +} diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift new file mode 100644 index 00000000..36ac3393 --- /dev/null +++ b/Tests/StringTests.swift @@ -0,0 +1,38 @@ +// +// StringTests.swift +// SwiftyJSON +// +// Created by Pinglin Tang on 14-10-7. +// +// + +import UIKit +import XCTest +import SwiftyJSON + +class StringTests: XCTestCase { + + func testString() { + //getter + var json = JSON("abcdefg hijklmn;opqrst.?+_()") + XCTAssertEqual(json.string!, "abcdefg hijklmn;opqrst.?+_()") + XCTAssertEqual(json.stringValue, "abcdefg hijklmn;opqrst.?+_()") + + json.string = "12345?67890.@#" + XCTAssertEqual(json.string!, "12345?67890.@#") + XCTAssertEqual(json.stringValue, "12345?67890.@#") + } + + func testURL() { + let json = JSON("http://github.com") + XCTAssertEqual(json.URL!, NSURL(string:"http://github.com")) + } + + func testURLPercentEscapes() { + let emDash = "\\u2014" + let urlString = "http://examble.com/unencoded" + emDash + "string" + let encodedURLString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) + let json = JSON(urlString) + XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!), "Wrong unpacked ") + } +} diff --git a/Tests/SwiftyJSONTests.swift b/Tests/SwiftyJSONTests.swift index bd059b30..1a97db6f 100644 --- a/Tests/SwiftyJSONTests.swift +++ b/Tests/SwiftyJSONTests.swift @@ -60,7 +60,6 @@ class SwiftyJSONTests: XCTestCase { func testCompare2() { let json = JSON("32.1234567890") - } func testCompare() { @@ -252,16 +251,7 @@ class SwiftyJSONTests: XCTestCase { let json = JSON(data:self.testData) XCTAssertNotNil(json.object) } - - func testJSONURLPercentEscapes() { - let emDash = "\\u2014" - let urlString = "http://examble.com/unencoded" + emDash + "string" - let encodedURLString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) - let json = JSON(urlString) - XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!), "Wrong unpacked ") - } - func testNumberCompare(){ XCTAssertEqual(NSNumber(double: 888332), NSNumber(int:888332)) XCTAssertNotEqual(NSNumber(double: 888332.1), NSNumber(int:888332)) From 46526110d0fa82308eed0ffd990d0e4c9b684bac Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 16:48:00 +0800 Subject: [PATCH 018/470] Update subscript's error --- Source/SwiftyJSON.swift | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 916dac70..59aa8613 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -202,10 +202,9 @@ extension JSON { returnJSON._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) } } else { - returnJSON._error = NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an array"]) + returnJSON._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) } return returnJSON - } set { if self.type == .Array { @@ -231,7 +230,7 @@ extension JSON { returnJSON._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) } } else { - returnJSON._error = NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Wrong type, It is not an dictionary"]) + returnJSON._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] failure, It is not an dictionary"]) } return returnJSON } @@ -400,7 +399,11 @@ extension JSON { } } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSMutableArray(array: newValue!, copyItems: true) + } else { + self.object = NSNull() + } } } } @@ -442,7 +445,11 @@ extension JSON { } } set { - self.object = newValue ?? NSNull() + if newValue != nil { + self.object = NSMutableDictionary(dictionary: newValue!, copyItems: true) + } else { + self.object = NSNull() + } } } } From 69439a5a72ac92d1e955ce61bfedb3637cc31328 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 16:48:32 +0800 Subject: [PATCH 019/470] Add Dictionary and Array tests --- SwiftyJSON.xcodeproj/project.pbxproj | 8 ++++ Tests/ArrayTests.swift | 46 +++++++++++++++++++++++ Tests/ComparableTests.swift | 1 - Tests/DictionaryTests.swift | 56 ++++++++++++++++++++++++++++ Tests/NumberTests.swift | 21 +++++++++-- Tests/StringTests.swift | 20 ++++++++-- Tests/SubscriptTests.swift | 24 +++++++++++- 7 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 Tests/ArrayTests.swift create mode 100644 Tests/DictionaryTests.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 52e8aad6..204bbaca 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -20,6 +20,8 @@ A87080EA19E43C0700CDE086 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; + A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; + A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -49,6 +51,8 @@ A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; + A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryTests.swift; sourceTree = ""; }; + A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -119,6 +123,8 @@ A87080E519E3DF7800CDE086 /* ComparableTests.swift */, A87080E919E43C0700CDE086 /* StringTests.swift */, A87080E719E439DA00CDE086 /* NumberTests.swift */, + A8B66C8B19E51D6500540692 /* DictionaryTests.swift */, + A8B66C8D19E52F4200540692 /* ArrayTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); path = Tests; @@ -253,6 +259,8 @@ A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, + A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, + A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */, A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */, A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */, A87080EA19E43C0700CDE086 /* StringTests.swift in Sources */, diff --git a/Tests/ArrayTests.swift b/Tests/ArrayTests.swift new file mode 100644 index 00000000..b7fbfc87 --- /dev/null +++ b/Tests/ArrayTests.swift @@ -0,0 +1,46 @@ +// ArrayTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class ArrayTests: XCTestCase { + + func testSingleDimensionalArraysGetter() { + let array = ["1","2", "a", "B", "D"] + let json = JSON(array) + XCTAssertEqual((json.array![0] as JSON).string!, "1") + XCTAssertEqual((json.array![1] as JSON).string!, "2") + XCTAssertEqual((json.array![2] as JSON).string!, "a") + XCTAssertEqual((json.array![3] as JSON).string!, "B") + XCTAssertEqual((json.array![4] as JSON).string!, "D") + } + + func testSingleDimensionalArraysSetter() { + let array = ["1","2", "a", "B", "D"] + var json = JSON(array) + json.arrayObject = ["111", "222"] + XCTAssertEqual((json.array![0] as JSON).string!, "111") + XCTAssertEqual((json.array![1] as JSON).string!, "222") + } +} diff --git a/Tests/ComparableTests.swift b/Tests/ComparableTests.swift index e57f3b33..71967fcd 100644 --- a/Tests/ComparableTests.swift +++ b/Tests/ComparableTests.swift @@ -1,4 +1,3 @@ -// // ComparableTests.swift // // Copyright (c) 2014 Pinglin Tang diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift new file mode 100644 index 00000000..60aa1bd5 --- /dev/null +++ b/Tests/DictionaryTests.swift @@ -0,0 +1,56 @@ +// DictionaryTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class DictionaryTests: XCTestCase { + + func testGetter() { + let dictionary = ["number":9823.212, "name":"NAME", "list":[1234, 4.212], "object":["sub_number":877.2323, "sub_name":"sub_name"], "bool":true] + let json = JSON(dictionary) + //dictionary + XCTAssertEqual((json.dictionary!["number"]! as JSON).double!, 9823.212) + XCTAssertEqual((json.dictionary!["name"]! as JSON).string!, "NAME") + XCTAssertEqual(((json.dictionary!["list"]! as JSON).array![0] as JSON).int!, 1234) + XCTAssertEqual(((json.dictionary!["list"]! as JSON).array![1] as JSON).int!, 4.212) + XCTAssertEqual((((json.dictionary!["object"]! as JSON).dictionaryValue)["sub_number"]! as JSON).double!, 877.2323) + XCTAssertTrue(json.dictionary!["null"] == nil) + //dictionaryValue + XCTAssertEqual(((((json.dictionaryValue)["object"]! as JSON).dictionaryValue)["sub_name"]! as JSON).string!, "sub_name") + XCTAssertEqual((json.dictionaryValue["bool"]! as JSON).bool!, true) + XCTAssertTrue(json.dictionaryValue["null"] == nil) + XCTAssertTrue(JSON.nullJSON.dictionaryValue == [:]) + //dictionaryObject + XCTAssertEqual(json.dictionaryObject!["number"]! as Double, 9823.212) + XCTAssertTrue(json.dictionaryObject!["null"] == nil) + XCTAssertTrue(JSON.nullJSON.dictionaryObject == nil) + } + + func testSetter() { + var json:JSON = ["test":"case"] + XCTAssertEqual(json.dictionaryObject! as Dictionary, ["test":"case"]) + json.dictionaryObject = ["name":"NAME"] + XCTAssertEqual(json.dictionaryObject! as Dictionary, ["name":"NAME"]) + } +} diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 4ec3cd2a..50e5defd 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -1,10 +1,24 @@ -// // NumberTests.swift -// SwiftyJSON // -// Created by Pinglin Tang on 14-10-7. +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. import UIKit import XCTest @@ -41,6 +55,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, false as NSNumber) json.bool = nil + XCTAssertTrue(json.bool == nil) XCTAssertEqual(json.boolValue, false) XCTAssertEqual(json.numberValue, 0) diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index 36ac3393..3ada0200 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -1,10 +1,24 @@ -// // StringTests.swift -// SwiftyJSON // -// Created by Pinglin Tang on 14-10-7. +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: // +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. import UIKit import XCTest diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 3be94a5a..778b7c71 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -159,7 +159,7 @@ class SubscriptTests: XCTestCase { func testDictionaryAllArray() { //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) - var json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertEqual(json[0], [1,2.123456,123456789]) XCTAssertEqual(json[0][1].double!, 2.123456) XCTAssertEqual(json[0][2], 123456789) @@ -172,10 +172,30 @@ class SubscriptTests: XCTestCase { } func testOutOfBounds() { - var json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertEqual(json[9], JSON.nullJSON) XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[9][8], JSON.nullJSON) + XCTAssertEqual(json[8][7].error!.code, ErrorIndexOutOfBounds) + } + + func testErrorWrongType() { + let json = JSON(12345) + XCTAssertEqual(json[9], JSON.nullJSON) + XCTAssertEqual(json[9].error!.code, ErrorWrongType) XCTAssertEqual(json[8][7].error!.code, ErrorWrongType) + XCTAssertEqual(json["name"], JSON.nullJSON) + XCTAssertEqual(json["name"].error!.code, ErrorWrongType) + XCTAssertEqual(json[0]["name"].error!.code, ErrorWrongType) + XCTAssertEqual(json["type"]["name"].error!.code, ErrorWrongType) + XCTAssertEqual(json["name"][99].error!.code, ErrorWrongType) + } + + func testErrorNotExist() { + let json = ["name":"NAME", "age":15] + XCTAssertEqual(json["Type"], JSON.nullJSON) + XCTAssertEqual(json["Type"].error!.code, ErrorNotExist) + XCTAssertEqual(json["Type"][1].error!.code, ErrorNotExist) + XCTAssertEqual(json["Type"]["Value"].error!.code, ErrorNotExist) } } From 776c79e2f3a7eb1e89e6b1cebedf1552e8b3c9e1 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 16:53:52 +0800 Subject: [PATCH 020/470] Change tests files name --- SwiftyJSON.xcodeproj/project.pbxproj | 16 ++++++++-------- Tests/{SwiftyJSONTests.swift => BaseTests.swift} | 6 +++--- Tests/{SwiftyJSONTests.json => Tests.json} | 0 3 files changed, 11 insertions(+), 11 deletions(-) rename Tests/{SwiftyJSONTests.swift => BaseTests.swift} (98%) rename Tests/{SwiftyJSONTests.json => Tests.json} (100%) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 204bbaca..8b60bb0c 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -18,8 +18,8 @@ A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; A87080EA19E43C0700CDE086 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; - A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */; }; - A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */; }; + A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */; }; + A885D1DC19CFCFF0002FD4C3 /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; /* End PBXBuildFile section */ @@ -49,8 +49,8 @@ A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = ""; }; A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberTests.swift; sourceTree = ""; }; A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; - A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSONTests.swift; sourceTree = ""; }; - A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; + A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseTests.swift; sourceTree = ""; }; + A885D1DA19CFCFF0002FD4C3 /* Tests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Tests.json; sourceTree = ""; }; A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryTests.swift; sourceTree = ""; }; A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTests.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -113,8 +113,8 @@ 2E4FEFEA19575BE100351305 /* Tests */ = { isa = PBXGroup; children = ( - A885D1DA19CFCFF0002FD4C3 /* SwiftyJSONTests.json */, - A885D1D119CF1EE6002FD4C3 /* SwiftyJSONTests.swift */, + A885D1DA19CFCFF0002FD4C3 /* Tests.json */, + A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */, A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */, A819C4A019E37FC600ADCC3D /* PrintableTests.swift */, A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */, @@ -235,7 +235,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - A885D1DC19CFCFF0002FD4C3 /* SwiftyJSONTests.json in Resources */, + A885D1DC19CFCFF0002FD4C3 /* Tests.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -258,7 +258,7 @@ A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */, A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, - A885D1D219CF1EE6002FD4C3 /* SwiftyJSONTests.swift in Sources */, + A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */, A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */, diff --git a/Tests/SwiftyJSONTests.swift b/Tests/BaseTests.swift similarity index 98% rename from Tests/SwiftyJSONTests.swift rename to Tests/BaseTests.swift index 1a97db6f..136473e6 100644 --- a/Tests/SwiftyJSONTests.swift +++ b/Tests/BaseTests.swift @@ -1,4 +1,4 @@ -// SwiftyJSONTests.swift +// BaseTests.swift // // Copyright (c) 2014 Ruoyu Fu, Pinglin Tang // @@ -24,7 +24,7 @@ import UIKit import XCTest import SwiftyJSON -class SwiftyJSONTests: XCTestCase { +class BaseTests: XCTestCase { var testData: NSData! @@ -32,7 +32,7 @@ class SwiftyJSONTests: XCTestCase { super.setUp() - if let file = NSBundle(forClass:SwiftyJSONTests.self).pathForResource("SwiftyJSONTests", ofType: "json") { + if let file = NSBundle(forClass:BaseTests.self).pathForResource("Tests", ofType: "json") { self.testData = NSData(contentsOfFile: file) } else { XCTFail("Can't find the test JSON file") diff --git a/Tests/SwiftyJSONTests.json b/Tests/Tests.json similarity index 100% rename from Tests/SwiftyJSONTests.json rename to Tests/Tests.json From ddd84ab2aeb3add95d88cd50cf3ef0ed5f004348 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 18:28:49 +0800 Subject: [PATCH 021/470] Update README.md --- README.md | 171 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 146 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 67f021bf..d59d3fb9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,22 @@ #SwiftyJSON + SwiftyJSON makes it easy to deal with JSON data in Swift. + +1. [Why is the typical JSON handling in Swift NOT good](#Why-is-the-typical-JSON-handling-in-Swift-NOT-good) +1. [Requirements](#requirements) +1. [Integration](#integration) +1. [Usage](#usage) + 1. [Initialization](#initialization) + 1. [Subscript](#subscript) + 1. [Error](#Error) + 1. [Loop](#loop) + 1. [Optional getter](#optional-getter) + 1. [Non-optional getter](#non-optional-getter) + 1. [Setter](#setter) + 1. [Raw object](#raw-object) + 1. [Literal convertible](#literal-convertible) +1. [Work with Alamofire](#work-with-alamofire) + ##Why is the typical JSON handling in Swift NOT good? Swift is very strict about types, it's good while explicit typing left us little chance to make mistakes. But while dealing with things that naturally implicit about types such as JSON, it's painful. @@ -68,11 +85,8 @@ if let userName = (((jsonObject as? NSArray)?[0] as? NSDictionary)?["user"] as? } ``` - An unreadable mess for something like this should really be simple! -##SwiftyJSON - With SwiftyJSON all you have to do is: ```swift @@ -103,6 +117,13 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ - iOS 7.0+ / Mac OS X 10.9+ - Xcode 6.0 +##Integration + +CocoaPods is not fully supported for Swift yet, to use this library in your project you should: + +1. for Projects just drag SwiftyJSON.swift to the project tree +2. for Workspaces you may include the whole SwiftyJSON.xcodeproj as suggested by @garnett + ## Usage ####Initialization @@ -110,31 +131,82 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ let json = JSON(data: dataFromNetworking) ``` ```swift -let json = JSON(object: jsonObject) +let json = JSON(jsonObject) +``` + +####Subscript +```swift +let name = json[0]["name"].stringValue ``` + ####Loop ```swift let json = JSON(data:dataFromNetworking) -//If json is .Mapping + //If json is .Dictionary for (key: String, subJson: JSON) in json { -//Do something you want + //Do something you want } -//If json is .Sequence +//If json is .Array //The `index` is 0.. = json["list"].arrayValue let user: Dictionary = json["user"].dictionaryValue ``` -####Get the raw object from JSON +####Setter ```swift -let json = JSON(data: dataFromNetworking) -if let jsonObject: AnyObject = json.object { - // do something +json["id"].int = 1234567890 +json["coordinate"].double = 8766.766 +json["name"].string = "Jack" +json.array = [1,2,3,4] +json.dictionary = ["name":"Jack", "age":25] +``` +####Raw object +```swift +let jsonObject: AnyObject = json.object +``` +```swift +if let jsonObject: AnyObject = json.toRaw +``` +```swift +if let json = JSON.fromRaw(object) { + //object can be converted to JSON } else { - // print the error - println(json) + //object can not be converted to JSON } ``` - -##Integration - -CocoaPods is not fully supported for Swift yet, to use this library in your project you should: - -1. for Projects just drag SwiftyJSON.swift to the project tree -2. for Workspaces you may include the whole SwiftyJSON.xcodeproj as suggested by @garnett - +####Literal convertible +More info about the literal convertible. please read [Swift Literal Convertibles](http://nshipster.com/swift-literal-convertible/) by Mattt Thompson +```swift +//StringLiteralConvertible +let json:JSON = "I'm a json" +``` +```swift +//IntegerLiteralConvertible +let json:JSON = 12345 +``` +```swift +//BooleanLiteralConvertible +let json:JSON = true +``` +```swift +//FloatLiteralConvertible +let json:JSON = 2.8765 +``` +```swift +//DictionaryLiteralConvertible +let json:JSON = ["I":"am", "a":"json"] +``` +```swift +//ArrayLiteralConvertible +let json:JSON = ["I", "am", "a", "json"] +``` +```swift +//NilLiteralConvertible +let json:JSON = nil +``` +```swift +//With subscript in array +var json:JSON = [1,2,3] +json[0] = 100 +json[1] = 200 +json[2] = 300 +json[999] = 300 //Don't worry, nothing will happen +``` +```swift +//With subscript in dictionary +var json:JSON = ["name":"Jack", "age": 25] +json["name"] = "Mike" +json["age"] = "25" //It's OK to set String +json["address"] = "L.A." // Add the "address": "L.A." in json +``` ##Work with Alamofire From 8186d6c780754fe2447b608cd792932133b7c04f Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 18:30:55 +0800 Subject: [PATCH 022/470] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d59d3fb9..82f16823 100644 --- a/README.md +++ b/README.md @@ -229,7 +229,7 @@ if let id = json["user"]["is_translator"].bool { ``` ```swift //Int -if let id = json["user"]["id"].integer { +if let id = json["user"]["id"].int { //Do something you want } else { //Print the error @@ -241,7 +241,7 @@ if let id = json["user"]["id"].integer { Non-optional getter is named `xxxValue` ```swift //If not a Number or nil, return 0 -let id: Int = json["id"].integerValue +let id: Int = json["id"].intValue ``` ```swift //If not a String or nil, return "" From f6e8580368ea7a46eb565821d4f309d57a63c1db Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 18:35:55 +0800 Subject: [PATCH 023/470] Update README.md --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 82f16823..0e7f287a 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,15 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. 1. [Requirements](#requirements) 1. [Integration](#integration) 1. [Usage](#usage) - 1. [Initialization](#initialization) - 1. [Subscript](#subscript) - 1. [Error](#Error) - 1. [Loop](#loop) - 1. [Optional getter](#optional-getter) - 1. [Non-optional getter](#non-optional-getter) - 1. [Setter](#setter) - 1. [Raw object](#raw-object) - 1. [Literal convertible](#literal-convertible) + - [Initialization](#initialization) + - [Subscript](#subscript) + - [Error](#Error) + - [Loop](#loop) + - [Optional getter](#optional-getter) + - [Non-optional getter](#non-optional-getter) + - [Setter](#setter) + - [Raw object](#raw-object) + - [Literal convertible](#literal-convertible) 1. [Work with Alamofire](#work-with-alamofire) ##Why is the typical JSON handling in Swift NOT good? From 54d5a5eb2bc881ff316c2bc37d2ae03131ed6426 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 18:40:15 +0800 Subject: [PATCH 024/470] Update error's printable --- Source/SwiftyJSON.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 59aa8613..acc301aa 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -332,7 +332,7 @@ extension JSON: Printable, DebugPrintable { case .Null: return self.error?.description ?? "null" default: - return "unknown" + return self.error?.description ?? "unknown" } } } @@ -351,13 +351,9 @@ extension JSON: Printable, DebugPrintable { case .Bool: return (self.object as Bool).description case .Null: - if self.error != nil { - return self.error!.debugDescription - } else { - return "null" - } + return self.error?.debugDescription ?? "null" default: - return "unknown" + return self.error?.debugDescription ?? "unknown" } } } From 5c4773be8f4b8fe4d4c8bf129500b0e157deddd4 Mon Sep 17 00:00:00 2001 From: Ross Kimes Date: Wed, 8 Oct 2014 09:55:29 -0500 Subject: [PATCH 025/470] Added support for Xcode 6.1 GM Seed 2. --- Example/AppDelegate.swift | 2 +- Source/SwiftyJSON.swift | 95 +++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 44 deletions(-) diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 391ab66b..ee00e609 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -34,7 +34,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let viewController = navigationController.topViewController as ViewController if let file = NSBundle(forClass:AppDelegate.self).pathForResource("SwiftyJSONTests", ofType: "json") { - let data = NSData(contentsOfFile: file) + let data = NSData(contentsOfFile: file)! let json = JSON(data:data) viewController.json = json } else { diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index acc301aa..491312d3 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -246,71 +246,80 @@ extension JSON { //MARK:- LiteralConvertible extension JSON: StringLiteralConvertible { - - public static func convertFromStringLiteral(value: StringLiteralType) -> JSON { - return JSON(value) - } - - public static func convertFromExtendedGraphemeClusterLiteral(value: StringLiteralType) -> JSON { - return JSON(value) - } + + public init(stringLiteral value: StringLiteralType) { + self.init(value) + } + + public init(extendedGraphemeClusterLiteral value: StringLiteralType) { + self.init(value) + } + + public init(unicodeScalarLiteral value: StringLiteralType) { + self.init(value) + } } extension JSON: IntegerLiteralConvertible { - public static func convertFromIntegerLiteral(value: IntegerLiteralType) -> JSON { - return JSON(value) - } + + public init(integerLiteral value: IntegerLiteralType) { + self.init(value) + } } extension JSON: BooleanLiteralConvertible { - public static func convertFromBooleanLiteral(value: BooleanLiteralType) -> JSON { - return JSON(value) - } + + public init(booleanLiteral value: BooleanLiteralType) { + self.init(value) + } } extension JSON: FloatLiteralConvertible { - public static func convertFromFloatLiteral(value: FloatLiteralType) -> JSON { - return JSON(value) - } + + public init(floatLiteral value: FloatLiteralType) { + self.init(value) + } } extension JSON: DictionaryLiteralConvertible { - public static func convertFromDictionaryLiteral(elements: (String, AnyObject)...) -> JSON { - var dictionary_ = [String : AnyObject]() - for (key_, value) in elements { - dictionary_[key_] = value - } - return JSON(dictionary_) - } + + public init(dictionaryLiteral elements: (String, AnyObject)...) { + var dictionary_ = [String : AnyObject]() + for (key_, value) in elements { + dictionary_[key_] = value + } + self.init(dictionary_) + } } extension JSON: ArrayLiteralConvertible { - public static func convertFromArrayLiteral(elements: AnyObject...) -> JSON { - return JSON(elements) - } + + public init(arrayLiteral elements: AnyObject...) { + self.init(elements) + } } extension JSON: NilLiteralConvertible { - public static func convertFromNilLiteral() -> JSON { - return JSON(NSNull()) - } + + public init(nilLiteral: ()) { + self.init(NSNull()) + } } //MARK:- RawRepresentable extension JSON: RawRepresentable { - - public static func fromRaw(raw: AnyObject) -> JSON? { - let json = JSON(raw) - if json.type == .Unknow { - return nil - } else { - return json - } - } - - public func toRaw() -> AnyObject { - return self.object - } + + public init?(rawValue: AnyObject) { + if JSON(rawValue).type == .Unknow { + return nil + } else { + self.init(rawValue) + } + } + + public var rawValue: AnyObject { + return self.object + } } //MARK: - Printable, DebugPrintable From 5115f09e3e3c1322ee2babe4b37860012c1a15ee Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 23:12:58 +0800 Subject: [PATCH 026/470] Remove needless setting --- Example.xcodeproj/project.pbxproj | 8 -------- 1 file changed, 8 deletions(-) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index 5a8bba51..20596a92 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -343,10 +343,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/build/Debug-iphoneos", - ); INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -357,10 +353,6 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/build/Debug-iphoneos", - ); INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; From bc4a6fc80b83c8205a9761e7312d31e688972cf6 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 23:13:38 +0800 Subject: [PATCH 027/470] Add JSON data's looping test --- Tests/SequenceTypeTests.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index 17c48cd8..b7273324 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -27,6 +27,26 @@ import SwiftyJSON class SequenceTypeTests: XCTestCase { + func testJSONFile() { + if let file = NSBundle(forClass:BaseTests.self).pathForResource("Tests", ofType: "json") { + let testData = NSData(contentsOfFile: file) + let json = JSON(data:testData) + for (index, sub) in json { + switch (index as NSString).integerValue { + case 0: + XCTAssertEqual(sub["id_str"],"240558470661799936") + case 1: + XCTAssertEqual(sub["id_str"],"240556426106372096") + case 2: + XCTAssertEqual(sub["id_str"],"240539141056638977") + default:0 + } + } + } else { + XCTFail("Can't find the test JSON file") + } + } + func testArrayAllNumber() { var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] XCTAssertEqual(json.count, 5) From dda34da59d1fe0cfd09a9f2e37c00b98ee90988b Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 8 Oct 2014 23:36:49 +0800 Subject: [PATCH 028/470] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 0e7f287a..c5ee2ed4 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,8 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ - iOS 7.0+ / Mac OS X 10.9+ - Xcode 6.0 +> For Xcode 6.1, check out the `xcode6.1` branch. + ##Integration CocoaPods is not fully supported for Swift yet, to use this library in your project you should: From abc285c05f4ceedda49322f80a4ec1c5c1599ee1 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 9 Oct 2014 07:47:11 +0800 Subject: [PATCH 029/470] Update README.md --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c5ee2ed4..706301c3 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Non-optional getter](#non-optional-getter) - [Setter](#setter) - [Raw object](#raw-object) - - [Literal convertible](#literal-convertible) + - [Literal convertibles](#literal-convertibles) 1. [Work with Alamofire](#work-with-alamofire) ##Why is the typical JSON handling in Swift NOT good? @@ -143,11 +143,12 @@ let name = json[0]["name"].stringValue ####Loop ```swift -let json = JSON(data:dataFromNetworking) - //If json is .Dictionary +//If json is .Dictionary for (key: String, subJson: JSON) in json { - //Do something you want +//Do something you want } +``` +```swift //If json is .Array //The `index` is 0.. Date: Thu, 9 Oct 2014 17:23:11 +0800 Subject: [PATCH 030/470] Update tests for Xcode 6.1 GM 2 --- Tests/BaseTests.swift | 2 +- Tests/ComparableTests.swift | 38 ++++----- Tests/DictionaryTests.swift | 2 +- Tests/LiteralConvertibleTests.swift | 4 +- Tests/NumberTests.swift | 28 +++---- Tests/PrintableTests.swift | 4 +- Tests/RawRepresentableTests.swift | 34 ++++---- Tests/SequenceTypeTests.swift | 16 ++-- Tests/StringTests.swift | 4 +- Tests/SubscriptTests.swift | 124 ++++++++++++++-------------- 10 files changed, 127 insertions(+), 129 deletions(-) diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 136473e6..f2d557dd 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -99,7 +99,7 @@ class BaseTests: XCTestCase { let new_tweets_1_coordinates_coordinates = JSON([-122.25831,37.871609]) XCTAssertEqual(tweets_1_coordinates_coordinates, new_tweets_1_coordinates_coordinates) XCTAssertEqual(tweets_1_coordinates_coordinates_point_0_double!, -122.25831) - XCTAssertEqual(tweets_1_coordinates_coordinates_point_1_float!, 37.871609) + XCTAssertTrue(tweets_1_coordinates_coordinates_point_1_float! == 37.871609) let tweets_1_coordinates_coordinates_point_0_string = tweets_1_coordinates_coordinates[0].stringValue let tweets_1_coordinates_coordinates_point_1_string = tweets_1_coordinates_coordinates[1].stringValue XCTAssertEqual(tweets_1_coordinates_coordinates_point_0_string, "-122.25831") diff --git a/Tests/ComparableTests.swift b/Tests/ComparableTests.swift index 71967fcd..465949ed 100644 --- a/Tests/ComparableTests.swift +++ b/Tests/ComparableTests.swift @@ -30,35 +30,35 @@ class ComparableTests: XCTestCase { var jsonL1:JSON = 1234567890.876623 var jsonR1:JSON = JSON(1234567890.876623) XCTAssertEqual(jsonL1, jsonR1) - XCTAssertEqual(jsonL1, 1234567890.876623) + XCTAssertTrue(jsonL1 == 1234567890.876623) var jsonL2:JSON = 987654321 var jsonR2:JSON = JSON(987654321) XCTAssertEqual(jsonL2, jsonR2) - XCTAssertEqual(jsonR2, 987654321) + XCTAssertTrue(jsonR2 == 987654321) var jsonL3:JSON = JSON(NSNumber(double:87654321.12345678)) var jsonR3:JSON = JSON(NSNumber(double:87654321.12345678)) XCTAssertEqual(jsonL3, jsonR3) - XCTAssertEqual(jsonR3, 87654321.12345678) + XCTAssertTrue(jsonR3 == 87654321.12345678) } func testNumberNotEqual() { var jsonL1:JSON = 1234567890.876623 var jsonR1:JSON = JSON(123.123) XCTAssertNotEqual(jsonL1, jsonR1) - XCTAssertNotEqual(jsonL1, 34343) + XCTAssertFalse(jsonL1 == 34343) var jsonL2:JSON = 8773 var jsonR2:JSON = JSON(123.23) XCTAssertNotEqual(jsonL2, jsonR2) - XCTAssertNotEqual(jsonR1, 454352) + XCTAssertFalse(jsonR1 == 454352) var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) var jsonR3:JSON = JSON(NSNumber(double:87654321.45678)) XCTAssertNotEqual(jsonL3, jsonR3) - XCTAssertNotEqual(jsonL3, 4545.232) + XCTAssertFalse(jsonL3 == 4545.232) } func testNumberGreaterThanOrEqual() { @@ -133,7 +133,7 @@ class ComparableTests: XCTestCase { var jsonL1:JSON = true var jsonR1:JSON = JSON(true) XCTAssertEqual(jsonL1, jsonR1) - XCTAssertEqual(jsonL1, true) + XCTAssertTrue(jsonL1 == true) var jsonL2:JSON = false var jsonR2:JSON = JSON(false) @@ -145,7 +145,7 @@ class ComparableTests: XCTestCase { var jsonL1:JSON = true var jsonR1:JSON = JSON(false) XCTAssertNotEqual(jsonL1, jsonR1) - XCTAssertNotEqual(jsonL1, false) + XCTAssertTrue(jsonL1 != false) var jsonL2:JSON = false var jsonR2:JSON = JSON(true) @@ -157,7 +157,7 @@ class ComparableTests: XCTestCase { var jsonL1:JSON = true var jsonR1:JSON = JSON(true) XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) - XCTAssertGreaterThanOrEqual(jsonL1,true) + XCTAssertTrue(jsonL1 >= true) var jsonL2:JSON = false var jsonR2:JSON = JSON(false) @@ -169,7 +169,7 @@ class ComparableTests: XCTestCase { var jsonL1:JSON = true var jsonR1:JSON = JSON(true) XCTAssertLessThanOrEqual(jsonL1, jsonR1) - XCTAssertLessThanOrEqual(true, jsonR1) + XCTAssertTrue(true <= jsonR1) var jsonL2:JSON = false var jsonR2:JSON = JSON(false) @@ -234,7 +234,7 @@ class ComparableTests: XCTestCase { var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertEqual(jsonL1, jsonR1) - XCTAssertEqual(jsonL1, "abcdefg 123456789 !@#$%^&*()") + XCTAssertTrue(jsonL1 == "abcdefg 123456789 !@#$%^&*()") } func testStringNotEqual() { @@ -242,7 +242,7 @@ class ComparableTests: XCTestCase { var jsonR1:JSON = JSON("-=[]\\\"987654321") XCTAssertNotEqual(jsonL1, jsonR1) - XCTAssertNotEqual(jsonL1, "not equal") + XCTAssertTrue(jsonL1 != "not equal") } func testStringGreaterThanOrEqual() { @@ -250,12 +250,12 @@ class ComparableTests: XCTestCase { var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) - XCTAssertGreaterThanOrEqual(jsonL1, "abcdefg 123456789 !@#$%^&*()") + XCTAssertTrue(jsonL1 >= "abcdefg 123456789 !@#$%^&*()") var jsonL2:JSON = "z-+{}:" var jsonR2:JSON = JSON("a<>?:") XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) - XCTAssertGreaterThanOrEqual(jsonL2, "mnbvcxz") + XCTAssertTrue(jsonL2 >= "mnbvcxz") } func testStringLessThanOrEqual() { @@ -263,12 +263,12 @@ class ComparableTests: XCTestCase { var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertLessThanOrEqual(jsonL1, jsonR1) - XCTAssertLessThanOrEqual(jsonL1, "abcdefg 123456789 !@#$%^&*()") + XCTAssertTrue(jsonL1 <= "abcdefg 123456789 !@#$%^&*()") var jsonL2:JSON = "z-+{}:" var jsonR2:JSON = JSON("a<>?:") XCTAssertLessThanOrEqual(jsonR2, jsonL2) - XCTAssertLessThanOrEqual("mnbvcxz", jsonL2) + XCTAssertTrue("mnbvcxz" <= jsonL2) } func testStringGreaterThan() { @@ -301,7 +301,7 @@ class ComparableTests: XCTestCase { var jsonL1:JSON = nil var jsonR1:JSON = JSON(NSNull()) XCTAssertEqual(jsonL1, jsonR1) - XCTAssertNotEqual(jsonL1, "123") + XCTAssertTrue(jsonL1 != "123") XCTAssertFalse(jsonL1 > "abcd") XCTAssertFalse(jsonR1 < "*&^") XCTAssertFalse(jsonL1 >= "jhfid") @@ -314,8 +314,8 @@ class ComparableTests: XCTestCase { var jsonL1:JSON = [1,2,"4",5,"6"] var jsonR1:JSON = JSON([1,2,"4",5,"6"]) XCTAssertEqual(jsonL1, jsonR1) - XCTAssertEqual(jsonL1, [1,2,"4",5,"6"]) - XCTAssertNotEqual(jsonL1, ["abcd","efg"]) + XCTAssertTrue(jsonL1 == [1,2,"4",5,"6"]) + XCTAssertTrue(jsonL1 != ["abcd","efg"]) XCTAssertTrue(jsonL1 >= jsonR1) XCTAssertTrue(jsonL1 <= jsonR1) XCTAssertFalse(jsonL1 > ["abcd",""]) diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index 60aa1bd5..4ed4a31b 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -33,7 +33,7 @@ class DictionaryTests: XCTestCase { XCTAssertEqual((json.dictionary!["number"]! as JSON).double!, 9823.212) XCTAssertEqual((json.dictionary!["name"]! as JSON).string!, "NAME") XCTAssertEqual(((json.dictionary!["list"]! as JSON).array![0] as JSON).int!, 1234) - XCTAssertEqual(((json.dictionary!["list"]! as JSON).array![1] as JSON).int!, 4.212) + XCTAssertEqual(((json.dictionary!["list"]! as JSON).array![1] as JSON).double!, 4.212) XCTAssertEqual((((json.dictionary!["object"]! as JSON).dictionaryValue)["sub_number"]! as JSON).double!, 877.2323) XCTAssertTrue(json.dictionary!["null"] == nil) //dictionaryValue diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift index 2db8f561..9902ba15 100644 --- a/Tests/LiteralConvertibleTests.swift +++ b/Tests/LiteralConvertibleTests.swift @@ -32,8 +32,8 @@ class LiteralConvertibleTests: XCTestCase { XCTAssertEqual(json.intValue, 1234567890) XCTAssertEqual(json.double!, 1234567890.876623) XCTAssertEqual(json.doubleValue, 1234567890.876623) - XCTAssertEqual(json.float!, 1234567890.876623) - XCTAssertEqual(json.floatValue, 1234567890.876623) + XCTAssertTrue(json.float! == 1234567890.876623) + XCTAssertTrue(json.floatValue == 1234567890.876623) } func testBool() { diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 50e5defd..89ed546f 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -90,15 +90,15 @@ class NumberTests: XCTestCase { func testFloat() { var json = JSON(54321.12345) - XCTAssertEqual(json.float!, 54321.12345) - XCTAssertEqual(json.floatValue, 54321.12345) + XCTAssertTrue(json.float! == 54321.12345) + XCTAssertTrue(json.floatValue == 54321.12345) println(json.numberValue.doubleValue) XCTAssertEqual(json.numberValue, 54321.12345) XCTAssertEqual(json.stringValue, "54321.12345") json.float = 23231.65 - XCTAssertEqual(json.float!, 23231.65) - XCTAssertEqual(json.floatValue, 23231.65) + XCTAssertTrue(json.float! == 23231.65) + XCTAssertTrue(json.floatValue == 23231.65) XCTAssertEqual(json.numberValue, NSNumber(float:23231.65)) json.floatValue = -98766.23 @@ -115,8 +115,8 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.stringValue, "123456789") json.int = nil - XCTAssertEqual(json.boolValue, false) - XCTAssertEqual(json.intValue, 0.0) + XCTAssertTrue(json.boolValue == false) + XCTAssertTrue(json.intValue == 0) XCTAssertEqual(json.numberValue, 0) XCTAssertEqual(json.object as NSNull, NSNull()) XCTAssertTrue(json.int == nil) @@ -134,26 +134,26 @@ class NumberTests: XCTestCase { func testUInt() { var json = JSON(123456789) - XCTAssertEqual(json.uInt!, 123456789) - XCTAssertEqual(json.uIntValue, 123456789) + XCTAssertTrue(json.uInt! == 123456789) + XCTAssertTrue(json.uIntValue == 123456789) XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 123456789)) XCTAssertEqual(json.stringValue, "123456789") json.uInt = nil - XCTAssertEqual(json.boolValue, false) - XCTAssertEqual(json.uIntValue, 0.0) + XCTAssertTrue(json.boolValue == false) + XCTAssertTrue(json.uIntValue == 0) XCTAssertEqual(json.numberValue, 0) XCTAssertEqual(json.object as NSNull, NSNull()) XCTAssertTrue(json.uInt == nil) json.uIntValue = 76543 - XCTAssertEqual(json.uInt!, 76543) - XCTAssertEqual(json.uIntValue, 76543) + XCTAssertTrue(json.uInt! == 76543) + XCTAssertTrue(json.uIntValue == 76543) XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 76543)) json.uIntValue = 98765421 - XCTAssertEqual(json.uInt!, 98765421) - XCTAssertEqual(json.uIntValue, 98765421) + XCTAssertTrue(json.uInt! == 98765421) + XCTAssertTrue(json.uIntValue == 98765421) XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 98765421)) } diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index f2ddcb9a..e0dabf35 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -63,7 +63,7 @@ class PrintableTests: XCTestCase { func testDictionary() { var json:JSON = ["1":2,"2":2, "3":3] - XCTAssertEqual(json.description, "[2: 2, 3: 3, 1: 2]") - XCTAssertEqual(json.debugDescription, "[\"2\": 2, \"3\": 3, \"1\": 2]") + XCTAssertEqual(json.description, ["1":2,"2":2, "3":3].description) + XCTAssertEqual(json.debugDescription, ["1":2,"2":2, "3":3].debugDescription) } } diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index 926612b2..8325c2ae 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -27,48 +27,46 @@ import SwiftyJSON class RawRepresentableTests: XCTestCase { func testNumber() { - var json:JSON = JSON.fromRaw(948394394.347384 as NSNumber)! + var json:JSON = JSON(rawValue: 948394394.347384 as NSNumber)! XCTAssertEqual(json.int!, 948394394) XCTAssertEqual(json.intValue, 948394394) XCTAssertEqual(json.double!, 948394394.347384) XCTAssertEqual(json.doubleValue, 948394394.347384) - XCTAssertEqual(json.float!, 948394394.347384) - XCTAssertEqual(json.floatValue, 948394394.347384) + XCTAssertTrue(json.float! == 948394394.347384) + XCTAssertTrue(json.floatValue == 948394394.347384) - var object: AnyObject = json.toRaw() + var object: AnyObject = json.rawValue XCTAssertEqual(object as Int, 948394394) XCTAssertEqual(object as Double, 948394394.347384) - XCTAssertEqual(object as Float, 948394394.347384) + XCTAssertTrue(object as Float == 948394394.347384) XCTAssertEqual(object as NSNumber, 948394394.347384) } func testBool() { - var jsonTrue:JSON = JSON.fromRaw(true as NSNumber)! + var jsonTrue:JSON = JSON(rawValue: true as NSNumber)! XCTAssertEqual(jsonTrue.bool!, true) XCTAssertEqual(jsonTrue.boolValue, true) - var jsonFalse:JSON = JSON.fromRaw(false)! + var jsonFalse:JSON = JSON(rawValue: false)! XCTAssertEqual(jsonFalse.bool!, false) XCTAssertEqual(jsonFalse.boolValue, false) - var objectTrue: AnyObject = jsonTrue.toRaw() + var objectTrue: AnyObject = jsonTrue.rawValue XCTAssertEqual(objectTrue as Int, 1) XCTAssertEqual(objectTrue as Double, 1.0) - XCTAssertEqual(objectTrue as Float, 1.0) XCTAssertEqual(objectTrue as Bool, true) XCTAssertEqual(objectTrue as NSNumber, NSNumber(bool: true)) - var objectFalse: AnyObject = jsonFalse.toRaw() + var objectFalse: AnyObject = jsonFalse.rawValue XCTAssertEqual(objectFalse as Int, 0) XCTAssertEqual(objectFalse as Double, 0.0) - XCTAssertEqual(objectFalse as Float, 0.0) XCTAssertEqual(objectFalse as Bool, false) XCTAssertEqual(objectFalse as NSNumber, NSNumber(bool: false)) } func testString() { let string = "The better way to deal with JSON data in Swift." - if let json:JSON = JSON.fromRaw(string) { + if let json:JSON = JSON(rawValue: string) { XCTAssertEqual(json.string!, string) XCTAssertEqual(json.stringValue, string) XCTAssertTrue(json.array == nil) @@ -81,33 +79,33 @@ class RawRepresentableTests: XCTestCase { XCTFail("Should not run into here") } - let object: AnyObject = JSON.fromRaw(string)!.toRaw() + let object: AnyObject = JSON(rawValue: string)!.rawValue XCTAssertEqual(object as String, string) } func testNil() { - if let json = JSON.fromRaw(NSObject()) { + if let json = JSON(rawValue: NSObject()) { XCTFail("Should not run into here") } } func testArray() { let array = [1,2,"3",4102,"5632", "abocde", "!@# $%^&*()"] as NSArray - if let json:JSON = JSON.fromRaw(array) { + if let json:JSON = JSON(rawValue: array) { XCTAssertEqual(json, JSON(array)) } - let object: AnyObject = JSON.fromRaw(array)!.toRaw() + let object: AnyObject = JSON(rawValue: array)!.rawValue XCTAssertTrue(array == object as NSArray) } func testDictionary() { let dictionary = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] as NSDictionary - if let json:JSON = JSON.fromRaw(dictionary) { + if let json:JSON = JSON(rawValue: dictionary) { XCTAssertEqual(json, JSON(dictionary)) } - let object: AnyObject = JSON.fromRaw(dictionary)!.toRaw() + let object: AnyObject = JSON(rawValue: dictionary)!.rawValue XCTAssertTrue(dictionary == object as NSDictionary) } } diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index b7273324..7cdd838d 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -30,15 +30,15 @@ class SequenceTypeTests: XCTestCase { func testJSONFile() { if let file = NSBundle(forClass:BaseTests.self).pathForResource("Tests", ofType: "json") { let testData = NSData(contentsOfFile: file) - let json = JSON(data:testData) + let json = JSON(data:testData!) for (index, sub) in json { switch (index as NSString).integerValue { case 0: - XCTAssertEqual(sub["id_str"],"240558470661799936") + XCTAssertTrue(sub["id_str"] == "240558470661799936") case 1: - XCTAssertEqual(sub["id_str"],"240556426106372096") + XCTAssertTrue(sub["id_str"] == "240556426106372096") case 2: - XCTAssertEqual(sub["id_str"],"240539141056638977") + XCTAssertTrue(sub["id_str"] == "240539141056638977") default:0 } } @@ -80,7 +80,7 @@ class SequenceTypeTests: XCTestCase { } func testArrayAllString() { - var json:JSON = JSON.fromRaw(["aoo","bpp","zoo"] as NSArray)! + var json:JSON = JSON(rawValue: ["aoo","bpp","zoo"] as NSArray)! XCTAssertEqual(json.count, 3) var index = 0 @@ -96,7 +96,7 @@ class SequenceTypeTests: XCTestCase { } func testArrayWithNull() { - var json:JSON = JSON.fromRaw(["aoo","bpp", NSNull() ,"zoo"] as NSArray)! + var json:JSON = JSON(rawValue: ["aoo","bpp", NSNull() ,"zoo"] as NSArray)! XCTAssertEqual(json.count, 4) var index = 0 @@ -167,7 +167,7 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryAllString() { - var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! + var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! XCTAssertEqual(json.count, 3) var index = 0 @@ -184,7 +184,7 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryWithNull() { - var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! + var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! XCTAssertEqual(json.count, 4) var index = 0 diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index 3ada0200..880cfe7e 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -39,7 +39,7 @@ class StringTests: XCTestCase { func testURL() { let json = JSON("http://github.com") - XCTAssertEqual(json.URL!, NSURL(string:"http://github.com")) + XCTAssertEqual(json.URL!, NSURL(string:"http://github.com")!) } func testURLPercentEscapes() { @@ -47,6 +47,6 @@ class StringTests: XCTestCase { let urlString = "http://examble.com/unencoded" + emDash + "string" let encodedURLString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) let json = JSON(urlString) - XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!), "Wrong unpacked ") + XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!)!, "Wrong unpacked ") } } diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 778b7c71..6d3268b1 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -28,10 +28,10 @@ class SubscriptTests: XCTestCase { func testArrayAllNumber() { var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] - XCTAssertEqual(json, [1,2.0,3.3,123456789,987654321.123456789]) - XCTAssertEqual(json[0], 1) + XCTAssertTrue(json == [1,2.0,3.3,123456789,987654321.123456789]) + XCTAssertTrue(json[0] == 1) XCTAssertEqual(json[1].double!, 2.0) - XCTAssertEqual(json[2].floatValue, 3.3) + XCTAssertTrue(json[2].floatValue == 3.3) XCTAssertEqual(json[3].int!, 123456789) XCTAssertEqual(json[4].doubleValue, 987654321.123456789) @@ -41,66 +41,66 @@ class SubscriptTests: XCTestCase { json[3] = 0.999 json[4] = 98732 - XCTAssertEqual(json[0], 1.9) + XCTAssertTrue(json[0] == 1.9) XCTAssertEqual(json[1].doubleValue, 2.899) - XCTAssertEqual(json[2], 3.567) - XCTAssertEqual(json[3].float!, 0.999) - XCTAssertEqual(json[4].intValue, 98732) + XCTAssertTrue(json[2] == 3.567) + XCTAssertTrue(json[3].float! == 0.999) + XCTAssertTrue(json[4].intValue == 98732) } func testArrayAllBool() { var json:JSON = [true, false, false, true, true] - XCTAssertEqual(json, [true, false, false, true, true]) - XCTAssertEqual(json[0], true) - XCTAssertEqual(json[1], false) - XCTAssertEqual(json[2], false) - XCTAssertEqual(json[3], true) - XCTAssertEqual(json[4], true) + XCTAssertTrue(json == [true, false, false, true, true]) + XCTAssertTrue(json[0] == true) + XCTAssertTrue(json[1] == false) + XCTAssertTrue(json[2] == false) + XCTAssertTrue(json[3] == true) + XCTAssertTrue(json[4] == true) json[0] = false json[4] = true - XCTAssertEqual(json[0], false) - XCTAssertEqual(json[4], true) + XCTAssertTrue(json[0] == false) + XCTAssertTrue(json[4] == true) } func testArrayAllString() { - var json:JSON = JSON.fromRaw(["aoo","bpp","zoo"] as NSArray)! - XCTAssertEqual(json, ["aoo","bpp","zoo"]) - XCTAssertEqual(json[0], "aoo") - XCTAssertEqual(json[1], "bpp") - XCTAssertEqual(json[2], "zoo") + var json:JSON = JSON(rawValue: ["aoo","bpp","zoo"] as NSArray)! + XCTAssertTrue(json == ["aoo","bpp","zoo"]) + XCTAssertTrue(json[0] == "aoo") + XCTAssertTrue(json[1] == "bpp") + XCTAssertTrue(json[2] == "zoo") json[1] = "update" - XCTAssertEqual(json[0], "aoo") - XCTAssertEqual(json[1], "update") - XCTAssertEqual(json[2], "zoo") + XCTAssertTrue(json[0] == "aoo") + XCTAssertTrue(json[1] == "update") + XCTAssertTrue(json[2] == "zoo") } func testArrayWithNull() { - var json:JSON = JSON.fromRaw(["aoo","bpp", NSNull() ,"zoo"] as NSArray)! - XCTAssertEqual(json[0], "aoo") - XCTAssertEqual(json[1], "bpp") + var json:JSON = JSON(rawValue: ["aoo","bpp", NSNull() ,"zoo"] as NSArray)! + XCTAssertTrue(json[0] == "aoo") + XCTAssertTrue(json[1] == "bpp") XCTAssertNil(json[2].string) XCTAssertNotNil(json[2].null) - XCTAssertEqual(json[3], "zoo") + XCTAssertTrue(json[3] == "zoo") json[2] = "update" json[3] = JSON(NSNull()) - XCTAssertEqual(json[0], "aoo") - XCTAssertEqual(json[1], "bpp") - XCTAssertEqual(json[2], "update") + XCTAssertTrue(json[0] == "aoo") + XCTAssertTrue(json[1] == "bpp") + XCTAssertTrue(json[2] == "update") XCTAssertNil(json[3].string) XCTAssertNotNil(json[3].null) } func testArrayAllDictionary() { var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] - XCTAssertEqual(json[0], ["1":1, "2":2]) + XCTAssertTrue(json[0] == ["1":1, "2":2]) XCTAssertEqual(json[1].dictionary!, ["a":"A", "b":"B"]) XCTAssertEqual(json[2], JSON(["null":NSNull()])) - XCTAssertEqual(json[0]["1"], 1) - XCTAssertEqual(json[0]["2"], 2) - XCTAssertEqual(json[1]["a"], JSON.fromRaw("A")!) + XCTAssertTrue(json[0]["1"] == 1) + XCTAssertTrue(json[0]["2"] == 2) + XCTAssertEqual(json[1]["a"], JSON(rawValue: "A")!) XCTAssertEqual(json[1]["b"], JSON("B")) XCTAssertNotNil(json[2]["null"].null) } @@ -108,65 +108,65 @@ class SubscriptTests: XCTestCase { func testDictionaryAllNumber() { var json:JSON = ["double":1.11111, "int":987654321] XCTAssertEqual(json["double"].double!, 1.11111) - XCTAssertEqual(json["int"], 987654321) + XCTAssertTrue(json["int"] == 987654321) json["double"] = 2.2222 json["int"] = 123456789 json["add"] = 7890 - XCTAssertEqual(json["double"], 2.2222) + XCTAssertTrue(json["double"] == 2.2222) XCTAssertEqual(json["int"].doubleValue, 123456789.0) XCTAssertEqual(json["add"].intValue, 7890) } func testDictionaryAllBool() { var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] - XCTAssertEqual(json["t"], true) - XCTAssertEqual(json["f"], false) - XCTAssertEqual(json["false"], false) - XCTAssertEqual(json["tr"], true) - XCTAssertEqual(json["true"], true) + XCTAssertTrue(json["t"] == true) + XCTAssertTrue(json["f"] == false) + XCTAssertTrue(json["false"] == false) + XCTAssertTrue(json["tr"] == true) + XCTAssertTrue(json["true"] == true) json["f"] = true json["tr"] = false - XCTAssertEqual(json["f"], true) - XCTAssertEqual(json["tr"], JSON(false)) + XCTAssertTrue(json["f"] == true) + XCTAssertTrue(json["tr"] == JSON(false)) } func testDictionaryAllString() { - var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! - XCTAssertEqual(json["a"], "aoo") + var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! + XCTAssertTrue(json["a"] == "aoo") XCTAssertEqual(json["bb"], JSON("bpp")) - XCTAssertEqual(json["z"], "zoo") + XCTAssertTrue(json["z"] == "zoo") json["bb"] = "update" - XCTAssertEqual(json["a"], "aoo") - XCTAssertEqual(json["bb"], "update") - XCTAssertEqual(json["z"], "zoo") + XCTAssertTrue(json["a"] == "aoo") + XCTAssertTrue(json["bb"] == "update") + XCTAssertTrue(json["z"] == "zoo") } func testDictionaryWithNull() { - var json:JSON = JSON.fromRaw(["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! - XCTAssertEqual(json["a"], "aoo") + var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! + XCTAssertTrue(json["a"] == "aoo") XCTAssertEqual(json["bb"], JSON("bpp")) XCTAssertEqual(json["null"], JSON(NSNull())) - XCTAssertEqual(json["z"], "zoo") + XCTAssertTrue(json["z"] == "zoo") json["null"] = "update" - XCTAssertEqual(json["a"], "aoo") - XCTAssertEqual(json["null"], "update") - XCTAssertEqual(json["z"], "zoo") + XCTAssertTrue(json["a"] == "aoo") + XCTAssertTrue(json["null"] == "update") + XCTAssertTrue(json["z"] == "zoo") } func testDictionaryAllArray() { //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) - XCTAssertEqual(json[0], [1,2.123456,123456789]) + XCTAssertTrue(json[0] == [1,2.123456,123456789]) XCTAssertEqual(json[0][1].double!, 2.123456) - XCTAssertEqual(json[0][2], 123456789) - XCTAssertEqual(json[1][0], "aa") - XCTAssertEqual(json[1], ["aa","bbb","cccc"]) - XCTAssertEqual(json[2][0], true) - XCTAssertEqual(json[2][1], "766") + XCTAssertTrue(json[0][2] == 123456789) + XCTAssertTrue(json[1][0] == "aa") + XCTAssertTrue(json[1] == ["aa","bbb","cccc"]) + XCTAssertTrue(json[2][0] == true) + XCTAssertTrue(json[2][1] == "766") XCTAssertEqual(json[2][2], JSON(NSNull())) XCTAssertEqual(json[2][3], JSON(655231.9823)) } @@ -192,7 +192,7 @@ class SubscriptTests: XCTestCase { } func testErrorNotExist() { - let json = ["name":"NAME", "age":15] + let json:JSON = ["name":"NAME", "age":15] XCTAssertEqual(json["Type"], JSON.nullJSON) XCTAssertEqual(json["Type"].error!.code, ErrorNotExist) XCTAssertEqual(json["Type"][1].error!.code, ErrorNotExist) From ee47ed717c515c60baf8e7065e44079e11559f98 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 9 Oct 2014 17:44:15 +0800 Subject: [PATCH 031/470] Add launch image for example project --- Example.xcodeproj/project.pbxproj | 2 + .../LaunchImage.launchimage/Contents.json | 52 ++++++++++++++++++ .../LaunchImage.launchimage/Default@2x.png | Bin 0 -> 196 bytes 3 files changed, 54 insertions(+) create mode 100644 Example/Images.xcassets/LaunchImage.launchimage/Contents.json create mode 100644 Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index 20596a92..dda2844e 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -343,6 +343,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -353,6 +354,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Example/Images.xcassets/LaunchImage.launchimage/Contents.json b/Example/Images.xcassets/LaunchImage.launchimage/Contents.json new file mode 100644 index 00000000..d8c7ca1b --- /dev/null +++ b/Example/Images.xcassets/LaunchImage.launchimage/Contents.json @@ -0,0 +1,52 @@ +{ + "images" : [ + { + "orientation" : "portrait", + "idiom" : "iphone", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "extent" : "full-screen", + "idiom" : "iphone", + "subtype" : "retina4", + "filename" : "Default@2x.png", + "minimum-system-version" : "7.0", + "orientation" : "portrait", + "scale" : "2x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "1x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "1x" + }, + { + "orientation" : "portrait", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + }, + { + "orientation" : "landscape", + "idiom" : "ipad", + "extent" : "full-screen", + "minimum-system-version" : "7.0", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png b/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..3604134f9f14c4be47447be00b6e5dc59612b443 GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sU@2f^28uX1mOBF}<^Z1%*Z=?jFFzuE0?4iL zba4!+xb@~>Bap+;u;A}X@s&&zopr019Iv(f|Me literal 0 HcmV?d00001 From 1a5d12bc1388b61912e6b80644f0fccea37e28a5 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 9 Oct 2014 18:16:52 +0800 Subject: [PATCH 032/470] Update for iOS 7 --- Example/ViewController.swift | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index bd59a56e..9d578eab 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -67,7 +67,16 @@ class ViewController: UITableViewController { // MARK: - Navigation override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { - if let nextController = segue.destinationViewController.topViewController as? ViewController { + + var object: AnyObject + switch UIDevice.currentDevice().systemVersion.compare("8.0.0", options: NSStringCompareOptions.NumericSearch) { + case .OrderedSame, .OrderedDescending: + object = segue.destinationViewController.topViewController + case .OrderedAscending: + object = segue.destinationViewController + } + + if let nextController = object as? ViewController { if let indexPath = self.tableView.indexPathForSelectedRow() { var row = indexPath.row @@ -85,6 +94,7 @@ class ViewController: UITableViewController { print("") } nextController.json = nextJson + print(nextJson) } } } From dc3ae4bb5b58c3e65859c2f1880220ea33625b41 Mon Sep 17 00:00:00 2001 From: Blair McArthur Date: Fri, 10 Oct 2014 08:51:17 +1300 Subject: [PATCH 033/470] Making SourceKit not freak out about self.object.count being called --- Source/SwiftyJSON.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index acc301aa..7df0ec2c 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -144,8 +144,10 @@ extension JSON: SequenceType{ public var count: Int { get { switch self.type { - case .Array, .Dictionary: - return self.object.count + case .Array: + return self.arrayValue.count + case .Dictionary: + return self.dictionaryValue.count default: return 0 } @@ -478,8 +480,10 @@ extension JSON: BooleanType { switch self.type { case .Bool, .Number, .String: return self.object.boolValue - case .Array, .Dictionary: - return self.object.count > 0 + case .Array: + return self.arrayValue.count > 0 + case .Dictionary: + return self.dictionaryValue.count > 0 case .Null: return false default: From 1dfbd5392c8bede9051360ebc5de7072a15254d7 Mon Sep 17 00:00:00 2001 From: tangplin Date: Sat, 11 Oct 2014 15:55:39 +0800 Subject: [PATCH 034/470] Add subscript which parameter is array or array literal. - sub = json["list",0,"name"] - let path: [SubscriptType]= ["list",0,"name"]; sub = json[path] - json["list",0,"name"] = "Jack" - let path: [SubscriptType] = ["list",0,"name"]; json[path] = "Jack" --- Source/SwiftyJSON.swift | 79 +++++++++++++++++++++++++++++++++++--- Tests/SubscriptTests.swift | 38 ++++++++++++++++++ 2 files changed, 111 insertions(+), 6 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 491312d3..0981ebbd 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -185,19 +185,25 @@ extension JSON: SequenceType{ } } +public protocol SubscriptType {} +extension Int: SubscriptType {} +extension String: SubscriptType {} + +typealias Filter = JSON -> JSON + // MARK: - Subscript extension JSON { /** If self is .Sequence return the array[index]'s json else return .Null with error */ - public subscript(idx: Int) -> JSON { + private subscript(#index: Int) -> JSON { get { var returnJSON = JSON.nullJSON if self.type == .Array { let array_ = self.object as Array - if array_.count > idx { - returnJSON = JSON(array_[idx]) + if array_.count > index { + returnJSON = JSON(array_[index]) } else { returnJSON._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) } @@ -209,8 +215,8 @@ extension JSON { set { if self.type == .Array { var array_ = self.object as Array - if array_.count > idx { - array_[idx] = newValue.object + if array_.count > index { + array_[index] = newValue.object self.object = array_ } } @@ -220,7 +226,7 @@ extension JSON { /** If self is .Sequence return the dictionary[key]'s JSON else return .Null with error */ - public subscript(key: String) -> JSON { + private subscript(#key: String) -> JSON { get { var returnJSON = JSON.nullJSON if self.type == .Dictionary { @@ -242,6 +248,67 @@ extension JSON { } } } + + private subscript(#sub: SubscriptType) -> JSON { + get { + switch sub { + case let key as String: return self[key:key] + case let index as Int: return self[index:index] + default:return JSON.nullJSON + } + } + set { + switch sub { + case let key as String: self[key:key] = newValue + case let index as Int: self[index:index] = newValue + default:0 + } + } + } + + public subscript(path: [SubscriptType]) -> JSON { + get { + if path.count == 0 { + return JSON.nullJSON + } + + var next = self + for sub in path { + next = next[sub:sub] + } + return next + } + set { + + switch path.count { + case 0: return + case 1: self[sub:path[0]] = newValue + default: + var last = newValue + var newPath = path + newPath.removeLast() + for sub in path.reverse() { + var lastLast = self[newPath] + lastLast[sub:sub] = last + last = lastLast + if newPath.count <= 1 { + break + } + newPath.removeLast() + } + self[sub:newPath[0]] = last + } + } + } + + public subscript(path: SubscriptType...) -> JSON { + get { + return self[path] + } + set { + self[path] = newValue + } + } } //MARK:- LiteralConvertible diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 6d3268b1..ce330317 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -103,6 +103,7 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[1]["a"], JSON(rawValue: "A")!) XCTAssertEqual(json[1]["b"], JSON("B")) XCTAssertNotNil(json[2]["null"].null) + XCTAssertNotNil(json[2,"null"].null) } func testDictionaryAllNumber() { @@ -167,8 +168,12 @@ class SubscriptTests: XCTestCase { XCTAssertTrue(json[1] == ["aa","bbb","cccc"]) XCTAssertTrue(json[2][0] == true) XCTAssertTrue(json[2][1] == "766") + XCTAssertTrue(json[[2,1]] == "766") XCTAssertEqual(json[2][2], JSON(NSNull())) + XCTAssertEqual(json[2,2], JSON(NSNull())) XCTAssertEqual(json[2][3], JSON(655231.9823)) + XCTAssertEqual(json[2,3], JSON(655231.9823)) + XCTAssertEqual(json[[2,3]], JSON(655231.9823)) } func testOutOfBounds() { @@ -177,6 +182,8 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[9][8], JSON.nullJSON) XCTAssertEqual(json[8][7].error!.code, ErrorIndexOutOfBounds) + XCTAssertEqual(json[8,7].error!.code, ErrorIndexOutOfBounds) + XCTAssertEqual(json[999].error!.code, ErrorIndexOutOfBounds) } func testErrorWrongType() { @@ -189,6 +196,9 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[0]["name"].error!.code, ErrorWrongType) XCTAssertEqual(json["type"]["name"].error!.code, ErrorWrongType) XCTAssertEqual(json["name"][99].error!.code, ErrorWrongType) + XCTAssertEqual(json[1,"Value"].error!.code, ErrorWrongType) + XCTAssertEqual(json[1, 2,"Value"].error!.code, ErrorWrongType) + XCTAssertEqual(json[[1, 2,"Value"]].error!.code, ErrorWrongType) } func testErrorNotExist() { @@ -196,6 +206,34 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json["Type"], JSON.nullJSON) XCTAssertEqual(json["Type"].error!.code, ErrorNotExist) XCTAssertEqual(json["Type"][1].error!.code, ErrorNotExist) + XCTAssertEqual(json["Type", 1].error!.code, ErrorNotExist) XCTAssertEqual(json["Type"]["Value"].error!.code, ErrorNotExist) + XCTAssertEqual(json["Type","Value"].error!.code, ErrorNotExist) + } + + func testMultilevelGetter() { + let json:JSON = [[[[["one":1]]]]] + XCTAssertEqual(json[[0, 0, 0, 0, "one"]].int!, 1) + XCTAssertEqual(json[0, 0, 0, 0, "one"].int!, 1) + XCTAssertEqual(json[0][0][0][0]["one"].int!, 1) + } + + func testMultilevelSetter() { + var json:JSON = [[[[["num":1]]]]] + json[0, 0, 0, 0, "num"] = 2 + XCTAssertEqual(json[[0, 0, 0, 0, "num"]].intValue, 2) + json[0, 0, 0, 0, "num"] = nil + XCTAssertEqual(json[0, 0, 0, 0, "num"].null!, NSNull()) + json[0, 0, 0, 0, "num"] = 100.009 + XCTAssertEqual(json[0][0][0][0]["num"].doubleValue, 100.009) + json[[0, 0, 0, 0]] = ["name":"Jack"] + XCTAssertEqual(json[0,0,0,0,"name"].stringValue, "Jack") + XCTAssertEqual(json[0][0][0][0]["name"].stringValue, "Jack") + XCTAssertEqual(json[[0,0,0,0,"name"]].stringValue, "Jack") + json[[0,0,0,0,"name"]].string = "Mike" + XCTAssertEqual(json[0,0,0,0,"name"].stringValue, "Mike") + let path:[SubscriptType] = [0,0,0,0,"name"] + json[path].string = "Jim" + XCTAssertEqual(json[path].stringValue, "Jim") } } From 59c330959be2d418b3301f02e489fc5bf3f4bc4e Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 13 Oct 2014 12:34:37 +0800 Subject: [PATCH 035/470] Fix: 32bit test failures #71 --- Source/SwiftyJSON.swift | 17 +++++++++-------- Tests/BaseTests.swift | 8 +++++--- Tests/NumberTests.swift | 17 +++++++++++++---- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 0981ebbd..5668216d 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1052,18 +1052,19 @@ public func <(lhs: JSON, rhs: JSON) -> Bool { } } +private let trueNumber = NSNumber(bool: true) +private let falseNumber = NSNumber(bool: false) +private let trueObjCType = String.fromCString(trueNumber.objCType) +private let falseObjCType = String.fromCString(falseNumber.objCType) + // MARK: - NSNumber: Comparable extension NSNumber: Comparable { var isBool:Bool { get { - switch String.fromCString(self.objCType)! { - case "c", "C": - if self.compare(NSNumber(bool: true)) == NSComparisonResult.OrderedSame || self.compare(NSNumber(bool: false)) == NSComparisonResult.OrderedSame { - return true - } else { - return false - } - default: + let objCType = String.fromCString(self.objCType) + if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ + return true + } else { return false } } diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index f2d557dd..5e537fd8 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -96,7 +96,7 @@ class BaseTests: XCTestCase { let tweets_1_coordinates_coordinates = tweets_1_coordinates["coordinates"] let tweets_1_coordinates_coordinates_point_0_double = tweets_1_coordinates_coordinates[0].double let tweets_1_coordinates_coordinates_point_1_float = tweets_1_coordinates_coordinates[1].float - let new_tweets_1_coordinates_coordinates = JSON([-122.25831,37.871609]) + let new_tweets_1_coordinates_coordinates = JSON([-122.25831,37.871609] as NSArray) XCTAssertEqual(tweets_1_coordinates_coordinates, new_tweets_1_coordinates_coordinates) XCTAssertEqual(tweets_1_coordinates_coordinates_point_0_double!, -122.25831) XCTAssertTrue(tweets_1_coordinates_coordinates_point_1_float! == 37.871609) @@ -186,9 +186,11 @@ class BaseTests: XCTestCase { XCTAssertEqual(JSON(1).description,"1") XCTAssertEqual(JSON(22).description,"22") + #if (arch(x86_64) || arch(arm64)) + XCTAssertEqual(JSON(9.22337203685478E18).description,"9.22337203685478e+18") + #elseif (arch(i386) || arch(arm)) XCTAssertEqual(JSON(2147483647).description,"2147483647") - XCTAssertEqual(JSON(2147483648).description,"2147483648") - + #endif XCTAssertEqual(JSON(-1).description,"-1") XCTAssertEqual(JSON(-934834834).description,"-934834834") XCTAssertEqual(JSON(-2147483648).description,"-2147483648") diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 89ed546f..59d8780f 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -174,22 +174,31 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, nm128) XCTAssertEqual(json.stringValue, "-128") - let n0 = NSNumber(char: 0) + let n0 = NSNumber(char: 0 as Int8) json.int8Value = n0.charValue XCTAssertTrue(json.int8! == n0.charValue) XCTAssertTrue(json.int8Value == n0.charValue) println(json.number) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) - XCTAssertEqual(json.stringValue, "false") + #if (arch(x86_64) || arch(arm64)) + XCTAssertEqual(json.stringValue, "false") + #elseif (arch(i386) || arch(arm)) + XCTAssertEqual(json.stringValue, "0") + #endif - let n1 = NSNumber(char: 1) + + let n1 = NSNumber(char: 1 as Int8) json.int8Value = n1.charValue XCTAssertTrue(json.int8! == n1.charValue) XCTAssertTrue(json.int8Value == n1.charValue) XCTAssertTrue(json.number! == n1) XCTAssertEqual(json.numberValue, n1) - XCTAssertEqual(json.stringValue, "true") + #if (arch(x86_64) || arch(arm64)) + XCTAssertEqual(json.stringValue, "true") + #elseif (arch(i386) || arch(arm)) + XCTAssertEqual(json.stringValue, "1") + #endif } func testUInt8() { From 24771789ddaca183114e22940fa8be6f9c2891f0 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 13 Oct 2014 22:27:40 +0800 Subject: [PATCH 036/470] Update getter for [JSON] and [String:JSON] by map --- Source/SwiftyJSON.swift | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5668216d..251cee3f 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -437,19 +437,15 @@ extension JSON: Printable, DebugPrintable { // MARK: - Array extension JSON { - + //Optional Array public var array: Array? { get { if self.type == .Array { - let array_ = self.object as Array - var returnArray_ = Array() - for subObject_ in array_ { - returnArray_.append(JSON(subObject_)) - } - return returnArray_ + return map(self.object as Array){ JSON($0) } + } else { + return nil } - return nil } } @@ -483,17 +479,20 @@ extension JSON { // MARK: - Dictionary extension JSON { + private func _map(source: [Key: Value], transform: Value -> NewValue) -> [Key: NewValue] { + var result = [Key: NewValue](minimumCapacity:source.count) + for (key,value) in source { + result[key] = transform(value) + } + return result + } + //Optional Dictionary public var dictionary: Dictionary? { get { - switch self.type { - case .Dictionary: - var jsonDictionary_ = Dictionary() - for (key_, value_) in self.object as Dictionary { - jsonDictionary_[key_] = JSON( value_) - } - return jsonDictionary_ - default: + if self.type == .Dictionary { + return _map(self.object as Dictionary){ JSON($0) } + } else { return nil } } From 61b43146625c0945d8159bcd72ad4db430ec28d8 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 13 Oct 2014 22:28:28 +0800 Subject: [PATCH 037/470] Add performance tests --- SwiftyJSON.xcodeproj/project.pbxproj | 4 ++ Tests/BaseTests.swift | 27 --------- Tests/PerformanceTests.swift | 88 ++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 27 deletions(-) create mode 100644 Tests/PerformanceTests.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 8b60bb0c..cf3f17d6 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; @@ -45,6 +46,7 @@ A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; + A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = ""; }; A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = ""; }; A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberTests.swift; sourceTree = ""; }; @@ -114,6 +116,7 @@ isa = PBXGroup; children = ( A885D1DA19CFCFF0002FD4C3 /* Tests.json */, + A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */, A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */, A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */, A819C4A019E37FC600ADCC3D /* PrintableTests.swift */, @@ -256,6 +259,7 @@ files = ( A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */, A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */, + A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */, A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 5e537fd8..94f3e3c8 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -265,32 +265,5 @@ class BaseTests: XCTestCase { XCTAssertEqual(NSNumber(bool: true), NSNumber(bool:true)) } - func testInitPerformance() { - - self.measureBlock() { - var t:Int = 0 - while (true) { - if t == 100 { - break - } - JSON(data:self.testData) - t++ - } - } - } - - func testObjectMethodPerformance() { - var json = JSON(data:self.testData) - self.measureBlock() { - var t:Int = 0 - while (true) { - if t == 100 { - break - } - let object:AnyObject? = json.object - t++ - } - } - } } \ No newline at end of file diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift new file mode 100644 index 00000000..2bfd80a0 --- /dev/null +++ b/Tests/PerformanceTests.swift @@ -0,0 +1,88 @@ +// PerformanceTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class PerformanceTests: XCTestCase { + + var testData: NSData! + + override func setUp() { + super.setUp() + + if let file = NSBundle(forClass:PerformanceTests.self).pathForResource("Tests", ofType: "json") { + self.testData = NSData(contentsOfFile: file) + } else { + XCTFail("Can't find the test JSON file") + } + } + + override func tearDown() { + // Put teardown code here. This method is called after the invocation of each test method in the class. + super.tearDown() + } + + func testInitPerformance() { + self.measureBlock() { + for _ in 1...100 { + let json = JSON(data:self.testData) + XCTAssertTrue(json != JSON.nullJSON) + } + } + } + + func testObjectMethodPerformance() { + var json = JSON(data:self.testData) + self.measureBlock() { + for _ in 1...100 { + let object:AnyObject? = json.object + XCTAssertTrue(object != nil) + } + } + } + + func testArrayMethodPerformance() { + let json = JSON(data:self.testData) + self.measureBlock() { + for _ in 1...100 { + autoreleasepool{ + let array = json.array + XCTAssertTrue(array?.count > 0) + } + } + } + } + + func testDictionaryMethodPerformance() { + let json = JSON(data:testData)[0] + self.measureBlock() { + for _ in 1...100 { + autoreleasepool{ + var dictionary = json.dictionary + XCTAssertTrue(dictionary?.count > 0) + } + } + } + } +} From 093256d216a60eb66d0c602091f88a73fcdd72d0 Mon Sep 17 00:00:00 2001 From: tangplin Date: Tue, 14 Oct 2014 00:18:35 +0800 Subject: [PATCH 038/470] Update array subscript: If index is minus, get the null json with out of bounds error. --- Source/SwiftyJSON.swift | 48 +++++++++++++++++++++----------------- Tests/SubscriptTests.swift | 1 + 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 01ffcffa..a58927bb 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -201,18 +201,22 @@ extension JSON { */ private subscript(#index: Int) -> JSON { get { - var returnJSON = JSON.nullJSON - if self.type == .Array { - let array_ = self.object as Array - if array_.count > index { - returnJSON = JSON(array_[index]) - } else { - returnJSON._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) - } - } else { - returnJSON._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) + + if self.type != .Array { + var errorResult_ = JSON.nullJSON + errorResult_._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) + return errorResult_ } - return returnJSON + + let array_ = self.object as [AnyObject] + + if index >= 0 && index < array_.count { + return JSON(array_[index]) + } + + var errorResult_ = JSON.nullJSON + errorResult_._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) + return errorResult_ } set { if self.type == .Array { @@ -253,17 +257,17 @@ extension JSON { private subscript(#sub: SubscriptType) -> JSON { get { - switch sub { - case let key as String: return self[key:key] - case let index as Int: return self[index:index] - default:return JSON.nullJSON + if sub is String { + return self[key:sub as String] + } else { + return self[index:sub as Int] } } set { - switch sub { - case let key as String: self[key:key] = newValue - case let index as Int: self[index:index] = newValue - default:0 + if sub is String { + self[key:sub as String] = newValue + } else { + self[index:sub as Int] = newValue } } } @@ -290,9 +294,9 @@ extension JSON { var newPath = path newPath.removeLast() for sub in path.reverse() { - var lastLast = self[newPath] - lastLast[sub:sub] = last - last = lastLast + var previousLast = self[newPath] + previousLast[sub:sub] = last + last = previousLast if newPath.count <= 1 { break } diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index ce330317..e9b84bad 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -179,6 +179,7 @@ class SubscriptTests: XCTestCase { func testOutOfBounds() { let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertEqual(json[9], JSON.nullJSON) + XCTAssertEqual(json[-2].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[9][8], JSON.nullJSON) XCTAssertEqual(json[8][7].error!.code, ErrorIndexOutOfBounds) From 5ef814e43b0c4400ce603ba049fc3764baa97620 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 16 Oct 2014 00:32:25 +0800 Subject: [PATCH 039/470] Add methods to get raw NSData and String. Fix #70 --- Source/SwiftyJSON.swift | 12 +++++++ SwiftyJSON.xcodeproj/project.pbxproj | 4 +++ Tests/PerformanceTests.swift | 13 +++++++ Tests/RawTests.swift | 54 ++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 Tests/RawTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a58927bb..36323acf 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -393,6 +393,18 @@ extension JSON: RawRepresentable { public var rawValue: AnyObject { return self.object } + + public func rawData(options opt: NSJSONWritingOptions = .PrettyPrinted, error: NSErrorPointer = nil) -> NSData? { + return NSJSONSerialization.dataWithJSONObject(self.object, options: opt, error:error) + } + + public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted, error: NSErrorPointer = nil) -> String? { + if let data = self.rawData(options: opt, error:error) { + return NSString(data: data, encoding: encoding) + } else { + return nil + } + } } //MARK: - Printable, DebugPrintable diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index cf3f17d6..c41df008 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + A863BE2819EED46F0092A41F /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; A87080E619E3DF7800CDE086 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; @@ -46,6 +47,7 @@ A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; + A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawTests.swift; sourceTree = ""; }; A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = ""; }; A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = ""; }; @@ -126,6 +128,7 @@ A87080E519E3DF7800CDE086 /* ComparableTests.swift */, A87080E919E43C0700CDE086 /* StringTests.swift */, A87080E719E439DA00CDE086 /* NumberTests.swift */, + A863BE2719EED46F0092A41F /* RawTests.swift */, A8B66C8B19E51D6500540692 /* DictionaryTests.swift */, A8B66C8D19E52F4200540692 /* ArrayTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, @@ -262,6 +265,7 @@ A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */, A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, + A863BE2819EED46F0092A41F /* RawTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */, diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index 2bfd80a0..46fc6a1e 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -85,4 +85,17 @@ class PerformanceTests: XCTestCase { } } } + + func testRawStringMethodPerformance() { + let json = JSON(data:testData) + self.measureBlock() { + for _ in 1...100 { + autoreleasepool{ + var string = json.rawString() + XCTAssertTrue(string != nil) + } + } + } + } + } diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift new file mode 100644 index 00000000..ba31b9b6 --- /dev/null +++ b/Tests/RawTests.swift @@ -0,0 +1,54 @@ +// RawTests.swift +// +// Copyright (c) 2014 Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import UIKit +import XCTest +import SwiftyJSON + +class RawTests: XCTestCase { + + func testArray() { + let json:JSON = [1, "2", 3.12, NSNull(), true, ["name": "Jack"]] + let data = json.rawData() + let string = json.rawString() + XCTAssertTrue (data != nil) + XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + println(string!) + } + + func testDictionary() { + let json:JSON = ["number":111111.23456789, "name":"Jack", "list":[1,2,3,4], "bool":false, "null":NSNull()] + let data = json.rawData() + let string = json.rawString() + XCTAssertTrue (data != nil) + XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + println(string!) + } + + func testPerformanceExample() { + // This is an example of a performance test case. + self.measureBlock() { + // Put the code you want to measure the time of here. + } + } + +} From 4e7073050ca45e4b4704b14b453cc4dd7de72db1 Mon Sep 17 00:00:00 2001 From: MaddTheSane Date: Wed, 15 Oct 2014 11:57:54 -0600 Subject: [PATCH 040/470] Update SwiftyJSON.swift Why were the constants marked with an exclamation point? public let variables should already be defined. --- Source/SwiftyJSON.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 7df0ec2c..6397a91a 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -27,12 +27,12 @@ public typealias JSONValue = JSON //MARK: - Return Error //The SwiftyJSON's error domain -public let ErrorDomain: String! = "SwiftyJSONErrorDomain" +public let ErrorDomain = "SwiftyJSONErrorDomain" //The error code -public let ErrorUnsupportedType: Int! = 999 -public let ErrorIndexOutOfBounds: Int! = 900 -public let ErrorWrongType: Int! = 901 -public let ErrorNotExist: Int! = 500 +public let ErrorUnsupportedType = 999 +public let ErrorIndexOutOfBounds = 900 +public let ErrorWrongType = 901 +public let ErrorNotExist = 500 public enum Type :Int{ @@ -1218,4 +1218,4 @@ extension JSON { return self.numberValue.unsignedIntegerValue } } -} \ No newline at end of file +} From f1a832054653a990e69566ae77d34d2de3084b75 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 16 Oct 2014 11:30:44 +0800 Subject: [PATCH 041/470] Update README.md --- README.md | 100 ++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 706301c3..ee39bd93 100644 --- a/README.md +++ b/README.md @@ -23,38 +23,6 @@ But while dealing with things that naturally implicit about types such as JSON, Take the Twitter API for example: say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline) -```JSON - -[ - { - ...... - "text": "just another test", - ...... - "user": { - "name": "OAuth Dancer", - "favourites_count": 7, - "entities": { - "url": { - "urls": [ - { - "expanded_url": null, - "url": "http://bit.ly/oauth-dancer", - "indices": [ - 0, - 26 - ], - "display_url": null - } - ] - } - ...... - }, - "in_reply_to_screen_name": null, - }, - ......] - -``` - The code would look like this: ```swift @@ -138,22 +106,43 @@ let json = JSON(jsonObject) ####Subscript ```swift -let name = json[0]["name"].stringValue +//With a int from JSON supposed to an Array +let name = json[0].double +``` +```swift +//With a string from JSON supposed to an Dictionary +let name = json["name"].stringValue +``` +```swift +//With an array like path to the element +let path = [1,"list",2,"name"] +let name = json[path].string +//Just the same +let name = json[1]["like"][2]["name"].string +``` +```swift +//With a literal array to the element +let name = json[1,"list",2,"name"].string +//Just the same +let name = json[1]["like"][2]["name"].string +``` +```swift +//With a Hard Way +let name = json[[1,"list",2,"name"]].string ``` - ####Loop ```swift //If json is .Dictionary for (key: String, subJson: JSON) in json { -//Do something you want + //Do something you want } ``` +*The first element always String even the JSON's object is Array* ```swift - //If json is .Array //The `index` is 0.. = json["user"].dictionaryValue ####Setter ```swift +json["name"] = JSON("new-name") +json[0] = JSON(1) +``` +```swift json["id"].int = 1234567890 json["coordinate"].double = 8766.766 json["name"].string = "Jack" json.array = [1,2,3,4] json.dictionary = ["name":"Jack", "age":25] ``` + ####Raw object ```swift let jsonObject: AnyObject = json.object @@ -326,7 +316,13 @@ json["name"] = "Mike" json["age"] = "25" //It's OK to set String json["address"] = "L.A." // Add the "address": "L.A." in json ``` - +```swift +//Mix +var json:JSON = ["name":"Jack", "age": 25, "list":["a","b","c",["what":"this"]]] +json["list"][3]["what"] = "that" +json["list",3,"what"] = "that" +let path = ["list",3,"what"] +json[path] = "that" ##Work with Alamofire To use Alamofire and SwiftyJSON, try [Alamofire-SwiftyJSON](https://github.com/SwiftyJSON/Alamofire-SwiftyJSON). From 857ccc021b56b9e030e71cf1a52bf9267b7b9473 Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 16 Oct 2014 11:39:10 +0800 Subject: [PATCH 042/470] Update README.md --- README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ee39bd93..309a2f43 100644 --- a/README.md +++ b/README.md @@ -262,13 +262,18 @@ json.dictionary = ["name":"Jack", "age":25] let jsonObject: AnyObject = json.object ``` ```swift -if let jsonObject: AnyObject = json.toRaw +if let jsonObject: AnyObject = json.rawValue ``` ```swift -if let json = JSON.fromRaw(object) { - //object can be converted to JSON -} else { - //object can not be converted to JSON +//convert the JSON to raw NSData +if let data = json.rawData() { + //Do something you want +} +``` +```swift +//convert the JSON to raw String +if let string = json.rawString() { + //Do something you want } ``` ####Literal convertibles @@ -317,12 +322,13 @@ json["age"] = "25" //It's OK to set String json["address"] = "L.A." // Add the "address": "L.A." in json ``` ```swift -//Mix +//Array & Dictionary var json:JSON = ["name":"Jack", "age": 25, "list":["a","b","c",["what":"this"]]] json["list"][3]["what"] = "that" json["list",3,"what"] = "that" let path = ["list",3,"what"] json[path] = "that" +``` ##Work with Alamofire To use Alamofire and SwiftyJSON, try [Alamofire-SwiftyJSON](https://github.com/SwiftyJSON/Alamofire-SwiftyJSON). From d45c0419f9d62a05ea86e21266952c09242a087d Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sun, 19 Oct 2014 10:32:12 +0800 Subject: [PATCH 043/470] Update document. --- Source/SwiftyJSON.swift | 181 +++++++++++++++++++++++++--------------- 1 file changed, 115 insertions(+), 66 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 36323acf..82d35737 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -22,18 +22,24 @@ import Foundation -@availability(*, unavailable, renamed="JSON") -public typealias JSONValue = JSON +// MARK: - Error -//MARK: - Return Error -//The SwiftyJSON's error domain +///Error domain public let ErrorDomain: String! = "SwiftyJSONErrorDomain" -//The error code + +///Error code public let ErrorUnsupportedType: Int! = 999 public let ErrorIndexOutOfBounds: Int! = 900 public let ErrorWrongType: Int! = 901 public let ErrorNotExist: Int! = 500 +// MARK: - JSON Type + +/** +JSON's type definitions. + +See http://tools.ietf.org/html/rfc7231#section-4.3 +*/ public enum Type :Int{ case Number @@ -45,18 +51,46 @@ public enum Type :Int{ case Unknow } -//MARK:- Base -//http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf +// MARK: - JSON Base + public struct JSON { + + /** + Creates a JSON using the data. - public var type: Type { - get { - return _type - } - set { - _type = newValue + :param: data The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary + :param: opt The JSON serialization reading options. `.AllowFragments` by default. + :param: error error The NSErrorPointer used to return the error. `nil` by default. + + :returns: The created JSON + */ + public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { + if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error) { + self.init(object) + } else { + self.init(NSNull()) } } + + /** + Creates a JSON using the object. + + :param: object The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. + + :returns: The created JSON + */ + public init(_ object: AnyObject) { + self.object = object + } + + /// Private object + private var _object: AnyObject = NSNull() + /// Private type + private var _type: Type = .Null + /// prviate error + private var _error: NSError? + + /// Object in JSON public var object: AnyObject { get { return _object @@ -86,47 +120,21 @@ public struct JSON { } } - public var error: NSError? { get { return self._error } } - public static var nullJSON: JSON { get { return JSON(NSNull()) } } + /// json type + public var type: Type { get { return _type } } - /** - :param: data The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - :param: options The JSON serialization reading options. `.AllowFragments` by default. - :param: error The NSErrorPointer used to return the error. `nil` by default. - */ - public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { - if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error) { - self.init(object) - } else { - self.init(NSNull()) - } - } - - /** - :param: object The object must have the following properties: - - All objects are NSString, NSNumber, NSArray, NSDictionary, or NSNull - - All dictionary keys are NSStrings - - NSNumbers are not NaN or infinity - In swift - - String as NSString - - Bool, Int, Float, Double... as NSNumber - - Array as NSArray - - Dictionary as NSDictionary with NSString keys - */ - public init(_ object: AnyObject) { - self.object = object - } + /// Error in JSON + public var error: NSError? { get { return self._error } } - private var _object: AnyObject = NSNull() - private var _type: Type = .Null - private var _error: NSError? + /// The static null json + public static var nullJSON: JSON { get { return JSON(NSNull()) } } } // MARK: - SequenceType extension JSON: SequenceType{ - /// `true` if and only if self's type is `.Array` or `.Dictionary` and it is empty + /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. var isEmpty: Bool { get { switch self.type { @@ -140,7 +148,7 @@ extension JSON: SequenceType{ } } - /// `count` value if self's type is `.Array` or `.Dictionary` otherwise is `0` + /// If `type` is `.Array` or `.Dictionary`, return `array.count` or `dictonary.count` otherwise return `0`. public var count: Int { get { switch self.type { @@ -153,9 +161,12 @@ extension JSON: SequenceType{ } } } - - /// - If self's type is .Array return GeneratorOf<(index, JSON(element))> otherwise return `nil` - /// - If self's type is .Dictionary return GeneratorOf<(index, JSON(element))> otherwise return `nil` + + /** + If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary, otherwise return a generator over empty. + + :returns: Return a *generator* over the elements of this *sequence*. + */ public func generate() -> GeneratorOf <(String, JSON)> { switch self.type { case .Array: @@ -187,18 +198,20 @@ extension JSON: SequenceType{ } } +// MARK: - Subscript + +/** +* To mark both String and Int can be used in subscript. +*/ public protocol SubscriptType {} + extension Int: SubscriptType {} -extension String: SubscriptType {} -typealias Filter = JSON -> JSON +extension String: SubscriptType {} -// MARK: - Subscript extension JSON { - /** - If self is .Sequence return the array[index]'s json else return .Null with error - */ + /// If `type` is `.Array`, return json which's object is `array[index]`, otherwise return null json with error. private subscript(#index: Int) -> JSON { get { @@ -229,9 +242,7 @@ extension JSON { } } - /** - If self is .Sequence return the dictionary[key]'s JSON else return .Null with error - */ + /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. private subscript(#key: String) -> JSON { get { var returnJSON = JSON.nullJSON @@ -255,6 +266,7 @@ extension JSON { } } + /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. private subscript(#sub: SubscriptType) -> JSON { get { if sub is String { @@ -272,6 +284,19 @@ extension JSON { } } + /** + Find a json in the complex data structuresby using the Int/String's array. + + :param: path The target json's path. Example: + + let json = JSON[data] + let path = [9,"list","person","name"] + let name = json[path] + + The same as: let name = json[9]["list"]["person"]["name"] + + :returns: Return a json found by the path or a null json with error + */ public subscript(path: [SubscriptType]) -> JSON { get { if path.count == 0 { @@ -307,6 +332,17 @@ extension JSON { } } + /** + Find a json in the complex data structuresby using the Int/String's array. + + :param: path The target json's path. Example: + + let name = json[9,"list","person","name"] + + The same as: let name = json[9]["list"]["person"]["name"] + + :returns: Return a json found by the path or a null json with error + */ public subscript(path: SubscriptType...) -> JSON { get { return self[path] @@ -317,7 +353,8 @@ extension JSON { } } -//MARK:- LiteralConvertible +// MARK: - LiteralConvertible + extension JSON: StringLiteralConvertible { public init(stringLiteral value: StringLiteralType) { @@ -379,7 +416,8 @@ extension JSON: NilLiteralConvertible { } } -//MARK:- RawRepresentable +// MARK: - Raw + extension JSON: RawRepresentable { public init?(rawValue: AnyObject) { @@ -407,7 +445,8 @@ extension JSON: RawRepresentable { } } -//MARK: - Printable, DebugPrintable +// MARK: - Printable, DebugPrintable + extension JSON: Printable, DebugPrintable { public var description: String { @@ -454,6 +493,7 @@ extension JSON: Printable, DebugPrintable { } // MARK: - Array + extension JSON { //Optional Array @@ -495,6 +535,7 @@ extension JSON { } // MARK: - Dictionary + extension JSON { private func _map(source: [Key: Value], transform: Value -> NewValue) -> [Key: NewValue] { @@ -543,7 +584,8 @@ extension JSON { } } -//MARK: - Bool +// MARK: - Bool + extension JSON: BooleanType { //Optional bool @@ -587,7 +629,8 @@ extension JSON: BooleanType { } } -//MARK: - String +// MARK: - String + extension JSON { //Optional string @@ -629,7 +672,7 @@ extension JSON { } } -//MARK: - Number +// MARK: - Number extension JSON { //Optional number @@ -716,7 +759,8 @@ extension JSON { } } -//MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 +// MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 + extension JSON { public var double: Double? { @@ -1077,6 +1121,7 @@ private let trueObjCType = String.fromCString(trueNumber.objCType) private let falseObjCType = String.fromCString(falseNumber.objCType) // MARK: - NSNumber: Comparable + extension NSNumber: Comparable { var isBool:Bool { get { @@ -1154,6 +1199,10 @@ public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { } //MARK:- Unavailable + +@availability(*, unavailable, renamed="JSON") +public typealias JSONValue = JSON + extension JSON { @availability(*, unavailable, message="use 'init(_ object:AnyObject)' instead") From 0916e7630172df741f967c6a37b4107bc3890d4c Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sun, 19 Oct 2014 10:34:43 +0800 Subject: [PATCH 044/470] If json type is `.Array` or `.Dictionary`, `json.boolValue` should return `false`. --- Source/SwiftyJSON.swift | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 82d35737..c3ee2b51 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -613,12 +613,6 @@ extension JSON: BooleanType { switch self.type { case .Bool, .Number, .String: return self.object.boolValue - case .Array: - return self.arrayValue.count > 0 - case .Dictionary: - return self.dictionaryValue.count > 0 - case .Null: - return false default: return false } From 08a51a9e604ab920f7c0cc221087971cfa2ab477 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sun, 19 Oct 2014 10:35:53 +0800 Subject: [PATCH 045/470] Update for XCode 6.1 --- Example/ViewController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 9d578eab..ba60cbc8 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -49,15 +49,15 @@ class ViewController: UITableViewController { switch self.json.type { case .Array: - cell.textLabel?.text = "\(row)" + cell.textLabel.text = "\(row)" cell.detailTextLabel?.text = self.json.arrayValue.description case .Dictionary: let key: AnyObject = (self.json.object as NSDictionary).allKeys[row] let value = self.json[key as String] - cell.textLabel?.text = "\(key)" + cell.textLabel.text = "\(key)" cell.detailTextLabel?.text = value.description default: - cell.textLabel?.text = "" + cell.textLabel.text = "" cell.detailTextLabel?.text = self.json.description } From 514dd98f816b28eb1280c16f6229e92f3407a931 Mon Sep 17 00:00:00 2001 From: tangplin Date: Sun, 19 Oct 2014 10:46:15 +0800 Subject: [PATCH 046/470] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 309a2f43..8b96ffff 100644 --- a/README.md +++ b/README.md @@ -83,9 +83,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ## Requirements - iOS 7.0+ / Mac OS X 10.9+ -- Xcode 6.0 - -> For Xcode 6.1, check out the `xcode6.1` branch. +- Xcode 6.1 ##Integration From dda468f698293169a7ab61bbaf31a956d01f5bbc Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sun, 19 Oct 2014 16:57:56 +0800 Subject: [PATCH 047/470] Change Dictionary to [K : V], Array to [T] --- Source/SwiftyJSON.swift | 60 +++++++++++++++++------------------ Tests/BaseTests.swift | 2 +- Tests/DictionaryTests.swift | 4 +-- Tests/SequenceTypeTests.swift | 10 +++--- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index c39ac969..ef0f2875 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -108,9 +108,9 @@ public struct JSON { _type = .String case let null as NSNull: _type = .Null - case let array as Array: + case let array as [AnyObject]: _type = .Array - case let dictionary as Dictionary: + case let dictionary as [String : AnyObject]: _type = .Dictionary default: _type = .Unknow @@ -139,9 +139,9 @@ extension JSON: SequenceType{ get { switch self.type { case .Array: - return (self.object as Array).isEmpty + return (self.object as [AnyObject]).isEmpty case .Dictionary: - return (self.object as Dictionary).isEmpty + return (self.object as [String : AnyObject]).isEmpty default: return false } @@ -170,7 +170,7 @@ extension JSON: SequenceType{ public func generate() -> GeneratorOf <(String, JSON)> { switch self.type { case .Array: - let array_ = object as Array + let array_ = object as [AnyObject] var generate_ = array_.generate() var index_: Int = 0 return GeneratorOf<(String, JSON)> { @@ -181,7 +181,7 @@ extension JSON: SequenceType{ } } case .Dictionary: - let dictionary_ = object as Dictionary + let dictionary_ = object as [String : AnyObject] var generate_ = dictionary_.generate() return GeneratorOf<(String, JSON)> { if let (key_: String, value_: AnyObject) = generate_.next() { @@ -233,7 +233,7 @@ extension JSON { } set { if self.type == .Array { - var array_ = self.object as Array + var array_ = self.object as [AnyObject] if array_.count > index { array_[index] = newValue.object self.object = array_ @@ -259,7 +259,7 @@ extension JSON { } set { if self.type == .Dictionary { - var dictionary_ = self.object as Dictionary + var dictionary_ = self.object as [String : AnyObject] dictionary_[key] = newValue.object self.object = dictionary_ } @@ -457,9 +457,9 @@ extension JSON: Printable, DebugPrintable { case .String: return self.object as String case .Array: - return (self.object as Array).description + return (self.object as [AnyObject]).description case .Dictionary: - return (self.object as Dictionary).description + return (self.object as [String : AnyObject]).description case .Bool: return (self.object as Bool).description case .Null: @@ -478,9 +478,9 @@ extension JSON: Printable, DebugPrintable { case .String: return self.object as String case .Array: - return (self.object as Array).debugDescription + return (self.object as [AnyObject]).debugDescription case .Dictionary: - return (self.object as Dictionary).debugDescription + return (self.object as [String : AnyObject]).debugDescription case .Bool: return (self.object as Bool).description case .Null: @@ -496,30 +496,30 @@ extension JSON: Printable, DebugPrintable { extension JSON { - //Optional Array - public var array: Array? { + //Optional [JSON] + public var array: [JSON]? { get { if self.type == .Array { - return map(self.object as Array){ JSON($0) } + return map(self.object as [AnyObject]){ JSON($0) } } else { return nil } } } - //Non-optional Array - public var arrayValue: Array { + //Non-optional [JSON] + public var arrayValue: [JSON] { get { return self.array ?? [] } } - //Optional Array - public var arrayObject: Array? { + //Optional [AnyObject] + public var arrayObject: [AnyObject]? { get { switch self.type { case .Array: - return self.object as? Array + return self.object as? [AnyObject] default: return nil } @@ -546,30 +546,30 @@ extension JSON { return result } - //Optional Dictionary - public var dictionary: Dictionary? { + //Optional [String : JSON] + public var dictionary: [String : JSON]? { get { if self.type == .Dictionary { - return _map(self.object as Dictionary){ JSON($0) } + return _map(self.object as [String : AnyObject]){ JSON($0) } } else { return nil } } } - //Non-optional Dictionary - public var dictionaryValue: Dictionary { + //Non-optional [String : JSON] + public var dictionaryValue: [String : JSON] { get { return self.dictionary ?? [:] } } - //Optional Dictionary - public var dictionaryObject: Dictionary? { + //Optional [String : AnyObject] + public var dictionaryObject: [String : AnyObject]? { get { switch self.type { case .Dictionary: - return self.object as? Dictionary + return self.object as? [String : AnyObject] default: return nil } @@ -1205,12 +1205,12 @@ extension JSON { } @availability(*, unavailable, renamed="dictionaryObject") - public var dictionaryObjects: Dictionary? { + public var dictionaryObjects: [String : AnyObject]? { get { return self.dictionaryObject } } @availability(*, unavailable, renamed="arrayObject") - public var arrayObjects: Array? { + public var arrayObjects: [AnyObject]? { get { return self.arrayObject } } diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 94f3e3c8..2226abc0 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -142,7 +142,7 @@ class BaseTests: XCTestCase { } var index = 0 - let keys = (json[1].dictionaryObject! as NSDictionary).allKeys as Array + let keys = (json[1].dictionaryObject! as NSDictionary).allKeys as [String] for (aKey, aJson) in json[1] { XCTAssertEqual(aKey, keys[index]) XCTAssertEqual(aJson, json[1][keys[index]]) diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index 4ed4a31b..3a595fda 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -49,8 +49,8 @@ class DictionaryTests: XCTestCase { func testSetter() { var json:JSON = ["test":"case"] - XCTAssertEqual(json.dictionaryObject! as Dictionary, ["test":"case"]) + XCTAssertEqual(json.dictionaryObject! as [String : String], ["test":"case"]) json.dictionaryObject = ["name":"NAME"] - XCTAssertEqual(json.dictionaryObject! as Dictionary, ["name":"NAME"]) + XCTAssertEqual(json.dictionaryObject! as [String : String], ["name":"NAME"]) } } diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index 7cdd838d..fa3d4724 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -125,11 +125,11 @@ class SequenceTypeTests: XCTestCase { index++ } XCTAssertEqual(index, 3) - XCTAssertEqual((array[0] as Dictionary)["1"]!, 1) - XCTAssertEqual((array[0] as Dictionary)["2"]!, 2) - XCTAssertEqual((array[1] as Dictionary)["a"]!, "A") - XCTAssertEqual((array[1] as Dictionary)["b"]!, "B") - XCTAssertEqual((array[2] as Dictionary)["null"]!, NSNull()) + XCTAssertEqual((array[0] as [String : Int])["1"]!, 1) + XCTAssertEqual((array[0] as [String : Int])["2"]!, 2) + XCTAssertEqual((array[1] as [String : String])["a"]!, "A") + XCTAssertEqual((array[1] as [String : String])["b"]!, "B") + XCTAssertEqual((array[2] as [String : NSNull])["null"]!, NSNull()) } func testDictionaryAllNumber() { From 7a4c6b7bc0153b807a81ffb0556106b9e01e832d Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sun, 19 Oct 2014 17:08:51 +0800 Subject: [PATCH 048/470] Change if to ?? --- Source/SwiftyJSON.swift | 6 +----- Tests/NumberTests.swift | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index ef0f2875..0b3426b5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -680,11 +680,7 @@ extension JSON { } } set { - if newValue != nil { - self.object = newValue!.copy() - } else { - self.object = NSNull() - } + self.object = newValue?.copy() ?? NSNull() } } diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 59d8780f..231f9bc6 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -38,6 +38,8 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 123456789.0987654321) json.number = nil XCTAssertEqual(json.numberValue, 0) + XCTAssertEqual(json.object as NSNull, NSNull()) + XCTAssertTrue(json.number == nil) json.numberValue = 2.9876 XCTAssertEqual(json.number!, 2.9876) } From 5ff175449a13df5919911cc866e08ecff3090605 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sun, 19 Oct 2014 23:29:09 +0800 Subject: [PATCH 049/470] Add support for non-array and non-dictionary get the raw string --- Source/SwiftyJSON.swift | 19 ++++++++++++++++--- Tests/RawTests.swift | 30 +++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 0b3426b5..516fad67 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -437,9 +437,22 @@ extension JSON: RawRepresentable { } public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted, error: NSErrorPointer = nil) -> String? { - if let data = self.rawData(options: opt, error:error) { - return NSString(data: data, encoding: encoding) - } else { + switch self.type { + case .Array, .Dictionary: + if let data = self.rawData(options: opt, error:error) { + return NSString(data: data, encoding: encoding) + } else { + return nil + } + case .String: + return (self.object as String) + case .Number: + return (self.object as NSNumber).stringValue + case .Bool: + return (self.object as Bool).description + case .Null: + return "null" + default: return nil } } diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index ba31b9b6..a867eac5 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -43,12 +43,28 @@ class RawTests: XCTestCase { XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) println(string!) } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measureBlock() { - // Put the code you want to measure the time of here. - } + + func testString() { + let json:JSON = "I'm a json" + println(json.rawString()) + XCTAssertTrue(json.rawString() == "I'm a json") + } + + func testNumber() { + let json:JSON = 123456789.123 + println(json.rawString()) + XCTAssertTrue(json.rawString() == "123456789.123") + } + + func testBool() { + let json:JSON = true + println(json.rawString()) + XCTAssertTrue(json.rawString() == "true") + } + + func testNull() { + let json:JSON = nil + println(json.rawString()) + XCTAssertTrue(json.rawString() == "null") } - } From e4365fe2ce67cc90cdfe8014c110adb775cca98a Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Mon, 20 Oct 2014 00:44:00 +0800 Subject: [PATCH 050/470] Update rawData's default options to NSJSONWritingOptions(0) --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 516fad67..885bed98 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -432,7 +432,7 @@ extension JSON: RawRepresentable { return self.object } - public func rawData(options opt: NSJSONWritingOptions = .PrettyPrinted, error: NSErrorPointer = nil) -> NSData? { + public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(0), error: NSErrorPointer = nil) -> NSData? { return NSJSONSerialization.dataWithJSONObject(self.object, options: opt, error:error) } From f11909984755141888c5721c5837dd175ec409bd Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Mon, 20 Oct 2014 00:45:30 +0800 Subject: [PATCH 051/470] Delete the rawString's `error` argument --- Source/SwiftyJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 885bed98..47d90560 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -436,10 +436,10 @@ extension JSON: RawRepresentable { return NSJSONSerialization.dataWithJSONObject(self.object, options: opt, error:error) } - public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted, error: NSErrorPointer = nil) -> String? { + public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted) -> String? { switch self.type { case .Array, .Dictionary: - if let data = self.rawData(options: opt, error:error) { + if let data = self.rawData(options: opt) { return NSString(data: data, encoding: encoding) } else { return nil From 08e450aceeaddb46eff35a51c2b919b68b06903f Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Mon, 20 Oct 2014 00:47:46 +0800 Subject: [PATCH 052/470] Update `description` and `debugDescription` to call `rawString` --- Source/SwiftyJSON.swift | 40 +++++--------------------------------- Tests/BaseTests.swift | 2 +- Tests/PrintableTests.swift | 8 ++++---- 3 files changed, 10 insertions(+), 40 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 47d90560..175b01ae 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -463,45 +463,15 @@ extension JSON: RawRepresentable { extension JSON: Printable, DebugPrintable { public var description: String { - get { - switch type { - case .Number: - return self.object.description - case .String: - return self.object as String - case .Array: - return (self.object as [AnyObject]).description - case .Dictionary: - return (self.object as [String : AnyObject]).description - case .Bool: - return (self.object as Bool).description - case .Null: - return self.error?.description ?? "null" - default: - return self.error?.description ?? "unknown" - } + if let string = self.rawString(options:.PrettyPrinted) { + return string + } else { + return "unknown" } } public var debugDescription: String { - get { - switch type { - case .Number: - return (self.object as NSNumber).debugDescription - case .String: - return self.object as String - case .Array: - return (self.object as [AnyObject]).debugDescription - case .Dictionary: - return (self.object as [String : AnyObject]).debugDescription - case .Bool: - return (self.object as Bool).description - case .Null: - return self.error?.debugDescription ?? "null" - default: - return self.error?.debugDescription ?? "unknown" - } - } + return description } } diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 2226abc0..55bb15d4 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -47,7 +47,7 @@ class BaseTests: XCTestCase { let json0 = JSON(data:self.testData) XCTAssertEqual(json0.array!.count, 3) XCTAssertEqual(JSON("123").description, "123") - XCTAssertEqual(JSON(["1":"2"]).description, ["1":"2"].description) + XCTAssertEqual(JSON(["1":"2"])["1"].string!, "2") var dictionary = NSMutableDictionary() dictionary.setObject(NSNumber(double: 1.0), forKey: "number" as NSString) dictionary.setObject(NSNull(), forKey: "null" as NSString) diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index e0dabf35..668c5938 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -57,13 +57,13 @@ class PrintableTests: XCTestCase { func testArray() { var json:JSON = [1,2,"4",5,"6"] - XCTAssertEqual(json.description, "[1, 2, 4, 5, 6]") - XCTAssertEqual(json.debugDescription, "[1, 2, 4, 5, 6]") + XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + XCTAssertTrue(json.debugDescription.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) } func testDictionary() { var json:JSON = ["1":2,"2":2, "3":3] - XCTAssertEqual(json.description, ["1":2,"2":2, "3":3].description) - XCTAssertEqual(json.debugDescription, ["1":2,"2":2, "3":3].debugDescription) + XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + XCTAssertTrue(json.debugDescription.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) } } From 6297219aa33818f3fae3b77d1c423b3ee54f8aae Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Mon, 20 Oct 2014 01:00:11 +0800 Subject: [PATCH 053/470] Update tests for `description` --- Tests/PrintableTests.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index 668c5938..54d76723 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -57,13 +57,18 @@ class PrintableTests: XCTestCase { func testArray() { var json:JSON = [1,2,"4",5,"6"] + var description = json.description.stringByReplacingOccurrencesOfString("\n", withString: "") + description = description.stringByReplacingOccurrencesOfString(" ", withString: "") + XCTAssertEqual(description, "[1,2,\"4\",5,\"6\"]") XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) XCTAssertTrue(json.debugDescription.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) } func testDictionary() { var json:JSON = ["1":2,"2":2, "3":3] + var debugDescription = json.debugDescription.stringByReplacingOccurrencesOfString("\n", withString: "") + debugDescription = debugDescription.stringByReplacingOccurrencesOfString(" ", withString: "") XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) - XCTAssertTrue(json.debugDescription.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + XCTAssertEqual(debugDescription, "{\"1\":2,\"2\":2,\"3\":3}") } } From 016b14b909a5b73bdec5520a6190beb469fdaf3f Mon Sep 17 00:00:00 2001 From: tangplin Date: Tue, 21 Oct 2014 11:56:08 +0800 Subject: [PATCH 054/470] Update test json print which's type is .dictionary. --- Tests/PrintableTests.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index 54d76723..398ec8b1 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -65,10 +65,12 @@ class PrintableTests: XCTestCase { } func testDictionary() { - var json:JSON = ["1":2,"2":2, "3":3] + var json:JSON = ["1":2,"2":"two", "3":3] var debugDescription = json.debugDescription.stringByReplacingOccurrencesOfString("\n", withString: "") debugDescription = debugDescription.stringByReplacingOccurrencesOfString(" ", withString: "") XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) - XCTAssertEqual(debugDescription, "{\"1\":2,\"2\":2,\"3\":3}") + XCTAssertTrue(debugDescription.rangeOfString("\"1\":2", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) + XCTAssertTrue(debugDescription.rangeOfString("\"2\":\"two\"", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) + XCTAssertTrue(debugDescription.rangeOfString("\"3\":3", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) } } From 56fb3fbd3241e832c671e5f6e7657107d133b859 Mon Sep 17 00:00:00 2001 From: tangplin Date: Wed, 22 Oct 2014 21:46:44 +0800 Subject: [PATCH 055/470] Add Chinese version link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b96ffff..7efc92cb 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#SwiftyJSON +#SwiftyJSON [中文介绍](http://tangplin.github.io/swiftyjson/) SwiftyJSON makes it easy to deal with JSON data in Swift. From f1bc3922a6444506b021ae52a3d00610141cc2bd Mon Sep 17 00:00:00 2001 From: John Gorenfeld Date: Wed, 22 Oct 2014 12:43:37 -0700 Subject: [PATCH 056/470] Update README.md I did an editorial polish on some of the language. --- README.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7efc92cb..2342fb2f 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,9 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. 1. [Work with Alamofire](#work-with-alamofire) ##Why is the typical JSON handling in Swift NOT good? -Swift is very strict about types, it's good while explicit typing left us little chance to make mistakes. -But while dealing with things that naturally implicit about types such as JSON, it's painful. +Swift is very strict about types. But although explicit typing leaves us little chance of making mistakes, it becomes painful when dealing with things that are naturally implicit about types, such as JSON. -Take the Twitter API for example: say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline) +Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline). The code would look like this: @@ -53,7 +52,7 @@ if let userName = (((jsonObject as? NSArray)?[0] as? NSDictionary)?["user"] as? } ``` -An unreadable mess for something like this should really be simple! +An unreadable mess--for something that should really be simple! With SwiftyJSON all you have to do is: @@ -66,7 +65,7 @@ if let userName = json[0]["user"]["name"].string{ ``` -And don't worry about the Optional Wrapping thing, it's done for you automatically +And don't worry about the Optional Wrapping thing. It's done for you automatically ```swift @@ -87,7 +86,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ##Integration -CocoaPods is not fully supported for Swift yet, to use this library in your project you should: +CocoaPods is not fully supported for Swift yet. To use this library in your project you should: 1. for Projects just drag SwiftyJSON.swift to the project tree 2. for Workspaces you may include the whole SwiftyJSON.xcodeproj as suggested by @garnett @@ -146,9 +145,9 @@ for (index: String, subJson: JSON) in json { ####Error Use subscript to get/set value in Array or Dicitonary -* If json is an array, the app may crash with index may be out of bounds. +* If json is an array, the app may crash with "index out-of-bounds." * If json is a dictionary, it will get `nil` without the reason. -* If json is not an array or a dictionary, the app may crash with wrong selector exception. +* If json is not an array or a dictionary, the app may crash with the wrong selector exception. It will never happen in SwiftyJSON From cb36f3f5f27f64fb7606bbfd279c5e43e81df391 Mon Sep 17 00:00:00 2001 From: John Gorenfeld Date: Fri, 24 Oct 2014 13:54:41 -0700 Subject: [PATCH 057/470] Update README.md Just a little more editing --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2342fb2f..30b5fac0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. 1. [Work with Alamofire](#work-with-alamofire) ##Why is the typical JSON handling in Swift NOT good? -Swift is very strict about types. But although explicit typing leaves us little chance of making mistakes, it becomes painful when dealing with things that are naturally implicit about types, such as JSON. +Swift is very strict about types. But although explicit typing is good for saving us from mistakes, it becomes painful when dealing with JSON and other areas that are, by nature, implicit about types. Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline). @@ -134,7 +134,7 @@ for (key: String, subJson: JSON) in json { //Do something you want } ``` -*The first element always String even the JSON's object is Array* +*The first element is always String, even if the JSON's object is Array* ```swift //If json is .Array //The `index` is 0.. Date: Thu, 6 Nov 2014 22:13:10 +0100 Subject: [PATCH 058/470] Remove redundant UIKit import to make tests OS X & iOS compatible. --- Tests/ArrayTests.swift | 1 - Tests/BaseTests.swift | 1 - Tests/ComparableTests.swift | 1 - Tests/DictionaryTests.swift | 1 - Tests/LiteralConvertibleTests.swift | 1 - Tests/NumberTests.swift | 1 - Tests/PerformanceTests.swift | 1 - Tests/PrintableTests.swift | 1 - Tests/RawRepresentableTests.swift | 1 - Tests/RawTests.swift | 1 - Tests/SequenceTypeTests.swift | 1 - Tests/StringTests.swift | 1 - Tests/SubscriptTests.swift | 1 - 13 files changed, 13 deletions(-) diff --git a/Tests/ArrayTests.swift b/Tests/ArrayTests.swift index b7fbfc87..1c6b1ee4 100644 --- a/Tests/ArrayTests.swift +++ b/Tests/ArrayTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 55bb15d4..8ca6aac7 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/ComparableTests.swift b/Tests/ComparableTests.swift index 465949ed..1ce07a71 100644 --- a/Tests/ComparableTests.swift +++ b/Tests/ComparableTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index 3a595fda..d8762122 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift index 9902ba15..bc9d0e47 100644 --- a/Tests/LiteralConvertibleTests.swift +++ b/Tests/LiteralConvertibleTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 231f9bc6..823de08b 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON class NumberTests: XCTestCase { diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index 46fc6a1e..598f3a6d 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index 398ec8b1..ef22802a 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index 8325c2ae..cedcf771 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index a867eac5..d92ba3ac 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index fa3d4724..b13c4a90 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -21,7 +21,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index 880cfe7e..c47357b1 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index e9b84bad..5e2034a4 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -20,7 +20,6 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. -import UIKit import XCTest import SwiftyJSON From 3ebfb4b419e0db771901ac26e181d8c9bd327d08 Mon Sep 17 00:00:00 2001 From: Carlos Lozano Date: Thu, 6 Nov 2014 22:14:18 +0100 Subject: [PATCH 059/470] Added OS X target - 100% test passing on OSX & iOS --- SwiftyJSON.xcodeproj/project.pbxproj | 249 ++++++++++++++++++++++++++- 1 file changed, 247 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index c41df008..d3c1b51d 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -9,6 +9,23 @@ /* Begin PBXBuildFile section */ 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; + 4EC1C1D41A0C1A2D0026ED0B /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */; }; + 4EC1C1E21A0C1A6E0026ED0B /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 4EC1C1E31A0C1A750026ED0B /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + 4EC1C1E41A0C1A800026ED0B /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; + 4EC1C1E51A0C1A800026ED0B /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; + 4EC1C1E61A0C1A800026ED0B /* BaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */; }; + 4EC1C1E71A0C1A800026ED0B /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; + 4EC1C1E81A0C1A800026ED0B /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; + 4EC1C1E91A0C1A800026ED0B /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; + 4EC1C1EA1A0C1A800026ED0B /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; + 4EC1C1EB1A0C1A800026ED0B /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; + 4EC1C1EC1A0C1A800026ED0B /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; + 4EC1C1ED1A0C1A800026ED0B /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; + 4EC1C1EE1A0C1A800026ED0B /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; + 4EC1C1EF1A0C1A800026ED0B /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; + 4EC1C1F01A0C1A800026ED0B /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; + 4EC1C1F11A0C1A800026ED0B /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; @@ -34,6 +51,13 @@ remoteGlobalIDString = 2E4FEFDA19575BE100351305; remoteInfo = SwiftyJSON; }; + 4EC1C1D51A0C1A2D0026ED0B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2E4FEFD219575BE100351305 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 4EC1C1C81A0C1A2D0026ED0B; + remoteInfo = SwiftyJSONOSX; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -41,6 +65,8 @@ 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; @@ -75,6 +101,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 4EC1C1C51A0C1A2D0026ED0B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4EC1C1D01A0C1A2D0026ED0B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4EC1C1D41A0C1A2D0026ED0B /* SwiftyJSON.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -92,6 +133,8 @@ children = ( 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */, + 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */, + 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */, ); name = Products; sourceTree = ""; @@ -155,6 +198,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 4EC1C1C61A0C1A2D0026ED0B /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 4EC1C1E21A0C1A6E0026ED0B /* SwiftyJSON.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -194,6 +245,42 @@ productReference = 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSX" */; + buildPhases = ( + 4EC1C1C41A0C1A2D0026ED0B /* Sources */, + 4EC1C1C51A0C1A2D0026ED0B /* Frameworks */, + 4EC1C1C61A0C1A2D0026ED0B /* Headers */, + 4EC1C1C71A0C1A2D0026ED0B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = SwiftyJSONOSX; + productName = SwiftyJSONOSX; + productReference = 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */; + productType = "com.apple.product-type.framework"; + }; + 4EC1C1D21A0C1A2D0026ED0B /* SwiftyJSONOSXTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4EC1C1DF1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSXTests" */; + buildPhases = ( + 4EC1C1CF1A0C1A2D0026ED0B /* Sources */, + 4EC1C1D01A0C1A2D0026ED0B /* Frameworks */, + 4EC1C1D11A0C1A2D0026ED0B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 4EC1C1D61A0C1A2D0026ED0B /* PBXTargetDependency */, + ); + name = SwiftyJSONOSXTests; + productName = SwiftyJSONOSXTests; + productReference = 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -209,6 +296,12 @@ CreatedOnToolsVersion = 6.0; TestTargetID = 2E4FEFDA19575BE100351305; }; + 4EC1C1C81A0C1A2D0026ED0B = { + CreatedOnToolsVersion = 6.1; + }; + 4EC1C1D21A0C1A2D0026ED0B = { + CreatedOnToolsVersion = 6.1; + }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -225,6 +318,8 @@ targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON */, 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, + 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */, + 4EC1C1D21A0C1A2D0026ED0B /* SwiftyJSONOSXTests */, ); }; /* End PBXProject section */ @@ -245,6 +340,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 4EC1C1C71A0C1A2D0026ED0B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4EC1C1D11A0C1A2D0026ED0B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4EC1C1E41A0C1A800026ED0B /* Tests.json in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -276,6 +386,34 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 4EC1C1C41A0C1A2D0026ED0B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4EC1C1E31A0C1A750026ED0B /* SwiftyJSON.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 4EC1C1CF1A0C1A2D0026ED0B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4EC1C1E71A0C1A800026ED0B /* SequenceTypeTests.swift in Sources */, + 4EC1C1EC1A0C1A800026ED0B /* ComparableTests.swift in Sources */, + 4EC1C1EE1A0C1A800026ED0B /* NumberTests.swift in Sources */, + 4EC1C1EB1A0C1A800026ED0B /* RawRepresentableTests.swift in Sources */, + 4EC1C1E61A0C1A800026ED0B /* BaseTests.swift in Sources */, + 4EC1C1F01A0C1A800026ED0B /* DictionaryTests.swift in Sources */, + 4EC1C1E51A0C1A800026ED0B /* PerformanceTests.swift in Sources */, + 4EC1C1EA1A0C1A800026ED0B /* LiteralConvertibleTests.swift in Sources */, + 4EC1C1E81A0C1A800026ED0B /* PrintableTests.swift in Sources */, + 4EC1C1ED1A0C1A800026ED0B /* StringTests.swift in Sources */, + 4EC1C1EF1A0C1A800026ED0B /* RawTests.swift in Sources */, + 4EC1C1F11A0C1A800026ED0B /* ArrayTests.swift in Sources */, + 4EC1C1E91A0C1A800026ED0B /* SubscriptTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -284,6 +422,11 @@ target = 2E4FEFDA19575BE100351305 /* SwiftyJSON */; targetProxy = 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */; }; + 4EC1C1D61A0C1A2D0026ED0B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */; + targetProxy = 4EC1C1D51A0C1A2D0026ED0B /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -322,7 +465,8 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; + MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -362,7 +506,8 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 7.1; + MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -434,6 +579,90 @@ }; name = Release; }; + 4EC1C1DD1A0C1A2D0026ED0B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_MODULE_NAME = SwiftyJSON; + PRODUCT_NAME = SwiftyJSON; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 4EC1C1DE1A0C1A2D0026ED0B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_MODULE_NAME = SwiftyJSON; + PRODUCT_NAME = SwiftyJSON; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 4EC1C1E01A0C1A2D0026ED0B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Debug; + }; + 4EC1C1E11A0C1A2D0026ED0B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + INFOPLIST_FILE = Tests/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -464,6 +693,22 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSX" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4EC1C1DD1A0C1A2D0026ED0B /* Debug */, + 4EC1C1DE1A0C1A2D0026ED0B /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; + 4EC1C1DF1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSXTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4EC1C1E01A0C1A2D0026ED0B /* Debug */, + 4EC1C1E11A0C1A2D0026ED0B /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; /* End XCConfigurationList section */ }; rootObject = 2E4FEFD219575BE100351305 /* Project object */; From 3175e4ce6efd3284e8144b13b67fc3cd54048af4 Mon Sep 17 00:00:00 2001 From: Carlos Lozano Date: Fri, 7 Nov 2014 11:05:14 +0100 Subject: [PATCH 060/470] Inherit project settings in target. --- SwiftyJSON.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index d3c1b51d..8af9ed84 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -447,7 +447,6 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -494,7 +493,6 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_NS_ASSERTIONS = NO; @@ -700,6 +698,7 @@ 4EC1C1DE1A0C1A2D0026ED0B /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 4EC1C1DF1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSXTests" */ = { isa = XCConfigurationList; @@ -708,6 +707,7 @@ 4EC1C1E11A0C1A2D0026ED0B /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; From 79617cc32c76d321a008533421e866cf2b51584e Mon Sep 17 00:00:00 2001 From: Jonathan Porta Date: Sat, 8 Nov 2014 22:10:51 -0700 Subject: [PATCH 061/470] Change recommendation for Alamofire integration Issues with recommending Alamofire-SwiftyJSON: - Not updated for Xcode 6.1. - No longer necessary as a shim to integrate Alamofire and SwiftyJSON. - Adds another dependency that needs to be manually included and managed. --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 30b5fac0..d537aa92 100644 --- a/README.md +++ b/README.md @@ -328,4 +328,12 @@ json[path] = "that" ``` ##Work with Alamofire -To use Alamofire and SwiftyJSON, try [Alamofire-SwiftyJSON](https://github.com/SwiftyJSON/Alamofire-SwiftyJSON). +SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: +```swift +Alamofire.request(.GET, url, parameters: parameters) + .responseJSON { (req, res, json, error) in + // Init a SwiftyJSON object using the Alamofire JSON response handler. + var json = JSON(json!) + NSLog("GET Result: \(json)") + } +``` From a1ce24bac68203cf3b58b49543815298d01e12fd Mon Sep 17 00:00:00 2001 From: Frank Luan Date: Tue, 11 Nov 2014 15:10:53 -0600 Subject: [PATCH 062/470] Renamed type 'Unknow' to 'Unknown' --- Source/SwiftyJSON.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 175b01ae..da153fb5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -48,7 +48,7 @@ public enum Type :Int{ case Array case Dictionary case Null - case Unknow + case Unknown } // MARK: - JSON Base @@ -113,7 +113,7 @@ public struct JSON { case let dictionary as [String : AnyObject]: _type = .Dictionary default: - _type = .Unknow + _type = .Unknown _object = NSNull() _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) } @@ -421,7 +421,7 @@ extension JSON: NilLiteralConvertible { extension JSON: RawRepresentable { public init?(rawValue: AnyObject) { - if JSON(rawValue).type == .Unknow { + if JSON(rawValue).type == .Unknown { return nil } else { self.init(rawValue) From ad17a21e52bb0eb9408771b4f2ce1845e8499fda Mon Sep 17 00:00:00 2001 From: Jonathan Porta Date: Thu, 13 Nov 2014 17:21:23 -0800 Subject: [PATCH 063/470] Add a super simple error handling example --- README.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d537aa92..a28d3a50 100644 --- a/README.md +++ b/README.md @@ -332,8 +332,14 @@ SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: ```swift Alamofire.request(.GET, url, parameters: parameters) .responseJSON { (req, res, json, error) in - // Init a SwiftyJSON object using the Alamofire JSON response handler. - var json = JSON(json!) - NSLog("GET Result: \(json)") + if(error != nil) { + NSLog("Error: \(error)") + println(req) + println(res) + } + else { + NSLog("Success: \(url)") + var json = JSON(json!) + } } ``` From 1d72868e524c8354697e9a5b7f5736dc5dbc9449 Mon Sep 17 00:00:00 2001 From: Lionel Schinckus Date: Sun, 23 Nov 2014 18:53:26 +0100 Subject: [PATCH 064/470] Correct mblsha podspec --- SwiftyJSON.podspec | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 SwiftyJSON.podspec diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec new file mode 100644 index 00000000..7b6b760e --- /dev/null +++ b/SwiftyJSON.podspec @@ -0,0 +1,13 @@ +Pod::Spec.new do |s| + s.name = "SwiftyJSON" + s.version = "2.1.1" + s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" + s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" + s.license = { :type => "MIT" } + s.authors = { "lingoer" => "lingoerer@gmail.com", "tangplin" => "tangplin@gmail.com" } + + s.osx.deployment_target = "10.9" + s.ios.deployment_target = "7.0" + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.1" } + s.source_files = "Source/*.swift" +end From 09779b1dd0f95661087433eb6f6c5d539e0e6e86 Mon Sep 17 00:00:00 2001 From: Justin Makaila Date: Tue, 2 Dec 2014 11:14:43 -0500 Subject: [PATCH 065/470] Updated all the code signing identities --- Example.xcodeproj/project.pbxproj | 31 ++++++++++++++++++++++++++++ SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 33 insertions(+) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index dda2844e..d44023bc 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -18,6 +18,20 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 4EC1C1C91A0C1A2D0026ED0B; + remoteInfo = SwiftyJSONOSX; + }; + 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 4EC1C1D31A0C1A2D0026ED0B; + remoteInfo = SwiftyJSONOSXTests; + }; A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; @@ -123,6 +137,8 @@ children = ( A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */, A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */, + 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */, + 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */, ); name = Products; sourceTree = ""; @@ -188,6 +204,20 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ + 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftyJSON.framework; + remoteRef = 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = SwiftyJSONOSXTests.xctest; + remoteRef = 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; @@ -355,6 +385,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + CODE_SIGN_IDENTITY = "iPhone Distribution"; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 8af9ed84..a6085ed1 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -518,6 +518,7 @@ 2E4FEFF219575BE100351305 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -533,6 +534,7 @@ 2E4FEFF319575BE100351305 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "iPhone Distribution"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; From eef5bf135c8cbc2cc64f3f66e5665e9019bb88cb Mon Sep 17 00:00:00 2001 From: Justin Makaila Date: Tue, 2 Dec 2014 11:30:11 -0500 Subject: [PATCH 066/470] Should fix code signing issues --- Example.xcodeproj/project.pbxproj | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index d44023bc..8c7df7d5 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -349,7 +349,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index a6085ed1..54fb6e68 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -447,6 +447,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -493,6 +494,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "iPhone Distribution"; COPY_PHASE_STRIP = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_NS_ASSERTIONS = NO; From def49ed99df1d937da702ca4cae864100e1e567f Mon Sep 17 00:00:00 2001 From: Justin Makaila Date: Tue, 2 Dec 2014 12:57:53 -0500 Subject: [PATCH 067/470] Updated deployment target --- SwiftyJSON.xcodeproj/project.pbxproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 54fb6e68..99b64685 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -465,7 +465,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -506,7 +506,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -527,6 +527,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -543,6 +544,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; From 0381feab23220fcb829f4e5659cb2223244b187e Mon Sep 17 00:00:00 2001 From: Justin Makaila Date: Tue, 2 Dec 2014 13:00:29 -0500 Subject: [PATCH 068/470] Removed .xcscheme from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8841a69a..6e137049 100644 --- a/.gitignore +++ b/.gitignore @@ -19,4 +19,3 @@ DerivedData #CocoaPods Pods -*.xcscheme From aa9cc392822729e77517dcc25642ffb2ea6b026d Mon Sep 17 00:00:00 2001 From: Justin Makaila Date: Tue, 2 Dec 2014 13:01:08 -0500 Subject: [PATCH 069/470] Added shared scheme --- .../xcschemes/SwiftyJSON.xcscheme | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.xcscheme diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.xcscheme new file mode 100644 index 00000000..158db480 --- /dev/null +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 78986c89ebd399b0c1aa695b1ad1fd5108908aa0 Mon Sep 17 00:00:00 2001 From: Brian Kracoff Date: Mon, 8 Dec 2014 14:14:39 -0500 Subject: [PATCH 070/470] Fix NSNumber != func --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index da153fb5..e65f33d9 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1120,7 +1120,7 @@ public func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { } public func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { - return !(rhs == rhs) + return !(lhs == rhs) } public func <(lhs: NSNumber, rhs: NSNumber) -> Bool { From 62bf5eb863e5d28c702e2bc099fd0f9779c19dc4 Mon Sep 17 00:00:00 2001 From: justinmakaila Date: Fri, 12 Dec 2014 10:53:58 -0500 Subject: [PATCH 071/470] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 30b5fac0..d6c1967d 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,9 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ##Integration +You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding +`github "SwiftyJSON/SwiftyJSON" >= 2.1.1` to your `Cartfile` + CocoaPods is not fully supported for Swift yet. To use this library in your project you should: 1. for Projects just drag SwiftyJSON.swift to the project tree From 9910b9db9c904a61b55f82e1ea5c55c70669ea29 Mon Sep 17 00:00:00 2001 From: tangplin Date: Sat, 13 Dec 2014 11:18:14 +0800 Subject: [PATCH 072/470] Update SwiftyJSON.podspec for 2.1.2 --- SwiftyJSON.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 7b6b760e..3d4af345 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.1.1" + s.version = "2.1.2" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -8,6 +8,6 @@ Pod::Spec.new do |s| s.osx.deployment_target = "10.9" s.ios.deployment_target = "7.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.1" } + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.2"} s.source_files = "Source/*.swift" end From 78dfbf4ffb235ef95badd68bb1c34a64d65a1501 Mon Sep 17 00:00:00 2001 From: tangplin Date: Sat, 13 Dec 2014 16:34:54 +0800 Subject: [PATCH 073/470] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f7de5a6..8b9dbcf6 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ##Integration You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding -`github "SwiftyJSON/SwiftyJSON" >= 2.1.1` to your `Cartfile` +`github "SwiftyJSON/SwiftyJSON" >= 2.1.2` to your `Cartfile` CocoaPods is not fully supported for Swift yet. To use this library in your project you should: From 99527af0a1bfd4a5336edee7a3e478c760d92255 Mon Sep 17 00:00:00 2001 From: "Maxim V. Potapov" Date: Sun, 14 Dec 2014 15:16:05 +0300 Subject: [PATCH 074/470] Use Mac' codesign identities for OSX targets --- SwiftyJSON.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 99b64685..2124ea3a 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -586,6 +586,7 @@ 4EC1C1DD1A0C1A2D0026ED0B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -610,6 +611,7 @@ 4EC1C1DE1A0C1A2D0026ED0B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; @@ -631,6 +633,7 @@ 4EC1C1E01A0C1A2D0026ED0B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", @@ -652,6 +655,7 @@ 4EC1C1E11A0C1A2D0026ED0B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( From 023f307a20eb041a23e34bfaa5e146cc77e659ab Mon Sep 17 00:00:00 2001 From: Hari Menon Date: Sun, 14 Dec 2014 15:33:07 -0500 Subject: [PATCH 075/470] fix the typos on the code snippets on README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b9dbcf6..62812798 100644 --- a/README.md +++ b/README.md @@ -118,13 +118,13 @@ let name = json["name"].stringValue let path = [1,"list",2,"name"] let name = json[path].string //Just the same -let name = json[1]["like"][2]["name"].string +let name = json[1]["list"][2]["name"].string ``` ```swift //With a literal array to the element let name = json[1,"list",2,"name"].string //Just the same -let name = json[1]["like"][2]["name"].string +let name = json[1]["list"][2]["name"].string ``` ```swift //With a Hard Way From 8df99e0c05e8974f00a78b7d2a51854f1efa2075 Mon Sep 17 00:00:00 2001 From: Hari Menon Date: Sun, 14 Dec 2014 15:50:45 -0500 Subject: [PATCH 076/470] updated the TOC links --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62812798..bc52ddad 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,14 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. -1. [Why is the typical JSON handling in Swift NOT good](#Why-is-the-typical-JSON-handling-in-Swift-NOT-good) +1. [Why is the typical JSON handling in Swift NOT good](#why-is-the-typical-json-handling-in-swift-not-good) 1. [Requirements](#requirements) 1. [Integration](#integration) 1. [Usage](#usage) - [Initialization](#initialization) - [Subscript](#subscript) - - [Error](#Error) - [Loop](#loop) + - [Error](#error) - [Optional getter](#optional-getter) - [Non-optional getter](#non-optional-getter) - [Setter](#setter) From f5347e5a90dfe00c32fa1fe228472291cacb386a Mon Sep 17 00:00:00 2001 From: "Michael Latta (TechnoMage)" Date: Sat, 20 Dec 2014 11:26:47 -0700 Subject: [PATCH 077/470] Make framework extension friendly --- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 2124ea3a..2a1c20ae 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -520,6 +520,7 @@ 2E4FEFF219575BE100351305 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -537,6 +538,7 @@ 2E4FEFF319575BE100351305 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; From b83db584965d75250182478b69ad6b9fbb8c35bc Mon Sep 17 00:00:00 2001 From: Victor Shamanov Date: Mon, 22 Dec 2014 14:38:03 +0300 Subject: [PATCH 078/470] Fix visibility of isEmpty property --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index e65f33d9..a76527eb 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -135,7 +135,7 @@ public struct JSON { extension JSON: SequenceType{ /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. - var isEmpty: Bool { + public var isEmpty: Bool { get { switch self.type { case .Array: From 5acbe93435a2ce0935224d214a0c531795f568e5 Mon Sep 17 00:00:00 2001 From: Rafael Veronezi Date: Tue, 23 Dec 2014 20:10:12 -0200 Subject: [PATCH 079/470] Prefixed "SequenceType" extension with Module name, since it was conflicting with other SequenceType declaration in separate library. --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a76527eb..cc24bec0 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -132,7 +132,7 @@ public struct JSON { } // MARK: - SequenceType -extension JSON: SequenceType{ +extension JSON : Swift.SequenceType { /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. public var isEmpty: Bool { From f5d08738c287508ffc9fd0672741dbca9ef50a32 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Wed, 24 Dec 2014 11:57:50 +0800 Subject: [PATCH 080/470] Update optional cell textLabel's text. --- Example.xcodeproj/project.pbxproj | 4 ++-- Example/ViewController.swift | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index 8c7df7d5..7279d2bf 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -323,7 +323,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -361,7 +361,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; diff --git a/Example/ViewController.swift b/Example/ViewController.swift index ba60cbc8..9d578eab 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -49,15 +49,15 @@ class ViewController: UITableViewController { switch self.json.type { case .Array: - cell.textLabel.text = "\(row)" + cell.textLabel?.text = "\(row)" cell.detailTextLabel?.text = self.json.arrayValue.description case .Dictionary: let key: AnyObject = (self.json.object as NSDictionary).allKeys[row] let value = self.json[key as String] - cell.textLabel.text = "\(key)" + cell.textLabel?.text = "\(key)" cell.detailTextLabel?.text = value.description default: - cell.textLabel.text = "" + cell.textLabel?.text = "" cell.detailTextLabel?.text = self.json.description } From 58a3772517290d3745dcba736c97710012596171 Mon Sep 17 00:00:00 2001 From: John Gorenfeld Date: Tue, 30 Dec 2014 11:34:22 -0800 Subject: [PATCH 081/470] Updated because podspec is now available... Also I was going to update the methods from .string to .stringValue, because I am not sure there is a .string method anymore, but then I saw the note about how this might be used to distinguish optional and non-optional returns. So I'm not sure. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bc52ddad..d8ec4aea 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding `github "SwiftyJSON/SwiftyJSON" >= 2.1.2` to your `Cartfile` -CocoaPods is not fully supported for Swift yet. To use this library in your project you should: +CocoaPods is now supported for Swift yet. But to use this library in your project manually you should: 1. for Projects just drag SwiftyJSON.swift to the project tree 2. for Workspaces you may include the whole SwiftyJSON.xcodeproj as suggested by @garnett From e735cae23f2c14a0b4b0df5c52cad6442bd5f9ec Mon Sep 17 00:00:00 2001 From: John Gorenfeld Date: Wed, 7 Jan 2015 15:14:21 -0800 Subject: [PATCH 082/470] Minor grammar fixes to README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d8ec4aea..24038a19 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ if let userName = json[0]["user"]["name"].string{ ``` -And don't worry about the Optional Wrapping thing. It's done for you automatically +And don't worry about the Optional Wrapping thing. It's done for you automatically. ```swift @@ -89,10 +89,10 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding `github "SwiftyJSON/SwiftyJSON" >= 2.1.2` to your `Cartfile` -CocoaPods is now supported for Swift yet. But to use this library in your project manually you should: +CocoaPods is now supported for Swift. But to use this library in your project manually you may: -1. for Projects just drag SwiftyJSON.swift to the project tree -2. for Workspaces you may include the whole SwiftyJSON.xcodeproj as suggested by @garnett +1. for Projects, just drag SwiftyJSON.swift to the project tree +2. for Workspaces, include the whole SwiftyJSON.xcodeproj (as suggested by @garnett) ## Usage @@ -152,7 +152,7 @@ Use subscript to get/set value in Array or Dicitonary * If json is a dictionary, it will get `nil` without the reason. * If json is not an array or a dictionary, the app may crash with the wrong selector exception. -It will never happen in SwiftyJSON +It will never happen in SwiftyJSON. ```swift let json = JSON(["name", "age"]) From c7319f07a35dd55aba95be4e7724bbe7f177b0f9 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Fri, 9 Jan 2015 11:59:09 +0800 Subject: [PATCH 083/470] add travis ci support --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..e42fd29b --- /dev/null +++ b/.travis.yml @@ -0,0 +1,2 @@ +language: swift +script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme SwiftyJSON -destination \"platform=iOS Simulator,name=iPhone 5\"" From 4ca2b62574d9d04a814874a3483b0b10c733dd4b Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Fri, 9 Jan 2015 12:05:22 +0800 Subject: [PATCH 084/470] travis ci trigger --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e42fd29b..0da22a6d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,3 @@ language: swift + script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme SwiftyJSON -destination \"platform=iOS Simulator,name=iPhone 5\"" From 81929fcf52ae416da87eedd060895601ee89846b Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Fri, 9 Jan 2015 12:07:28 +0800 Subject: [PATCH 085/470] test travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0da22a6d..10fefc91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,3 @@ -language: swift +language: objective-c script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme SwiftyJSON -destination \"platform=iOS Simulator,name=iPhone 5\"" From 8edd3e252bdcc520f28f3b483b6cfe235b0e0f5b Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Fri, 9 Jan 2015 12:14:52 +0800 Subject: [PATCH 086/470] trigger travis first build --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 10fefc91..ed62108f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,2 @@ language: objective-c - script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme SwiftyJSON -destination \"platform=iOS Simulator,name=iPhone 5\"" From 7ea630c5842b9aee6a6a0062fb9ec27cbb076a38 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Sat, 10 Jan 2015 14:57:10 +0800 Subject: [PATCH 087/470] using with cocoapods require >= iOS 8 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 3d4af345..c7e99be1 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.authors = { "lingoer" => "lingoerer@gmail.com", "tangplin" => "tangplin@gmail.com" } s.osx.deployment_target = "10.9" - s.ios.deployment_target = "7.0" + s.ios.deployment_target = "8.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.2"} s.source_files = "Source/*.swift" end From 2c0f54394f473cfee0cd1cd35d599f8f6f0f5c9e Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Sat, 10 Jan 2015 15:04:29 +0800 Subject: [PATCH 088/470] change podspec to 2.1.3 --- SwiftyJSON.podspec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index c7e99be1..0aa72e49 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,13 +1,14 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.1.2" + s.version = "2.1.3" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } s.authors = { "lingoer" => "lingoerer@gmail.com", "tangplin" => "tangplin@gmail.com" } + s.requires_arc = true s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.2"} + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.3"} s.source_files = "Source/*.swift" end From 63133c2d5c1be69ee0d7ac48e3175d663a745dc5 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Sat, 10 Jan 2015 15:24:40 +0800 Subject: [PATCH 089/470] Update README.md Add description for CocoaPods --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 24038a19..d83982a3 100644 --- a/README.md +++ b/README.md @@ -86,10 +86,22 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ##Integration +####Carthage You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding `github "SwiftyJSON/SwiftyJSON" >= 2.1.2` to your `Cartfile` -CocoaPods is now supported for Swift. But to use this library in your project manually you may: +####CocoaPods +CocoaPods beta release now supports for Swift. +```ruby +pod 'SwiftyJSON', '2.1.3' +``` +Note that it needs you to install CocoaPods pre-released version, and requires your iOS deploy target >= 8.0: +```bash +[sudo] gem install cocoapods --pre +``` +####Manually + +To use this library in your project manually you may: 1. for Projects, just drag SwiftyJSON.swift to the project tree 2. for Workspaces, include the whole SwiftyJSON.xcodeproj (as suggested by @garnett) From bad58520dad25de03e8104c2a927d818bf201969 Mon Sep 17 00:00:00 2001 From: Sean Cheng Date: Tue, 20 Jan 2015 12:40:16 +0800 Subject: [PATCH 090/470] Fix Carthage on OS X Support --- SwiftyJSON.xcodeproj/project.pbxproj | 30 +++-- .../xcschemes/SwiftyJSON OSX.xcscheme | 110 ++++++++++++++++++ ...yJSON.xcscheme => SwiftyJSON iOS.xcscheme} | 16 +-- 3 files changed, 132 insertions(+), 24 deletions(-) create mode 100644 SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme rename SwiftyJSON.xcodeproj/xcshareddata/xcschemes/{SwiftyJSON.xcscheme => SwiftyJSON iOS.xcscheme} (90%) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 2a1c20ae..56382dd8 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -209,9 +209,9 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 2E4FEFDA19575BE100351305 /* SwiftyJSON */ = { + 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */ = { isa = PBXNativeTarget; - buildConfigurationList = 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON" */; + buildConfigurationList = 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */; buildPhases = ( 2E4FEFD619575BE100351305 /* Sources */, 2E4FEFD719575BE100351305 /* Frameworks */, @@ -222,7 +222,7 @@ ); dependencies = ( ); - name = SwiftyJSON; + name = "SwiftyJSON iOS"; productName = SwiftyJSON; productReference = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; @@ -245,9 +245,9 @@ productReference = 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */ = { + 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSON OSX */ = { isa = PBXNativeTarget; - buildConfigurationList = 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSX" */; + buildConfigurationList = 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */; buildPhases = ( 4EC1C1C41A0C1A2D0026ED0B /* Sources */, 4EC1C1C51A0C1A2D0026ED0B /* Frameworks */, @@ -258,7 +258,7 @@ ); dependencies = ( ); - name = SwiftyJSONOSX; + name = "SwiftyJSON OSX"; productName = SwiftyJSONOSX; productReference = 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; @@ -316,9 +316,9 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 2E4FEFDA19575BE100351305 /* SwiftyJSON */, + 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */, 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, - 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */, + 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSON OSX */, 4EC1C1D21A0C1A2D0026ED0B /* SwiftyJSONOSXTests */, ); }; @@ -419,12 +419,12 @@ /* Begin PBXTargetDependency section */ 2E4FEFE919575BE100351305 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 2E4FEFDA19575BE100351305 /* SwiftyJSON */; + target = 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */; targetProxy = 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */; }; 4EC1C1D61A0C1A2D0026ED0B /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSONOSX */; + target = 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSON OSX */; targetProxy = 4EC1C1D51A0C1A2D0026ED0B /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -530,7 +530,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; }; name = Debug; @@ -548,7 +548,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; }; name = Release; @@ -588,7 +588,6 @@ 4EC1C1DD1A0C1A2D0026ED0B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -613,7 +612,6 @@ 4EC1C1DE1A0C1A2D0026ED0B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; @@ -685,7 +683,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON" */ = { + 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( 2E4FEFF219575BE100351305 /* Debug */, @@ -703,7 +701,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSX" */ = { + 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */ = { isa = XCConfigurationList; buildConfigurations = ( 4EC1C1DD1A0C1A2D0026ED0B /* Debug */, diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme new file mode 100644 index 00000000..e575d84f --- /dev/null +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme similarity index 90% rename from SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.xcscheme rename to SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme index 158db480..30b9d177 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme @@ -15,8 +15,8 @@ @@ -57,8 +57,8 @@ @@ -76,8 +76,8 @@ @@ -94,8 +94,8 @@ From 94b692c957acb7999cc04c22bc9985adfc956f6c Mon Sep 17 00:00:00 2001 From: Sean Cheng Date: Tue, 20 Jan 2015 12:58:46 +0800 Subject: [PATCH 091/470] Fix Carthage on OSX Support --- Source/Info-OSX.plist | 26 ++ Source/Info.plist | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 414 ++++++++---------- .../xcschemes/SwiftyJSON OSX.xcscheme | 16 +- .../xcschemes/SwiftyJSON iOS.xcscheme | 8 +- 5 files changed, 230 insertions(+), 236 deletions(-) create mode 100644 Source/Info-OSX.plist diff --git a/Source/Info-OSX.plist b/Source/Info-OSX.plist new file mode 100644 index 00000000..5d09593a --- /dev/null +++ b/Source/Info-OSX.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + diff --git a/Source/Info.plist b/Source/Info.plist index 20511ffd..051fe5f9 100644 --- a/Source/Info.plist +++ b/Source/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.swiftyjson.${PRODUCT_NAME:rfc1034identifier} + com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 56382dd8..f599da28 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -7,25 +7,11 @@ objects = { /* Begin PBXBuildFile section */ + 030B6CCE1A6E16E900C2D4F1 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */; }; + 030B6CDD1A6E172B00C2D4F1 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 030B6CDE1A6E172B00C2D4F1 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; - 4EC1C1D41A0C1A2D0026ED0B /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */; }; - 4EC1C1E21A0C1A6E0026ED0B /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4EC1C1E31A0C1A750026ED0B /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; - 4EC1C1E41A0C1A800026ED0B /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; - 4EC1C1E51A0C1A800026ED0B /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; - 4EC1C1E61A0C1A800026ED0B /* BaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */; }; - 4EC1C1E71A0C1A800026ED0B /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; - 4EC1C1E81A0C1A800026ED0B /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; - 4EC1C1E91A0C1A800026ED0B /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; - 4EC1C1EA1A0C1A800026ED0B /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; - 4EC1C1EB1A0C1A800026ED0B /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; - 4EC1C1EC1A0C1A800026ED0B /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; - 4EC1C1ED1A0C1A800026ED0B /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; - 4EC1C1EE1A0C1A800026ED0B /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; - 4EC1C1EF1A0C1A800026ED0B /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; - 4EC1C1F01A0C1A800026ED0B /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; - 4EC1C1F11A0C1A800026ED0B /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; @@ -44,29 +30,30 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */ = { + 030B6CCF1A6E16E900C2D4F1 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 2E4FEFD219575BE100351305 /* Project object */; proxyType = 1; - remoteGlobalIDString = 2E4FEFDA19575BE100351305; - remoteInfo = SwiftyJSON; + remoteGlobalIDString = 030B6CC21A6E16E800C2D4F1; + remoteInfo = "SwiftyJSON OSX"; }; - 4EC1C1D51A0C1A2D0026ED0B /* PBXContainerItemProxy */ = { + 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 2E4FEFD219575BE100351305 /* Project object */; proxyType = 1; - remoteGlobalIDString = 4EC1C1C81A0C1A2D0026ED0B; - remoteInfo = SwiftyJSONOSX; + remoteGlobalIDString = 2E4FEFDA19575BE100351305; + remoteInfo = SwiftyJSON; }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 030B6CCD1A6E16E900C2D4F1 /* SwiftyJSON OSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON OSXTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; @@ -86,33 +73,33 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 2E4FEFD719575BE100351305 /* Frameworks */ = { + 030B6CBF1A6E16E800C2D4F1 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; - 2E4FEFE319575BE100351305 /* Frameworks */ = { + 030B6CCA1A6E16E900C2D4F1 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */, + 030B6CCE1A6E16E900C2D4F1 /* SwiftyJSON.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; - 4EC1C1C51A0C1A2D0026ED0B /* Frameworks */ = { + 2E4FEFD719575BE100351305 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; - 4EC1C1D01A0C1A2D0026ED0B /* Frameworks */ = { + 2E4FEFE319575BE100351305 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 4EC1C1D41A0C1A2D0026ED0B /* SwiftyJSON.framework in Frameworks */, + 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -133,8 +120,8 @@ children = ( 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */, - 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */, - 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */, + 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */, + 030B6CCD1A6E16E900C2D4F1 /* SwiftyJSON OSXTests.xctest */, ); name = Products; sourceTree = ""; @@ -152,6 +139,7 @@ 2E4FEFDE19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( + 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */, 2E4FEFDF19575BE100351305 /* Info.plist */, ); name = "Supporting Files"; @@ -190,95 +178,95 @@ /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ - 2E4FEFD819575BE100351305 /* Headers */ = { + 030B6CC01A6E16E800C2D4F1 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */, + 030B6CDD1A6E172B00C2D4F1 /* SwiftyJSON.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; - 4EC1C1C61A0C1A2D0026ED0B /* Headers */ = { + 2E4FEFD819575BE100351305 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - 4EC1C1E21A0C1A6E0026ED0B /* SwiftyJSON.h in Headers */, + 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */ = { + 030B6CC21A6E16E800C2D4F1 /* SwiftyJSON OSX */ = { isa = PBXNativeTarget; - buildConfigurationList = 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */; + buildConfigurationList = 030B6CD61A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */; buildPhases = ( - 2E4FEFD619575BE100351305 /* Sources */, - 2E4FEFD719575BE100351305 /* Frameworks */, - 2E4FEFD819575BE100351305 /* Headers */, - 2E4FEFD919575BE100351305 /* Resources */, + 030B6CBE1A6E16E800C2D4F1 /* Sources */, + 030B6CBF1A6E16E800C2D4F1 /* Frameworks */, + 030B6CC01A6E16E800C2D4F1 /* Headers */, + 030B6CC11A6E16E800C2D4F1 /* Resources */, ); buildRules = ( ); dependencies = ( ); - name = "SwiftyJSON iOS"; - productName = SwiftyJSON; - productReference = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; + name = "SwiftyJSON OSX"; + productName = "SwiftyJSON OSX"; + productReference = 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; }; - 2E4FEFE519575BE100351305 /* SwiftyJSONTests */ = { + 030B6CCC1A6E16E900C2D4F1 /* SwiftyJSON OSXTests */ = { isa = PBXNativeTarget; - buildConfigurationList = 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */; + buildConfigurationList = 030B6CD91A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSXTests" */; buildPhases = ( - 2E4FEFE219575BE100351305 /* Sources */, - 2E4FEFE319575BE100351305 /* Frameworks */, - 2E4FEFE419575BE100351305 /* Resources */, + 030B6CC91A6E16E900C2D4F1 /* Sources */, + 030B6CCA1A6E16E900C2D4F1 /* Frameworks */, + 030B6CCB1A6E16E900C2D4F1 /* Resources */, ); buildRules = ( ); dependencies = ( - 2E4FEFE919575BE100351305 /* PBXTargetDependency */, + 030B6CD01A6E16E900C2D4F1 /* PBXTargetDependency */, ); - name = SwiftyJSONTests; - productName = SwiftyJSONTests; - productReference = 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */; + name = "SwiftyJSON OSXTests"; + productName = "SwiftyJSON OSXTests"; + productReference = 030B6CCD1A6E16E900C2D4F1 /* SwiftyJSON OSXTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSON OSX */ = { + 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */ = { isa = PBXNativeTarget; - buildConfigurationList = 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */; + buildConfigurationList = 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */; buildPhases = ( - 4EC1C1C41A0C1A2D0026ED0B /* Sources */, - 4EC1C1C51A0C1A2D0026ED0B /* Frameworks */, - 4EC1C1C61A0C1A2D0026ED0B /* Headers */, - 4EC1C1C71A0C1A2D0026ED0B /* Resources */, + 2E4FEFD619575BE100351305 /* Sources */, + 2E4FEFD719575BE100351305 /* Frameworks */, + 2E4FEFD819575BE100351305 /* Headers */, + 2E4FEFD919575BE100351305 /* Resources */, ); buildRules = ( ); dependencies = ( ); - name = "SwiftyJSON OSX"; - productName = SwiftyJSONOSX; - productReference = 4EC1C1C91A0C1A2D0026ED0B /* SwiftyJSON.framework */; + name = "SwiftyJSON iOS"; + productName = SwiftyJSON; + productReference = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; }; - 4EC1C1D21A0C1A2D0026ED0B /* SwiftyJSONOSXTests */ = { + 2E4FEFE519575BE100351305 /* SwiftyJSONTests */ = { isa = PBXNativeTarget; - buildConfigurationList = 4EC1C1DF1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSXTests" */; + buildConfigurationList = 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */; buildPhases = ( - 4EC1C1CF1A0C1A2D0026ED0B /* Sources */, - 4EC1C1D01A0C1A2D0026ED0B /* Frameworks */, - 4EC1C1D11A0C1A2D0026ED0B /* Resources */, + 2E4FEFE219575BE100351305 /* Sources */, + 2E4FEFE319575BE100351305 /* Frameworks */, + 2E4FEFE419575BE100351305 /* Resources */, ); buildRules = ( ); dependencies = ( - 4EC1C1D61A0C1A2D0026ED0B /* PBXTargetDependency */, + 2E4FEFE919575BE100351305 /* PBXTargetDependency */, ); - name = SwiftyJSONOSXTests; - productName = SwiftyJSONOSXTests; - productReference = 4EC1C1D31A0C1A2D0026ED0B /* SwiftyJSONOSXTests.xctest */; + name = SwiftyJSONTests; + productName = SwiftyJSONTests; + productReference = 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -289,6 +277,12 @@ attributes = { LastUpgradeCheck = 0600; TargetAttributes = { + 030B6CC21A6E16E800C2D4F1 = { + CreatedOnToolsVersion = 6.2; + }; + 030B6CCC1A6E16E900C2D4F1 = { + CreatedOnToolsVersion = 6.2; + }; 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; }; @@ -296,12 +290,6 @@ CreatedOnToolsVersion = 6.0; TestTargetID = 2E4FEFDA19575BE100351305; }; - 4EC1C1C81A0C1A2D0026ED0B = { - CreatedOnToolsVersion = 6.1; - }; - 4EC1C1D21A0C1A2D0026ED0B = { - CreatedOnToolsVersion = 6.1; - }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -318,46 +306,60 @@ targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */, 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, - 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSON OSX */, - 4EC1C1D21A0C1A2D0026ED0B /* SwiftyJSONOSXTests */, + 030B6CC21A6E16E800C2D4F1 /* SwiftyJSON OSX */, + 030B6CCC1A6E16E900C2D4F1 /* SwiftyJSON OSXTests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 2E4FEFD919575BE100351305 /* Resources */ = { + 030B6CC11A6E16E800C2D4F1 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; - 2E4FEFE419575BE100351305 /* Resources */ = { + 030B6CCB1A6E16E900C2D4F1 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - A885D1DC19CFCFF0002FD4C3 /* Tests.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; - 4EC1C1C71A0C1A2D0026ED0B /* Resources */ = { + 2E4FEFD919575BE100351305 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( ); runOnlyForDeploymentPostprocessing = 0; }; - 4EC1C1D11A0C1A2D0026ED0B /* Resources */ = { + 2E4FEFE419575BE100351305 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4EC1C1E41A0C1A800026ED0B /* Tests.json in Resources */, + A885D1DC19CFCFF0002FD4C3 /* Tests.json in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 030B6CBE1A6E16E800C2D4F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 030B6CDE1A6E172B00C2D4F1 /* SwiftyJSON.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 030B6CC91A6E16E900C2D4F1 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 2E4FEFD619575BE100351305 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -386,50 +388,104 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 4EC1C1C41A0C1A2D0026ED0B /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 4EC1C1E31A0C1A750026ED0B /* SwiftyJSON.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 4EC1C1CF1A0C1A2D0026ED0B /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 4EC1C1E71A0C1A800026ED0B /* SequenceTypeTests.swift in Sources */, - 4EC1C1EC1A0C1A800026ED0B /* ComparableTests.swift in Sources */, - 4EC1C1EE1A0C1A800026ED0B /* NumberTests.swift in Sources */, - 4EC1C1EB1A0C1A800026ED0B /* RawRepresentableTests.swift in Sources */, - 4EC1C1E61A0C1A800026ED0B /* BaseTests.swift in Sources */, - 4EC1C1F01A0C1A800026ED0B /* DictionaryTests.swift in Sources */, - 4EC1C1E51A0C1A800026ED0B /* PerformanceTests.swift in Sources */, - 4EC1C1EA1A0C1A800026ED0B /* LiteralConvertibleTests.swift in Sources */, - 4EC1C1E81A0C1A800026ED0B /* PrintableTests.swift in Sources */, - 4EC1C1ED1A0C1A800026ED0B /* StringTests.swift in Sources */, - 4EC1C1EF1A0C1A800026ED0B /* RawTests.swift in Sources */, - 4EC1C1F11A0C1A800026ED0B /* ArrayTests.swift in Sources */, - 4EC1C1E91A0C1A800026ED0B /* SubscriptTests.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 030B6CD01A6E16E900C2D4F1 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 030B6CC21A6E16E800C2D4F1 /* SwiftyJSON OSX */; + targetProxy = 030B6CCF1A6E16E900C2D4F1 /* PBXContainerItemProxy */; + }; 2E4FEFE919575BE100351305 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */; targetProxy = 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */; }; - 4EC1C1D61A0C1A2D0026ED0B /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 4EC1C1C81A0C1A2D0026ED0B /* SwiftyJSON OSX */; - targetProxy = 4EC1C1D51A0C1A2D0026ED0B /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ + 030B6CD71A6E16E900C2D4F1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "$(SRCROOT)/Source/Info-OSX.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = SwiftyJSON; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 030B6CD81A6E16E900C2D4F1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info-OSX.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = SwiftyJSON; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 030B6CDA1A6E16E900C2D4F1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "SwiftyJSON OSXTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Debug; + }; + 030B6CDB1A6E16E900C2D4F1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + INFOPLIST_FILE = "SwiftyJSON OSXTests/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Release; + }; 2E4FEFEF19575BE100351305 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -585,136 +641,48 @@ }; name = Release; }; - 4EC1C1DD1A0C1A2D0026ED0B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = YES; - PRODUCT_MODULE_NAME = SwiftyJSON; - PRODUCT_NAME = SwiftyJSON; - SDKROOT = macosx; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 4EC1C1DE1A0C1A2D0026ED0B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_MODULE_NAME = SwiftyJSON; - PRODUCT_NAME = SwiftyJSON; - SDKROOT = macosx; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 4EC1C1E01A0C1A2D0026ED0B /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_IDENTITY = "Mac Developer"; - COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; - MTL_ENABLE_DEBUG_INFO = YES; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 4EC1C1E11A0C1A2D0026ED0B /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application"; - COMBINE_HIDPI_IMAGES = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); - INFOPLIST_FILE = Tests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MACOSX_DEPLOYMENT_TARGET = 10.10; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Release; - }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */ = { + 030B6CD61A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */ = { isa = XCConfigurationList; buildConfigurations = ( - 2E4FEFEF19575BE100351305 /* Debug */, - 2E4FEFF019575BE100351305 /* Release */, + 030B6CD71A6E16E900C2D4F1 /* Debug */, + 030B6CD81A6E16E900C2D4F1 /* Release */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; }; - 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */ = { + 030B6CD91A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSXTests" */ = { isa = XCConfigurationList; buildConfigurations = ( - 2E4FEFF219575BE100351305 /* Debug */, - 2E4FEFF319575BE100351305 /* Release */, + 030B6CDA1A6E16E900C2D4F1 /* Debug */, + 030B6CDB1A6E16E900C2D4F1 /* Release */, ); defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; }; - 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */ = { + 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */ = { isa = XCConfigurationList; buildConfigurations = ( - 2E4FEFF519575BE100351305 /* Debug */, - 2E4FEFF619575BE100351305 /* Release */, + 2E4FEFEF19575BE100351305 /* Debug */, + 2E4FEFF019575BE100351305 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 4EC1C1DC1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */ = { + 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( - 4EC1C1DD1A0C1A2D0026ED0B /* Debug */, - 4EC1C1DE1A0C1A2D0026ED0B /* Release */, + 2E4FEFF219575BE100351305 /* Debug */, + 2E4FEFF319575BE100351305 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 4EC1C1DF1A0C1A2D0026ED0B /* Build configuration list for PBXNativeTarget "SwiftyJSONOSXTests" */ = { + 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */ = { isa = XCConfigurationList; buildConfigurations = ( - 4EC1C1E01A0C1A2D0026ED0B /* Debug */, - 4EC1C1E11A0C1A2D0026ED0B /* Release */, + 2E4FEFF519575BE100351305 /* Debug */, + 2E4FEFF619575BE100351305 /* Release */, ); defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme index e575d84f..2ee2f284 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -14,8 +14,8 @@ buildForAnalyzing = "YES"> @@ -56,8 +56,8 @@ @@ -75,8 +75,8 @@ @@ -93,8 +93,8 @@ diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme index 30b9d177..a4fde4d6 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme @@ -15,7 +15,7 @@ @@ -57,7 +57,7 @@ @@ -76,7 +76,7 @@ @@ -94,7 +94,7 @@ From 8cffc6486c5eede0d349602c6549054fec96f2f7 Mon Sep 17 00:00:00 2001 From: esbenvb Date: Tue, 20 Jan 2015 09:43:51 +0100 Subject: [PATCH 092/470] Update README.md Inserted a missing "if" in the error handling example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d83982a3..b8876740 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ It will never happen in SwiftyJSON. ```swift let json = JSON(["name", "age"]) -let name = json[999].string { +if let name = json[999].string { //Do something you want } else { println(json[999].error) // "Array[999] is out of bounds" From d542c44d9043c2610d4a851e0c690b3a6b14d7ba Mon Sep 17 00:00:00 2001 From: esbenvb Date: Tue, 20 Jan 2015 09:51:31 +0100 Subject: [PATCH 093/470] Update README.md Added a few more "if"s to the readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d83982a3..896eb7bc 100644 --- a/README.md +++ b/README.md @@ -168,7 +168,7 @@ It will never happen in SwiftyJSON. ```swift let json = JSON(["name", "age"]) -let name = json[999].string { +if let name = json[999].string { //Do something you want } else { println(json[999].error) // "Array[999] is out of bounds" @@ -176,7 +176,7 @@ let name = json[999].string { ``` ```swift let json = JSON(["name":"Jack", "age": 25]) -let name = json["address"].string { +if let name = json["address"].string { //Do something you want } else { println(json["address"].error) // "Dictionary["address"] does not exist" @@ -184,14 +184,14 @@ let name = json["address"].string { ``` ```swift let json = JSON(12345) -let age = json[0].string { +if let age = json[0].string { //Do something you want } else { println(json[0]) // "Array[0] failure, It is not an array" println(json[0].error) // "Array[0] failure, It is not an array" } -let name = json["name"].string { +if let name = json["name"].string { //Do something you want } else { println(json["name"]) // "Dictionary[\"name"] failure, It is not an dictionary" From c54eaa551ae06999c55131c067bb9463f860f9f4 Mon Sep 17 00:00:00 2001 From: Howard Wilson Date: Wed, 21 Jan 2015 19:52:12 +0100 Subject: [PATCH 094/470] Fix README.md nested example Username type should be NSString --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d83982a3..5744040b 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwi if let statusesArray = jsonObject as? NSArray{ if let aStatus = statusesArray[0] as? NSDictionary{ if let user = aStatus["user"] as? NSDictionary{ - if let userName = user["name"] as? NSDictionary{ + if let userName = user["name"] as? NSString{ //Finally We Got The Name } From 0d939002de0732ca024b2e5c04abadaafe5289b6 Mon Sep 17 00:00:00 2001 From: Zhixuan Lai Date: Tue, 27 Jan 2015 14:55:03 -0800 Subject: [PATCH 095/470] add missing ` in comments --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a76527eb..a0c79088 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -163,7 +163,7 @@ extension JSON: SequenceType{ } /** - If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary, otherwise return a generator over empty. + If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary`, otherwise return a generator over empty. :returns: Return a *generator* over the elements of this *sequence*. */ From b6ef388434914e08b12c74a7c799cb001202d5e1 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Wed, 28 Jan 2015 16:45:03 +0800 Subject: [PATCH 096/470] fix travis ci --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ed62108f..ef88a869 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,2 @@ language: objective-c -script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme SwiftyJSON -destination \"platform=iOS Simulator,name=iPhone 5\"" +script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme \"SwiftyJSON iOS\" -destination \"platform=iOS Simulator,name=iPhone 5\"" From 28ec80f991f6f38545f610bd31b290dcee668c66 Mon Sep 17 00:00:00 2001 From: Leslie Wu Date: Tue, 3 Feb 2015 17:17:36 -0800 Subject: [PATCH 097/470] Setter for JSON array should use arrayObject not array (which does not expose a setter) (README.md) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64465f4d..faf9ee82 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ json[0] = JSON(1) json["id"].int = 1234567890 json["coordinate"].double = 8766.766 json["name"].string = "Jack" -json.array = [1,2,3,4] +json.arrayObject = [1,2,3,4] json.dictionary = ["name":"Jack", "age":25] ``` From 28ab56bc653298111f623b1269088355f65a6b8b Mon Sep 17 00:00:00 2001 From: Leslie Wu Date: Thu, 5 Feb 2015 14:59:40 -0800 Subject: [PATCH 098/470] Allow construction of JSON from [JSON] --- Source/SwiftyJSON.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a0c79088..b151bb4b 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -83,6 +83,17 @@ public struct JSON { self.object = object } + /** + Creates a JSON from a [JSON] + + :param: jsonArray A Swift array of JSON objects + + :returns: The created JSON + */ + public init(_ jsonArray:[JSON]) { + self.init(jsonArray.map { $0.object }) + } + /// Private object private var _object: AnyObject = NSNull() /// Private type From aa39ffdac0d4a53f73009992016e94a3de660912 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki Date: Mon, 9 Feb 2015 22:44:29 +0100 Subject: [PATCH 099/470] Swift 1.2 compatibility fixes --- Source/SwiftyJSON.swift | 82 ++++++++++++++++++++--------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a0c79088..40fef595 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -139,9 +139,9 @@ extension JSON: SequenceType{ get { switch self.type { case .Array: - return (self.object as [AnyObject]).isEmpty + return (self.object as! [AnyObject]).isEmpty case .Dictionary: - return (self.object as [String : AnyObject]).isEmpty + return (self.object as! [String : AnyObject]).isEmpty default: return false } @@ -170,7 +170,7 @@ extension JSON: SequenceType{ public func generate() -> GeneratorOf <(String, JSON)> { switch self.type { case .Array: - let array_ = object as [AnyObject] + let array_ = object as! [AnyObject] var generate_ = array_.generate() var index_: Int = 0 return GeneratorOf<(String, JSON)> { @@ -181,7 +181,7 @@ extension JSON: SequenceType{ } } case .Dictionary: - let dictionary_ = object as [String : AnyObject] + let dictionary_ = object as! [String : AnyObject] var generate_ = dictionary_.generate() return GeneratorOf<(String, JSON)> { if let (key_: String, value_: AnyObject) = generate_.next() { @@ -221,7 +221,7 @@ extension JSON { return errorResult_ } - let array_ = self.object as [AnyObject] + let array_ = self.object as! [AnyObject] if index >= 0 && index < array_.count { return JSON(array_[index]) @@ -233,7 +233,7 @@ extension JSON { } set { if self.type == .Array { - var array_ = self.object as [AnyObject] + var array_ = self.object as! [AnyObject] if array_.count > index { array_[index] = newValue.object self.object = array_ @@ -259,7 +259,7 @@ extension JSON { } set { if self.type == .Dictionary { - var dictionary_ = self.object as [String : AnyObject] + var dictionary_ = self.object as! [String : AnyObject] dictionary_[key] = newValue.object self.object = dictionary_ } @@ -270,16 +270,16 @@ extension JSON { private subscript(#sub: SubscriptType) -> JSON { get { if sub is String { - return self[key:sub as String] + return self[key:sub as! String] } else { - return self[index:sub as Int] + return self[index:sub as! Int] } } set { if sub is String { - self[key:sub as String] = newValue + self[key:sub as! String] = newValue } else { - self[index:sub as Int] = newValue + self[index:sub as! Int] = newValue } } } @@ -440,16 +440,16 @@ extension JSON: RawRepresentable { switch self.type { case .Array, .Dictionary: if let data = self.rawData(options: opt) { - return NSString(data: data, encoding: encoding) + return NSString(data: data, encoding: encoding) as? String } else { return nil } case .String: - return (self.object as String) + return (self.object as! String) case .Number: - return (self.object as NSNumber).stringValue + return (self.object as! NSNumber).stringValue case .Bool: - return (self.object as Bool).description + return (self.object as! Bool).description case .Null: return "null" default: @@ -483,7 +483,7 @@ extension JSON { public var array: [JSON]? { get { if self.type == .Array { - return map(self.object as [AnyObject]){ JSON($0) } + return map(self.object as! [AnyObject]){ JSON($0) } } else { return nil } @@ -533,7 +533,7 @@ extension JSON { public var dictionary: [String : JSON]? { get { if self.type == .Dictionary { - return _map(self.object as [String : AnyObject]){ JSON($0) } + return _map(self.object as! [String : AnyObject]){ JSON($0) } } else { return nil } @@ -634,11 +634,11 @@ extension JSON { get { switch self.type { case .String: - return self.object as String + return self.object as! String case .Number: return self.object.stringValue case .Bool: - return (self.object as Bool).description + return (self.object as! Bool).description default: return "" } @@ -672,15 +672,15 @@ extension JSON { get { switch self.type { case .String: - let scanner = NSScanner(string: self.object as String) + let scanner = NSScanner(string: self.object as! String) if scanner.scanDouble(nil){ if (scanner.atEnd) { - return NSNumber(double:(self.object as NSString).doubleValue) + return NSNumber(double:(self.object as! NSString).doubleValue) } } return NSNumber(double: 0.0) case .Number, .Bool: - return self.object as NSNumber + return self.object as! NSNumber default: return NSNumber(double: 0.0) } @@ -1008,15 +1008,15 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as NSNumber) == (rhs.object as NSNumber) + return (lhs.object as! NSNumber) == (rhs.object as! NSNumber) case (.String, .String): - return (lhs.object as String) == (rhs.object as String) + return (lhs.object as! String) == (rhs.object as! String) case (.Bool, .Bool): - return (lhs.object as Bool) == (rhs.object as Bool) + return (lhs.object as! Bool) == (rhs.object as! Bool) case (.Array, .Array): - return (lhs.object as NSArray) == (rhs.object as NSArray) + return (lhs.object as! NSArray) == (rhs.object as! NSArray) case (.Dictionary, .Dictionary): - return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) + return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) case (.Null, .Null): return true default: @@ -1028,15 +1028,15 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as NSNumber) <= (rhs.object as NSNumber) + return (lhs.object as! NSNumber) <= (rhs.object as! NSNumber) case (.String, .String): - return (lhs.object as String) <= (rhs.object as String) + return (lhs.object as! String) <= (rhs.object as! String) case (.Bool, .Bool): - return (lhs.object as Bool) == (rhs.object as Bool) + return (lhs.object as! Bool) == (rhs.object as! Bool) case (.Array, .Array): - return (lhs.object as NSArray) == (rhs.object as NSArray) + return (lhs.object as! NSArray) == (rhs.object as! NSArray) case (.Dictionary, .Dictionary): - return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) + return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) case (.Null, .Null): return true default: @@ -1048,15 +1048,15 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as NSNumber) >= (rhs.object as NSNumber) + return (lhs.object as! NSNumber) >= (rhs.object as! NSNumber) case (.String, .String): - return (lhs.object as String) >= (rhs.object as String) + return (lhs.object as! String) >= (rhs.object as! String) case (.Bool, .Bool): - return (lhs.object as Bool) == (rhs.object as Bool) + return (lhs.object as! Bool) == (rhs.object as! Bool) case (.Array, .Array): - return (lhs.object as NSArray) == (rhs.object as NSArray) + return (lhs.object as! NSArray) == (rhs.object as! NSArray) case (.Dictionary, .Dictionary): - return (lhs.object as NSDictionary) == (rhs.object as NSDictionary) + return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) case (.Null, .Null): return true default: @@ -1068,9 +1068,9 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as NSNumber) > (rhs.object as NSNumber) + return (lhs.object as! NSNumber) > (rhs.object as! NSNumber) case (.String, .String): - return (lhs.object as String) > (rhs.object as String) + return (lhs.object as! String) > (rhs.object as! String) default: return false } @@ -1080,9 +1080,9 @@ public func <(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as NSNumber) < (rhs.object as NSNumber) + return (lhs.object as! NSNumber) < (rhs.object as! NSNumber) case (.String, .String): - return (lhs.object as String) < (rhs.object as String) + return (lhs.object as! String) < (rhs.object as! String) default: return false } From 0691445da4c4a94484621919c347d7b69f9598fe Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Thu, 12 Feb 2015 11:45:49 +0800 Subject: [PATCH 100/470] Fixed test and example's compilation errors in xcode 6.3 beta. --- Example/AppDelegate.swift | 4 ++-- Example/ViewController.swift | 6 +++--- Tests/BaseTests.swift | 4 ++-- Tests/DictionaryTests.swift | 6 +++--- Tests/NumberTests.swift | 6 +++--- Tests/RawRepresentableTests.swift | 32 ++++++++++++++--------------- Tests/SequenceTypeTests.swift | 34 +++++++++++++++---------------- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index ee00e609..8086ee3f 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -30,8 +30,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - let navigationController = self.window?.rootViewController as UINavigationController - let viewController = navigationController.topViewController as ViewController + let navigationController = self.window?.rootViewController as! UINavigationController + let viewController = navigationController.topViewController as! ViewController if let file = NSBundle(forClass:AppDelegate.self).pathForResource("SwiftyJSONTests", ofType: "json") { let data = NSData(contentsOfFile: file)! diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 9d578eab..6c3cb19d 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -43,7 +43,7 @@ class ViewController: UITableViewController { } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier("JSONCell", forIndexPath: indexPath) as UITableViewCell + let cell = tableView.dequeueReusableCellWithIdentifier("JSONCell", forIndexPath: indexPath) as! UITableViewCell var row = indexPath.row @@ -52,8 +52,8 @@ class ViewController: UITableViewController { cell.textLabel?.text = "\(row)" cell.detailTextLabel?.text = self.json.arrayValue.description case .Dictionary: - let key: AnyObject = (self.json.object as NSDictionary).allKeys[row] - let value = self.json[key as String] + let key: AnyObject = (self.json.object as! NSDictionary).allKeys[row] + let value = self.json[key as! String] cell.textLabel?.text = "\(key)" cell.detailTextLabel?.text = value.description default: diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 8ca6aac7..413447d5 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -141,7 +141,7 @@ class BaseTests: XCTestCase { } var index = 0 - let keys = (json[1].dictionaryObject! as NSDictionary).allKeys as [String] + let keys = (json[1].dictionaryObject! as NSDictionary).allKeys as! [String] for (aKey, aJson) in json[1] { XCTAssertEqual(aKey, keys[index]) XCTAssertEqual(aJson, json[1][keys[index]]) @@ -202,7 +202,7 @@ class BaseTests: XCTestCase { XCTAssertEqual(JSON(Int(Int.max)).description,"\(Int.max)") XCTAssertEqual(JSON(NSNumber(long: Int.min)).description,"\(Int.min)") - XCTAssertEqual(JSON(NSNumber(unsignedLong: ULONG_MAX)).description,"\(ULONG_MAX)") + XCTAssertEqual(JSON(NSNumber(unsignedLong: UInt.max)).description,"\(UInt.max)") XCTAssertEqual(JSON(NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") XCTAssertEqual(JSON(NSNumber(longLong: Int64.max)).description,"\(Int64.max)") XCTAssertEqual(JSON(NSNumber(unsignedLongLong: UInt64.max)).description,"\(UInt64.max)") diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index d8762122..b0d26b38 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -41,15 +41,15 @@ class DictionaryTests: XCTestCase { XCTAssertTrue(json.dictionaryValue["null"] == nil) XCTAssertTrue(JSON.nullJSON.dictionaryValue == [:]) //dictionaryObject - XCTAssertEqual(json.dictionaryObject!["number"]! as Double, 9823.212) + XCTAssertEqual(json.dictionaryObject!["number"]! as! Double, 9823.212) XCTAssertTrue(json.dictionaryObject!["null"] == nil) XCTAssertTrue(JSON.nullJSON.dictionaryObject == nil) } func testSetter() { var json:JSON = ["test":"case"] - XCTAssertEqual(json.dictionaryObject! as [String : String], ["test":"case"]) + XCTAssertEqual(json.dictionaryObject! as! [String : String], ["test":"case"]) json.dictionaryObject = ["name":"NAME"] - XCTAssertEqual(json.dictionaryObject! as [String : String], ["name":"NAME"]) + XCTAssertEqual(json.dictionaryObject! as! [String : String], ["name":"NAME"]) } } diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 823de08b..5254c348 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -37,7 +37,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 123456789.0987654321) json.number = nil XCTAssertEqual(json.numberValue, 0) - XCTAssertEqual(json.object as NSNull, NSNull()) + XCTAssertEqual(json.object as! NSNull, NSNull()) XCTAssertTrue(json.number == nil) json.numberValue = 2.9876 XCTAssertEqual(json.number!, 2.9876) @@ -119,7 +119,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.boolValue == false) XCTAssertTrue(json.intValue == 0) XCTAssertEqual(json.numberValue, 0) - XCTAssertEqual(json.object as NSNull, NSNull()) + XCTAssertEqual(json.object as! NSNull, NSNull()) XCTAssertTrue(json.int == nil) json.intValue = 76543 @@ -144,7 +144,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.boolValue == false) XCTAssertTrue(json.uIntValue == 0) XCTAssertEqual(json.numberValue, 0) - XCTAssertEqual(json.object as NSNull, NSNull()) + XCTAssertEqual(json.object as! NSNull, NSNull()) XCTAssertTrue(json.uInt == nil) json.uIntValue = 76543 diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index cedcf771..038264e0 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -35,10 +35,10 @@ class RawRepresentableTests: XCTestCase { XCTAssertTrue(json.floatValue == 948394394.347384) var object: AnyObject = json.rawValue - XCTAssertEqual(object as Int, 948394394) - XCTAssertEqual(object as Double, 948394394.347384) - XCTAssertTrue(object as Float == 948394394.347384) - XCTAssertEqual(object as NSNumber, 948394394.347384) + XCTAssertEqual(object as! Int, 948394394) + XCTAssertEqual(object as! Double, 948394394.347384) + XCTAssertTrue(object as! Float == 948394394.347384) + XCTAssertEqual(object as! NSNumber, 948394394.347384) } func testBool() { @@ -51,16 +51,16 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(jsonFalse.boolValue, false) var objectTrue: AnyObject = jsonTrue.rawValue - XCTAssertEqual(objectTrue as Int, 1) - XCTAssertEqual(objectTrue as Double, 1.0) - XCTAssertEqual(objectTrue as Bool, true) - XCTAssertEqual(objectTrue as NSNumber, NSNumber(bool: true)) + XCTAssertEqual(objectTrue as! Int, 1) + XCTAssertEqual(objectTrue as! Double, 1.0) + XCTAssertEqual(objectTrue as! Bool, true) + XCTAssertEqual(objectTrue as! NSNumber, NSNumber(bool: true)) var objectFalse: AnyObject = jsonFalse.rawValue - XCTAssertEqual(objectFalse as Int, 0) - XCTAssertEqual(objectFalse as Double, 0.0) - XCTAssertEqual(objectFalse as Bool, false) - XCTAssertEqual(objectFalse as NSNumber, NSNumber(bool: false)) + XCTAssertEqual(objectFalse as! Int, 0) + XCTAssertEqual(objectFalse as! Double, 0.0) + XCTAssertEqual(objectFalse as! Bool, false) + XCTAssertEqual(objectFalse as! NSNumber, NSNumber(bool: false)) } func testString() { @@ -73,13 +73,13 @@ class RawRepresentableTests: XCTestCase { XCTAssertTrue(json.null == nil) XCTAssertTrue(json.error == nil) XCTAssertTrue(json.type == .String) - XCTAssertEqual(json.object as String, string) + XCTAssertEqual(json.object as! String, string) } else { XCTFail("Should not run into here") } let object: AnyObject = JSON(rawValue: string)!.rawValue - XCTAssertEqual(object as String, string) + XCTAssertEqual(object as! String, string) } func testNil() { @@ -95,7 +95,7 @@ class RawRepresentableTests: XCTestCase { } let object: AnyObject = JSON(rawValue: array)!.rawValue - XCTAssertTrue(array == object as NSArray) + XCTAssertTrue(array == object as! NSArray) } func testDictionary() { @@ -105,6 +105,6 @@ class RawRepresentableTests: XCTestCase { } let object: AnyObject = JSON(rawValue: dictionary)!.rawValue - XCTAssertTrue(dictionary == object as NSDictionary) + XCTAssertTrue(dictionary == object as! NSDictionary) } } diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index b13c4a90..526281d9 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -107,8 +107,8 @@ class SequenceTypeTests: XCTestCase { index++ } XCTAssertEqual(index, 4) - XCTAssertEqual(array[0] as String, "aoo") - XCTAssertEqual(array[2] as NSNull, NSNull()) + XCTAssertEqual(array[0] as! String, "aoo") + XCTAssertEqual(array[2] as! NSNull, NSNull()) } func testArrayAllDictionary() { @@ -124,11 +124,11 @@ class SequenceTypeTests: XCTestCase { index++ } XCTAssertEqual(index, 3) - XCTAssertEqual((array[0] as [String : Int])["1"]!, 1) - XCTAssertEqual((array[0] as [String : Int])["2"]!, 2) - XCTAssertEqual((array[1] as [String : String])["a"]!, "A") - XCTAssertEqual((array[1] as [String : String])["b"]!, "B") - XCTAssertEqual((array[2] as [String : NSNull])["null"]!, NSNull()) + XCTAssertEqual((array[0] as! [String : Int])["1"]!, 1) + XCTAssertEqual((array[0] as! [String : Int])["2"]!, 2) + XCTAssertEqual((array[1] as! [String : String])["a"]!, "A") + XCTAssertEqual((array[1] as! [String : String])["b"]!, "B") + XCTAssertEqual((array[2] as! [String : NSNull])["null"]!, NSNull()) } func testDictionaryAllNumber() { @@ -195,9 +195,9 @@ class SequenceTypeTests: XCTestCase { } XCTAssertEqual(index, 4) - XCTAssertEqual(dictionary["a"]! as String, "aoo") - XCTAssertEqual(dictionary["bb"]! as String, "bpp") - XCTAssertEqual(dictionary["null"]! as NSNull, NSNull()) + XCTAssertEqual(dictionary["a"]! as! String, "aoo") + XCTAssertEqual(dictionary["bb"]! as! String, "bpp") + XCTAssertEqual(dictionary["null"]! as! NSNull, NSNull()) } func testDictionaryAllArray() { @@ -214,12 +214,12 @@ class SequenceTypeTests: XCTestCase { } XCTAssertEqual(index, 3) - XCTAssertEqual((dictionary["Number"] as NSArray)[0] as Int, 1) - XCTAssertEqual((dictionary["Number"] as NSArray)[1] as Double, 2.123456) - XCTAssertEqual((dictionary["String"] as NSArray)[0] as String, "aa") - XCTAssertEqual((dictionary["Mix"] as NSArray)[0] as Bool, true) - XCTAssertEqual((dictionary["Mix"] as NSArray)[1] as String, "766") - XCTAssertEqual((dictionary["Mix"] as NSArray)[2] as NSNull, NSNull()) - XCTAssertEqual((dictionary["Mix"] as NSArray)[3] as Double, 655231.9823) + XCTAssertEqual((dictionary["Number"] as! NSArray)[0] as! Int, 1) + XCTAssertEqual((dictionary["Number"] as! NSArray)[1] as! Double, 2.123456) + XCTAssertEqual((dictionary["String"] as! NSArray)[0] as! String, "aa") + XCTAssertEqual((dictionary["Mix"] as! NSArray)[0] as! Bool, true) + XCTAssertEqual((dictionary["Mix"] as! NSArray)[1] as! String, "766") + XCTAssertEqual((dictionary["Mix"] as! NSArray)[2] as! NSNull, NSNull()) + XCTAssertEqual((dictionary["Mix"] as! NSArray)[3] as! Double, 655231.9823) } } From 0e11e213dd1b6f550b17a3fbd3eb62ef92c6e85f Mon Sep 17 00:00:00 2001 From: Aron Cedercrantz Date: Sun, 15 Feb 2015 16:46:14 +0100 Subject: [PATCH 101/470] Remove SwiftJSON.xcodeproj/xcuserdata - It should not be committed. - The current .gitignore file ignores this path. --- .../xcschemes/SwiftyJSON-OSX.xcscheme | 69 ------------------- .../xcschemes/SwiftyJSON.xcscheme | 69 ------------------- .../xcschemes/xcschememanagement.plist | 42 ----------- 3 files changed, 180 deletions(-) delete mode 100644 SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON-OSX.xcscheme delete mode 100644 SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON.xcscheme delete mode 100644 SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/xcschememanagement.plist diff --git a/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON-OSX.xcscheme b/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON-OSX.xcscheme deleted file mode 100644 index 3d8f288a..00000000 --- a/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON-OSX.xcscheme +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON.xcscheme b/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON.xcscheme deleted file mode 100644 index 8e41d518..00000000 --- a/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/SwiftyJSON.xcscheme +++ /dev/null @@ -1,69 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/xcschememanagement.plist b/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100644 index ef313fc5..00000000 --- a/SwiftyJSON.xcodeproj/xcuserdata/lebedzeu.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,42 +0,0 @@ - - - - - SchemeUserState - - SwiftyJSON-OSX.xcscheme - - orderHint - 1 - - SwiftyJSON.xcscheme - - orderHint - 0 - - - SuppressBuildableAutocreation - - 2E4FEFDA19575BE100351305 - - primary - - - 2E4FEFE519575BE100351305 - - primary - - - 2E4FF00119575CE600351305 - - primary - - - 2E4FF00B19575CE600351305 - - primary - - - - - From dd129a37b479badbc6b8440f5c92d7d3358b2520 Mon Sep 17 00:00:00 2001 From: Aron Cedercrantz Date: Sun, 15 Feb 2015 17:32:29 +0100 Subject: [PATCH 102/470] Remove SwiftJSON OS X targets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Both the framework and tests targets. - So that we’re in a clean state when re-creating them. --- SwiftyJSON.xcodeproj/project.pbxproj | 213 ------------------ .../xcschemes/SwiftyJSON OSX.xcscheme | 110 --------- 2 files changed, 323 deletions(-) delete mode 100644 SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index f599da28..8a6a0ea1 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -7,9 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 030B6CCE1A6E16E900C2D4F1 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */; }; - 030B6CDD1A6E172B00C2D4F1 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 030B6CDE1A6E172B00C2D4F1 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; @@ -30,13 +27,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 030B6CCF1A6E16E900C2D4F1 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 2E4FEFD219575BE100351305 /* Project object */; - proxyType = 1; - remoteGlobalIDString = 030B6CC21A6E16E800C2D4F1; - remoteInfo = "SwiftyJSON OSX"; - }; 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 2E4FEFD219575BE100351305 /* Project object */; @@ -47,8 +37,6 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 030B6CCD1A6E16E900C2D4F1 /* SwiftyJSON OSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON OSXTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -73,21 +61,6 @@ /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ - 030B6CBF1A6E16E800C2D4F1 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 030B6CCA1A6E16E900C2D4F1 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 030B6CCE1A6E16E900C2D4F1 /* SwiftyJSON.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 2E4FEFD719575BE100351305 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -120,8 +93,6 @@ children = ( 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */, - 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */, - 030B6CCD1A6E16E900C2D4F1 /* SwiftyJSON OSXTests.xctest */, ); name = Products; sourceTree = ""; @@ -178,14 +149,6 @@ /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ - 030B6CC01A6E16E800C2D4F1 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 030B6CDD1A6E172B00C2D4F1 /* SwiftyJSON.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 2E4FEFD819575BE100351305 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -197,42 +160,6 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 030B6CC21A6E16E800C2D4F1 /* SwiftyJSON OSX */ = { - isa = PBXNativeTarget; - buildConfigurationList = 030B6CD61A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */; - buildPhases = ( - 030B6CBE1A6E16E800C2D4F1 /* Sources */, - 030B6CBF1A6E16E800C2D4F1 /* Frameworks */, - 030B6CC01A6E16E800C2D4F1 /* Headers */, - 030B6CC11A6E16E800C2D4F1 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "SwiftyJSON OSX"; - productName = "SwiftyJSON OSX"; - productReference = 030B6CC31A6E16E800C2D4F1 /* SwiftyJSON.framework */; - productType = "com.apple.product-type.framework"; - }; - 030B6CCC1A6E16E900C2D4F1 /* SwiftyJSON OSXTests */ = { - isa = PBXNativeTarget; - buildConfigurationList = 030B6CD91A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSXTests" */; - buildPhases = ( - 030B6CC91A6E16E900C2D4F1 /* Sources */, - 030B6CCA1A6E16E900C2D4F1 /* Frameworks */, - 030B6CCB1A6E16E900C2D4F1 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - 030B6CD01A6E16E900C2D4F1 /* PBXTargetDependency */, - ); - name = "SwiftyJSON OSXTests"; - productName = "SwiftyJSON OSXTests"; - productReference = 030B6CCD1A6E16E900C2D4F1 /* SwiftyJSON OSXTests.xctest */; - productType = "com.apple.product-type.bundle.unit-test"; - }; 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */ = { isa = PBXNativeTarget; buildConfigurationList = 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */; @@ -277,12 +204,6 @@ attributes = { LastUpgradeCheck = 0600; TargetAttributes = { - 030B6CC21A6E16E800C2D4F1 = { - CreatedOnToolsVersion = 6.2; - }; - 030B6CCC1A6E16E900C2D4F1 = { - CreatedOnToolsVersion = 6.2; - }; 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; }; @@ -306,27 +227,11 @@ targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */, 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, - 030B6CC21A6E16E800C2D4F1 /* SwiftyJSON OSX */, - 030B6CCC1A6E16E900C2D4F1 /* SwiftyJSON OSXTests */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - 030B6CC11A6E16E800C2D4F1 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 030B6CCB1A6E16E900C2D4F1 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; 2E4FEFD919575BE100351305 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -345,21 +250,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ - 030B6CBE1A6E16E800C2D4F1 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 030B6CDE1A6E172B00C2D4F1 /* SwiftyJSON.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - 030B6CC91A6E16E900C2D4F1 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; 2E4FEFD619575BE100351305 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -391,11 +281,6 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 030B6CD01A6E16E900C2D4F1 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 030B6CC21A6E16E800C2D4F1 /* SwiftyJSON OSX */; - targetProxy = 030B6CCF1A6E16E900C2D4F1 /* PBXContainerItemProxy */; - }; 2E4FEFE919575BE100351305 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */; @@ -404,88 +289,6 @@ /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ - 030B6CD71A6E16E900C2D4F1 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-OSX.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = YES; - PRODUCT_NAME = SwiftyJSON; - SDKROOT = macosx; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 030B6CD81A6E16E900C2D4F1 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - DEFINES_MODULE = YES; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - DYLIB_INSTALL_NAME_BASE = "@rpath"; - FRAMEWORK_VERSION = A; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-OSX.plist"; - INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_NAME = SwiftyJSON; - SDKROOT = macosx; - SKIP_INSTALL = YES; - }; - name = Release; - }; - 030B6CDA1A6E16E900C2D4F1 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - INFOPLIST_FILE = "SwiftyJSON OSXTests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MTL_ENABLE_DEBUG_INFO = YES; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Debug; - }; - 030B6CDB1A6E16E900C2D4F1 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - COMBINE_HIDPI_IMAGES = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); - INFOPLIST_FILE = "SwiftyJSON OSXTests/Info.plist"; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; - MTL_ENABLE_DEBUG_INFO = NO; - PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx; - }; - name = Release; - }; 2E4FEFEF19575BE100351305 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -644,22 +447,6 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 030B6CD61A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 030B6CD71A6E16E900C2D4F1 /* Debug */, - 030B6CD81A6E16E900C2D4F1 /* Release */, - ); - defaultConfigurationIsVisible = 0; - }; - 030B6CD91A6E16E900C2D4F1 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSXTests" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 030B6CDA1A6E16E900C2D4F1 /* Debug */, - 030B6CDB1A6E16E900C2D4F1 /* Release */, - ); - defaultConfigurationIsVisible = 0; - }; 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme deleted file mode 100644 index 2ee2f284..00000000 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ /dev/null @@ -1,110 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 46036b178389a5408b234cab6717f882fa7bfe8b Mon Sep 17 00:00:00 2001 From: Aron Cedercrantz Date: Sun, 15 Feb 2015 17:33:02 +0100 Subject: [PATCH 103/470] =?UTF-8?q?Rename=20iOS=20tests=20target=20to=20?= =?UTF-8?q?=E2=80=9CSwiftyJSON=20iOS=20Tests=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - So that we maintain a nice naming convention. --- SwiftyJSON.xcodeproj/project.pbxproj | 16 ++++++++-------- .../xcschemes/SwiftyJSON iOS.xcscheme | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 8a6a0ea1..03de45b3 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -41,7 +41,7 @@ 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; - 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyJSONTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; @@ -92,7 +92,7 @@ isa = PBXGroup; children = ( 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, - 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */, + 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */, ); name = Products; sourceTree = ""; @@ -178,9 +178,9 @@ productReference = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; }; - 2E4FEFE519575BE100351305 /* SwiftyJSONTests */ = { + 2E4FEFE519575BE100351305 /* SwiftyJSON iOS Tests */ = { isa = PBXNativeTarget; - buildConfigurationList = 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */; + buildConfigurationList = 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS Tests" */; buildPhases = ( 2E4FEFE219575BE100351305 /* Sources */, 2E4FEFE319575BE100351305 /* Frameworks */, @@ -191,9 +191,9 @@ dependencies = ( 2E4FEFE919575BE100351305 /* PBXTargetDependency */, ); - name = SwiftyJSONTests; + name = "SwiftyJSON iOS Tests"; productName = SwiftyJSONTests; - productReference = 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */; + productReference = 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; /* End PBXNativeTarget section */ @@ -226,7 +226,7 @@ projectRoot = ""; targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */, - 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, + 2E4FEFE519575BE100351305 /* SwiftyJSON iOS Tests */, ); }; /* End PBXProject section */ @@ -465,7 +465,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSONTests" */ = { + 2E4FEFF419575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS Tests" */ = { isa = XCConfigurationList; buildConfigurations = ( 2E4FEFF519575BE100351305 /* Debug */, diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme index a4fde4d6..d3569fae 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme @@ -29,8 +29,8 @@ @@ -47,8 +47,8 @@ From 40c3784c6b9fc463b0f68624992f1ed205ccf5d9 Mon Sep 17 00:00:00 2001 From: Aron Cedercrantz Date: Sun, 15 Feb 2015 17:45:24 +0100 Subject: [PATCH 104/470] Rename info plists to have -iOS suffix --- Source/{Info.plist => Info-iOS.plist} | 0 SwiftyJSON.xcodeproj/project.pbxproj | 96 ++++++++++++++++++++++++--- Tests/{Info.plist => Info-iOS.plist} | 0 3 files changed, 88 insertions(+), 8 deletions(-) rename Source/{Info.plist => Info-iOS.plist} (100%) rename Tests/{Info.plist => Info-iOS.plist} (100%) diff --git a/Source/Info.plist b/Source/Info-iOS.plist similarity index 100% rename from Source/Info.plist rename to Source/Info-iOS.plist diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 03de45b3..c41aaeb4 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -39,14 +39,14 @@ /* Begin PBXFileReference section */ 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 2E4FEFDF19575BE100351305 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; - A82A1C0D19D922DC009A653D /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + A82A1C0D19D922DC009A653D /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawTests.swift; sourceTree = ""; }; A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = ""; }; @@ -110,8 +110,8 @@ 2E4FEFDE19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( + 2E4FEFDF19575BE100351305 /* Info-iOS.plist */, 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */, - 2E4FEFDF19575BE100351305 /* Info.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -141,7 +141,7 @@ 2E4FEFEB19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( - A82A1C0D19D922DC009A653D /* Info.plist */, + A82A1C0D19D922DC009A653D /* Info-iOS.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -385,7 +385,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; + INFOPLIST_FILE = "Source/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -403,7 +403,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist"; + INFOPLIST_FILE = "Source/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -423,7 +423,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = Tests/Info.plist; + INFOPLIST_FILE = "Tests/Info-iOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -437,13 +437,93 @@ "$(SDKROOT)/Developer/Library/Frameworks", "$(inherited)", ); - INFOPLIST_FILE = Tests/Info.plist; + INFOPLIST_FILE = "Tests/Info-iOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; }; + 9C7DFC6F1A9102BD005AA3F7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "Source/Info-OSX.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = "$(PROJECT_NAME)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 9C7DFC701A9102BD005AA3F7 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + FRAMEWORK_VERSION = A; + INFOPLIST_FILE = "Source/Info-OSX.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(PROJECT_NAME)"; + SDKROOT = macosx; + SKIP_INSTALL = YES; + }; + name = Release; + }; + 9C7DFC721A9102BD005AA3F7 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + INFOPLIST_FILE = "Tests/Info-OSX.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Debug; + }; + 9C7DFC731A9102BD005AA3F7 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COMBINE_HIDPI_IMAGES = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + FRAMEWORK_SEARCH_PATHS = ( + "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(inherited)", + ); + INFOPLIST_FILE = "Tests/Info-OSX.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ diff --git a/Tests/Info.plist b/Tests/Info-iOS.plist similarity index 100% rename from Tests/Info.plist rename to Tests/Info-iOS.plist From fde6335486d6f6170a6d5c23977bb6f6aec521d4 Mon Sep 17 00:00:00 2001 From: Aron Cedercrantz Date: Sun, 15 Feb 2015 17:46:40 +0100 Subject: [PATCH 105/470] Add OS X framework and tests target + scheme - Only uses one single Xcode scheme. --- SwiftyJSON.xcodeproj/project.pbxproj | 163 ++++++++++++++++++ .../xcschemes/SwiftyJSON OSX.xcscheme | 110 ++++++++++++ Tests/Info-OSX.plist | 24 +++ 3 files changed, 297 insertions(+) create mode 100644 SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme create mode 100644 Tests/Info-OSX.plist diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index c41aaeb4..902c045d 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -9,6 +9,23 @@ /* Begin PBXBuildFile section */ 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; + 9C459EF41A910334008C9A41 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 9C459EF51A910361008C9A41 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + 9C459EF81A9103C1008C9A41 /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; + 9C459EF91A9103C1008C9A41 /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; + 9C459EFA1A9103C1008C9A41 /* BaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */; }; + 9C459EFB1A9103C1008C9A41 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; + 9C459EFC1A9103C1008C9A41 /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; + 9C459EFD1A9103C1008C9A41 /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; + 9C459EFE1A9103C1008C9A41 /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; + 9C459EFF1A9103C1008C9A41 /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; + 9C459F001A9103C1008C9A41 /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; + 9C459F011A9103C1008C9A41 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; + 9C459F021A9103C1008C9A41 /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; + 9C459F031A9103C1008C9A41 /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; + 9C459F041A9103C1008C9A41 /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; + 9C459F051A9103C1008C9A41 /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; + 9C7DFC661A9102BD005AA3F7 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */; }; A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; @@ -34,6 +51,13 @@ remoteGlobalIDString = 2E4FEFDA19575BE100351305; remoteInfo = SwiftyJSON; }; + 9C7DFC671A9102BD005AA3F7 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2E4FEFD219575BE100351305 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 9C7DFC5A1A9102BD005AA3F7; + remoteInfo = "SwiftyJSON OSX"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -42,6 +66,9 @@ 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; + 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; @@ -76,6 +103,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9C7DFC571A9102BD005AA3F7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 9C7DFC621A9102BD005AA3F7 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 9C7DFC661A9102BD005AA3F7 /* SwiftyJSON.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -93,6 +135,8 @@ children = ( 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */, + 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */, + 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */, ); name = Products; sourceTree = ""; @@ -142,6 +186,7 @@ isa = PBXGroup; children = ( A82A1C0D19D922DC009A653D /* Info-iOS.plist */, + 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -157,6 +202,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9C7DFC581A9102BD005AA3F7 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 9C459EF41A910334008C9A41 /* SwiftyJSON.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -196,6 +249,42 @@ productReference = 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */ = { + isa = PBXNativeTarget; + buildConfigurationList = 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */; + buildPhases = ( + 9C7DFC561A9102BD005AA3F7 /* Sources */, + 9C7DFC571A9102BD005AA3F7 /* Frameworks */, + 9C7DFC581A9102BD005AA3F7 /* Headers */, + 9C7DFC591A9102BD005AA3F7 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "SwiftyJSON OSX"; + productName = "SwiftyJSON OSX"; + productReference = 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */; + productType = "com.apple.product-type.framework"; + }; + 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON OSX Tests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 9C7DFC711A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX Tests" */; + buildPhases = ( + 9C7DFC611A9102BD005AA3F7 /* Sources */, + 9C7DFC621A9102BD005AA3F7 /* Frameworks */, + 9C7DFC631A9102BD005AA3F7 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 9C7DFC681A9102BD005AA3F7 /* PBXTargetDependency */, + ); + name = "SwiftyJSON OSX Tests"; + productName = "SwiftyJSON OSXTests"; + productReference = 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -211,6 +300,12 @@ CreatedOnToolsVersion = 6.0; TestTargetID = 2E4FEFDA19575BE100351305; }; + 9C7DFC5A1A9102BD005AA3F7 = { + CreatedOnToolsVersion = 6.1.1; + }; + 9C7DFC641A9102BD005AA3F7 = { + CreatedOnToolsVersion = 6.1.1; + }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -227,6 +322,8 @@ targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */, 2E4FEFE519575BE100351305 /* SwiftyJSON iOS Tests */, + 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */, + 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON OSX Tests */, ); }; /* End PBXProject section */ @@ -247,6 +344,21 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9C7DFC591A9102BD005AA3F7 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 9C7DFC631A9102BD005AA3F7 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9C459EF81A9103C1008C9A41 /* Tests.json in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -278,6 +390,34 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 9C7DFC561A9102BD005AA3F7 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9C459EF51A910361008C9A41 /* SwiftyJSON.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 9C7DFC611A9102BD005AA3F7 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 9C459EFB1A9103C1008C9A41 /* SequenceTypeTests.swift in Sources */, + 9C459F001A9103C1008C9A41 /* ComparableTests.swift in Sources */, + 9C459F021A9103C1008C9A41 /* NumberTests.swift in Sources */, + 9C459EFF1A9103C1008C9A41 /* RawRepresentableTests.swift in Sources */, + 9C459EFA1A9103C1008C9A41 /* BaseTests.swift in Sources */, + 9C459F041A9103C1008C9A41 /* DictionaryTests.swift in Sources */, + 9C459EF91A9103C1008C9A41 /* PerformanceTests.swift in Sources */, + 9C459EFE1A9103C1008C9A41 /* LiteralConvertibleTests.swift in Sources */, + 9C459EFC1A9103C1008C9A41 /* PrintableTests.swift in Sources */, + 9C459F011A9103C1008C9A41 /* StringTests.swift in Sources */, + 9C459F031A9103C1008C9A41 /* RawTests.swift in Sources */, + 9C459F051A9103C1008C9A41 /* ArrayTests.swift in Sources */, + 9C459EFD1A9103C1008C9A41 /* SubscriptTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -286,6 +426,11 @@ target = 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */; targetProxy = 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */; }; + 9C7DFC681A9102BD005AA3F7 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */; + targetProxy = 9C7DFC671A9102BD005AA3F7 /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -554,6 +699,24 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 9C7DFC6F1A9102BD005AA3F7 /* Debug */, + 9C7DFC701A9102BD005AA3F7 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 9C7DFC711A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 9C7DFC721A9102BD005AA3F7 /* Debug */, + 9C7DFC731A9102BD005AA3F7 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 2E4FEFD219575BE100351305 /* Project object */; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme new file mode 100644 index 00000000..6c1e44bc --- /dev/null +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/Info-OSX.plist b/Tests/Info-OSX.plist new file mode 100644 index 00000000..75bab451 --- /dev/null +++ b/Tests/Info-OSX.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + From 1736aec181c094e1c6b171f5152222d1117e7f78 Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Wed, 11 Mar 2015 12:07:25 +0200 Subject: [PATCH 106/470] Added automatically generated change log file --- CHANGELOG.md | 345 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..40bde729 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,345 @@ +# Change Log + +## [Unreleased](https://github.com/SwiftyJSON/SwiftyJSON/tree/HEAD) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.1.3...HEAD) + +**Closed issues:** + +- extend data to results [\#160](https://github.com/SwiftyJSON/SwiftyJSON/issues/160) + +- Create JSON From String [\#159](https://github.com/SwiftyJSON/SwiftyJSON/issues/159) + +- No Cocoapods support for iOS 7 [\#151](https://github.com/SwiftyJSON/SwiftyJSON/issues/151) + +- Update to Swift 1.2 [\#148](https://github.com/SwiftyJSON/SwiftyJSON/issues/148) + +- Url slashes ' / ' are being replaced with ' \/ ' [\#145](https://github.com/SwiftyJSON/SwiftyJSON/issues/145) + +- Issues when using carthage [\#144](https://github.com/SwiftyJSON/SwiftyJSON/issues/144) + +- Can not convert \[JSON\] to JSON [\#143](https://github.com/SwiftyJSON/SwiftyJSON/issues/143) + +- \[!\] Unable to find a specification for `SwiftyJSON \(= 2.1.3\)` [\#141](https://github.com/SwiftyJSON/SwiftyJSON/issues/141) + +- Deployment target iOS 7 or iOS 8? [\#131](https://github.com/SwiftyJSON/SwiftyJSON/issues/131) + +- Cocoapods support [\#126](https://github.com/SwiftyJSON/SwiftyJSON/issues/126) + +**Merged pull requests:** + +- Adding Swift 1.2 support [\#158](https://github.com/SwiftyJSON/SwiftyJSON/pull/158) ([Jasdev](https://github.com/Jasdev)) + +- Fix issues with the OS X target and scheme [\#156](https://github.com/SwiftyJSON/SwiftyJSON/pull/156) ([rastersize](https://github.com/rastersize)) + +- Fix issues with the OS X target and scheme [\#155](https://github.com/SwiftyJSON/SwiftyJSON/pull/155) ([rastersize](https://github.com/rastersize)) + +- Remove SwiftJSON.xcodeproj/xcuserdata [\#154](https://github.com/SwiftyJSON/SwiftyJSON/pull/154) ([rastersize](https://github.com/rastersize)) + +- Change to not build test when building iOS framework target \[Xcode 6.3 + external tools\] [\#153](https://github.com/SwiftyJSON/SwiftyJSON/pull/153) ([rastersize](https://github.com/rastersize)) + +- Swift 1.2 compatibility fixes [\#149](https://github.com/SwiftyJSON/SwiftyJSON/pull/149) ([darrarski](https://github.com/darrarski)) + +- add missing ` in comments [\#142](https://github.com/SwiftyJSON/SwiftyJSON/pull/142) ([zhxnlai](https://github.com/zhxnlai)) + +- Fix README.md nested example [\#139](https://github.com/SwiftyJSON/SwiftyJSON/pull/139) ([watsonbox](https://github.com/watsonbox)) + +- Shared OSX Scheme. OSX target fixes. [\#138](https://github.com/SwiftyJSON/SwiftyJSON/pull/138) ([haveahennessy](https://github.com/haveahennessy)) + +- Casting to NSDictionary instead of \[String : AnyObject\] [\#137](https://github.com/SwiftyJSON/SwiftyJSON/pull/137) ([clwkct](https://github.com/clwkct)) + +- Update README.md [\#136](https://github.com/SwiftyJSON/SwiftyJSON/pull/136) ([esbenvb](https://github.com/esbenvb)) + +- Update README.md [\#135](https://github.com/SwiftyJSON/SwiftyJSON/pull/135) ([esbenvb](https://github.com/esbenvb)) + +- Fixed the broken Carthage OS X Support. [\#134](https://github.com/SwiftyJSON/SwiftyJSON/pull/134) ([remaerd](https://github.com/remaerd)) + +## [2.1.3](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.1.3) (2015-01-10) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.1.2...2.1.3) + +**Closed issues:** + +- Cannot install using Carthage [\#122](https://github.com/SwiftyJSON/SwiftyJSON/issues/122) + +- Use of unresolved identifier 'dataFromNetworking' [\#112](https://github.com/SwiftyJSON/SwiftyJSON/issues/112) + +- I can't parse out the string like "{a:5}" [\#109](https://github.com/SwiftyJSON/SwiftyJSON/issues/109) + +- Cocoapods integration [\#108](https://github.com/SwiftyJSON/SwiftyJSON/issues/108) + +- Compile Error In Loop Array [\#107](https://github.com/SwiftyJSON/SwiftyJSON/issues/107) + +- Support for Carthage [\#105](https://github.com/SwiftyJSON/SwiftyJSON/issues/105) + +**Merged pull requests:** + +- Minor grammar fixes to README [\#128](https://github.com/SwiftyJSON/SwiftyJSON/pull/128) ([johngoren](https://github.com/johngoren)) + +- Updated because podspec is now available... [\#127](https://github.com/SwiftyJSON/SwiftyJSON/pull/127) ([johngoren](https://github.com/johngoren)) + +- Fix access modificator of isEmpty property [\#121](https://github.com/SwiftyJSON/SwiftyJSON/pull/121) ([wiruzx](https://github.com/wiruzx)) + +- Make framework extension friendly [\#119](https://github.com/SwiftyJSON/SwiftyJSON/pull/119) ([technomage](https://github.com/technomage)) + +- add a new way to access Json [\#117](https://github.com/SwiftyJSON/SwiftyJSON/pull/117) ([zhanghao111111111](https://github.com/zhanghao111111111)) + +- fix the typos on the code snippets and the links in the TOC on README [\#115](https://github.com/SwiftyJSON/SwiftyJSON/pull/115) ([floydpink](https://github.com/floydpink)) + +- Use Mac' codesign identities for OSX targets [\#114](https://github.com/SwiftyJSON/SwiftyJSON/pull/114) ([max-potapov](https://github.com/max-potapov)) + +## [2.1.2](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.1.2) (2014-12-13) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.1.1...2.1.2) + +**Closed issues:** + +- Why can't we parse a rawString back to json object? [\#101](https://github.com/SwiftyJSON/SwiftyJSON/issues/101) + +- Have a Piece of Code that might be of Value to SwiftyJSon [\#97](https://github.com/SwiftyJSON/SwiftyJSON/issues/97) + +- build osx application \(command line tool\) with swiftyjson error [\#96](https://github.com/SwiftyJSON/SwiftyJSON/issues/96) + +- 这个应该是bug吧,支持的不是很够 [\#95](https://github.com/SwiftyJSON/SwiftyJSON/issues/95) + +- Length of an array [\#90](https://github.com/SwiftyJSON/SwiftyJSON/issues/90) + +- Compilation error [\#89](https://github.com/SwiftyJSON/SwiftyJSON/issues/89) + +- Can't set value [\#88](https://github.com/SwiftyJSON/SwiftyJSON/issues/88) + +- Examples with AFHTTPSessionManager? [\#86](https://github.com/SwiftyJSON/SwiftyJSON/issues/86) + +**Merged pull requests:** + +- Update README.md to add Carthage instructions [\#113](https://github.com/SwiftyJSON/SwiftyJSON/pull/113) ([justinmakaila](https://github.com/justinmakaila)) + +- Improve init performance for dictionaries and arrays [\#111](https://github.com/SwiftyJSON/SwiftyJSON/pull/111) ([avorobjov](https://github.com/avorobjov)) + +- Fix NSNumber != func [\#106](https://github.com/SwiftyJSON/SwiftyJSON/pull/106) ([briankracoff](https://github.com/briankracoff)) + +- Carthage Support [\#104](https://github.com/SwiftyJSON/SwiftyJSON/pull/104) ([justinmakaila](https://github.com/justinmakaila)) + +- Added read option for date strings [\#103](https://github.com/SwiftyJSON/SwiftyJSON/pull/103) ([Dschee](https://github.com/Dschee)) + +- Add Podspec \(Correct mblsha podspec\) [\#100](https://github.com/SwiftyJSON/SwiftyJSON/pull/100) ([ValCapri](https://github.com/ValCapri)) + +- Add podspec + make it work as a framework [\#99](https://github.com/SwiftyJSON/SwiftyJSON/pull/99) ([mblsha](https://github.com/mblsha)) + +- Adding new Feature: JsonMapper [\#98](https://github.com/SwiftyJSON/SwiftyJSON/pull/98) ([Drogenix](https://github.com/Drogenix)) + +- Change recommendation for Alamofire integration [\#92](https://github.com/SwiftyJSON/SwiftyJSON/pull/92) ([JonathanPorta](https://github.com/JonathanPorta)) + +## [2.1.1](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.1.1) (2014-11-12) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.1.0...2.1.1) + +**Closed issues:** + +- NSDictionary to json string to json object [\#93](https://github.com/SwiftyJSON/SwiftyJSON/issues/93) + +- Error: use of unresolved identifier dataFromNetworking [\#82](https://github.com/SwiftyJSON/SwiftyJSON/issues/82) + +- Type \[SubscriptType\] Does not conform to protocol 'StringLiteralConvertible' [\#81](https://github.com/SwiftyJSON/SwiftyJSON/issues/81) + +- Doesn't conform literal protocols [\#80](https://github.com/SwiftyJSON/SwiftyJSON/issues/80) + +- iOS 8.1 compatability [\#79](https://github.com/SwiftyJSON/SwiftyJSON/issues/79) + +- Xcode 6.1 Compatibility [\#78](https://github.com/SwiftyJSON/SwiftyJSON/issues/78) + +- Problem with xCode 6.1 [\#76](https://github.com/SwiftyJSON/SwiftyJSON/issues/76) + +- Compilation errors [\#75](https://github.com/SwiftyJSON/SwiftyJSON/issues/75) + +**Merged pull requests:** + +- Renamed type 'Unknow' to 'Unknown' [\#94](https://github.com/SwiftyJSON/SwiftyJSON/pull/94) ([franklsf95](https://github.com/franklsf95)) + +- Added OSX target. [\#91](https://github.com/SwiftyJSON/SwiftyJSON/pull/91) ([carloslozano](https://github.com/carloslozano)) + +- Add date ,dateValue [\#87](https://github.com/SwiftyJSON/SwiftyJSON/pull/87) ([muukii0803](https://github.com/muukii0803)) + +- Add parse JSON Date [\#85](https://github.com/SwiftyJSON/SwiftyJSON/pull/85) ([ShineWu](https://github.com/ShineWu)) + +- Update README.md [\#84](https://github.com/SwiftyJSON/SwiftyJSON/pull/84) ([johngoren](https://github.com/johngoren)) + +- Update README.md for typos [\#83](https://github.com/SwiftyJSON/SwiftyJSON/pull/83) ([johngoren](https://github.com/johngoren)) + +## [2.1.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.1.0) (2014-10-19) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.0.0...2.1.0) + +**Closed issues:** + +- 32bit test failures [\#71](https://github.com/SwiftyJSON/SwiftyJSON/issues/71) + +- Trouble getting string representation [\#70](https://github.com/SwiftyJSON/SwiftyJSON/issues/70) + +- JSON keep null [\#69](https://github.com/SwiftyJSON/SwiftyJSON/issues/69) + +- Update .pbxproj to Deployment Target 8.0 [\#66](https://github.com/SwiftyJSON/SwiftyJSON/issues/66) + +- Looping not working [\#64](https://github.com/SwiftyJSON/SwiftyJSON/issues/64) + +**Merged pull requests:** + +- Get number from string in JSON.number [\#74](https://github.com/SwiftyJSON/SwiftyJSON/pull/74) ([yonaskolb](https://github.com/yonaskolb)) + +- Update SwiftyJSON.swift [\#73](https://github.com/SwiftyJSON/SwiftyJSON/pull/73) ([MaddTheSane](https://github.com/MaddTheSane)) + +- Generating Raw JSON Strings [\#72](https://github.com/SwiftyJSON/SwiftyJSON/pull/72) ([lesmuc](https://github.com/lesmuc)) + +- Making SourceKit not freak out about self.object.count being called [\#68](https://github.com/SwiftyJSON/SwiftyJSON/pull/68) ([Noobish1](https://github.com/Noobish1)) + +- Added support for Xcode 6.1 GM Seed 2. [\#65](https://github.com/SwiftyJSON/SwiftyJSON/pull/65) ([rosskimes](https://github.com/rosskimes)) + +## [2.0.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.0.0) (2014-10-08) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/1.1.0...2.0.0) + +**Closed issues:** + +- JSON to NSData [\#62](https://github.com/SwiftyJSON/SwiftyJSON/issues/62) + +- Updating a json [\#60](https://github.com/SwiftyJSON/SwiftyJSON/issues/60) + +**Merged pull requests:** + +- Update for new features \[Issue \#60\] [\#63](https://github.com/SwiftyJSON/SwiftyJSON/pull/63) ([tangplin](https://github.com/tangplin)) + +- SwiftJSON update feature implemented [\#61](https://github.com/SwiftyJSON/SwiftyJSON/pull/61) ([k06a](https://github.com/k06a)) + +## [1.1.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/1.1.0) (2014-10-02) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/1.0.0...1.1.0) + +**Closed issues:** + +- Long time to parse this json [\#57](https://github.com/SwiftyJSON/SwiftyJSON/issues/57) + +**Merged pull requests:** + +- Merge develop [\#59](https://github.com/SwiftyJSON/SwiftyJSON/pull/59) ([tangplin](https://github.com/tangplin)) + +- Added SwiftyJSON lazy wrapping [\#58](https://github.com/SwiftyJSON/SwiftyJSON/pull/58) ([k06a](https://github.com/k06a)) + +## [1.0.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/1.0.0) (2014-09-26) + +**Implemented enhancements:** + +- JNumber should be Number not double [\#8](https://github.com/SwiftyJSON/SwiftyJSON/issues/8) + +- Separate implementations of protocols [\#5](https://github.com/SwiftyJSON/SwiftyJSON/issues/5) + +**Fixed bugs:** + +- JNumber should be Number not double [\#8](https://github.com/SwiftyJSON/SwiftyJSON/issues/8) + +- Fails to compile on Beta2 [\#1](https://github.com/SwiftyJSON/SwiftyJSON/issues/1) + +**Closed issues:** + +- No such module "SwiftyJSON" [\#49](https://github.com/SwiftyJSON/SwiftyJSON/issues/49) + +- how to transfer JSONValue object to Dictionary object? [\#48](https://github.com/SwiftyJSON/SwiftyJSON/issues/48) + +- JSONValue in @objc [\#47](https://github.com/SwiftyJSON/SwiftyJSON/issues/47) + +- SwiftyJSON.swift:331:22: Use of undeclared type 'BooleanType' [\#46](https://github.com/SwiftyJSON/SwiftyJSON/issues/46) + +- Problem converting JSONValue to AnyObject [\#44](https://github.com/SwiftyJSON/SwiftyJSON/issues/44) + +- Can't use SwiftyJSON as part of a public API within a framework [\#42](https://github.com/SwiftyJSON/SwiftyJSON/issues/42) + +- how to add JSONValue object into exist JSONValue [\#40](https://github.com/SwiftyJSON/SwiftyJSON/issues/40) + +- Doesn't work in BETA 6 [\#39](https://github.com/SwiftyJSON/SwiftyJSON/issues/39) + +- Can't access property [\#38](https://github.com/SwiftyJSON/SwiftyJSON/issues/38) + +- Couldn't Compile and Run [\#37](https://github.com/SwiftyJSON/SwiftyJSON/issues/37) + +- Array index out of range [\#35](https://github.com/SwiftyJSON/SwiftyJSON/issues/35) + +- Iterating through a JSON response [\#32](https://github.com/SwiftyJSON/SwiftyJSON/issues/32) + +- NSNull in an array is discarded [\#25](https://github.com/SwiftyJSON/SwiftyJSON/issues/25) + +- Updating Dictionary [\#24](https://github.com/SwiftyJSON/SwiftyJSON/issues/24) + +- SourcekitService Terminated Issue [\#22](https://github.com/SwiftyJSON/SwiftyJSON/issues/22) + +- Code does not compile in iOS 8 Beta 3. [\#17](https://github.com/SwiftyJSON/SwiftyJSON/issues/17) + +- How to use .count [\#14](https://github.com/SwiftyJSON/SwiftyJSON/issues/14) + +- Add to cocoapods [\#12](https://github.com/SwiftyJSON/SwiftyJSON/issues/12) + +- String parsing [\#9](https://github.com/SwiftyJSON/SwiftyJSON/issues/9) + +- Cocoapods integration [\#4](https://github.com/SwiftyJSON/SwiftyJSON/issues/4) + +- How do I verify SwiftyJSON workS? [\#2](https://github.com/SwiftyJSON/SwiftyJSON/issues/2) + +**Merged pull requests:** + +- Revert "Added rawObject method for unwrapping JSONValue enum to objects" [\#56](https://github.com/SwiftyJSON/SwiftyJSON/pull/56) ([tangplin](https://github.com/tangplin)) + +- set the default JSONReadingOptions to .AllowFragments [\#55](https://github.com/SwiftyJSON/SwiftyJSON/pull/55) ([tangplin](https://github.com/tangplin)) + +- Fix Unit Test [\#54](https://github.com/SwiftyJSON/SwiftyJSON/pull/54) ([lingoer](https://github.com/lingoer)) + +- Add NSError to Null type [\#53](https://github.com/SwiftyJSON/SwiftyJSON/pull/53) ([lingoer](https://github.com/lingoer)) + +- Refactor! [\#51](https://github.com/SwiftyJSON/SwiftyJSON/pull/51) ([tangplin](https://github.com/tangplin)) + +- Rename LISCENSE to LICENSE [\#50](https://github.com/SwiftyJSON/SwiftyJSON/pull/50) ([fixe](https://github.com/fixe)) + +- Added rawObject method for unwrapping JSONValue enum to objects [\#45](https://github.com/SwiftyJSON/SwiftyJSON/pull/45) ([k06a](https://github.com/k06a)) + +- made JSONValue public for usage in framework APIs [\#43](https://github.com/SwiftyJSON/SwiftyJSON/pull/43) ([Dschee](https://github.com/Dschee)) + +- Adding public/private modifiers so that SwiftyJSON can be used as a framework [\#41](https://github.com/SwiftyJSON/SwiftyJSON/pull/41) ([jansabbe](https://github.com/jansabbe)) + +- Rename LISCENSE to LICENSE [\#36](https://github.com/SwiftyJSON/SwiftyJSON/pull/36) ([kriswallsmith](https://github.com/kriswallsmith)) + +- Fix for Xcode 6 beta 5 changes [\#34](https://github.com/SwiftyJSON/SwiftyJSON/pull/34) ([FahimF](https://github.com/FahimF)) + +- Use BooleanType instead of LogicValue for Beta 5 [\#33](https://github.com/SwiftyJSON/SwiftyJSON/pull/33) ([venables](https://github.com/venables)) + +- Support for JSON as string [\#31](https://github.com/SwiftyJSON/SwiftyJSON/pull/31) ([bsvingen](https://github.com/bsvingen)) + +- Support building JSON messages in code. [\#30](https://github.com/SwiftyJSON/SwiftyJSON/pull/30) ([johnno1962](https://github.com/johnno1962)) + +- Update project to include access modifiers from Xcode beta 4. [\#29](https://github.com/SwiftyJSON/SwiftyJSON/pull/29) ([Baltoli](https://github.com/Baltoli)) + +- jsonvalue now conforms to sequence protocol for array values [\#28](https://github.com/SwiftyJSON/SwiftyJSON/pull/28) ([NatashaTheRobot](https://github.com/NatashaTheRobot)) + +- updated array and dictionary syntax for beta3 [\#27](https://github.com/SwiftyJSON/SwiftyJSON/pull/27) ([NatashaTheRobot](https://github.com/NatashaTheRobot)) + +- Update for Beta 4: exposing JSONValue with public [\#26](https://github.com/SwiftyJSON/SwiftyJSON/pull/26) ([NachoSoto](https://github.com/NachoSoto)) + +- SourceKitService Termination issue fix [\#23](https://github.com/SwiftyJSON/SwiftyJSON/pull/23) ([ipraba](https://github.com/ipraba)) + +- Add percent escaping to URL string [\#21](https://github.com/SwiftyJSON/SwiftyJSON/pull/21) ([romanroibu](https://github.com/romanroibu)) + +- Converting JSON objects to string is fixed [\#20](https://github.com/SwiftyJSON/SwiftyJSON/pull/20) ([bkase](https://github.com/bkase)) + +- JSONValue can be inited via string [\#19](https://github.com/SwiftyJSON/SwiftyJSON/pull/19) ([bkase](https://github.com/bkase)) + +- Updated to remove errors in Xcode Beta 3 [\#18](https://github.com/SwiftyJSON/SwiftyJSON/pull/18) ([krishpop](https://github.com/krishpop)) + +- add first and last in JSONValue, add string to double, int etc. [\#16](https://github.com/SwiftyJSON/SwiftyJSON/pull/16) ([tangplin](https://github.com/tangplin)) + +- add a "url" property to JSONValue [\#15](https://github.com/SwiftyJSON/SwiftyJSON/pull/15) ([kyoh](https://github.com/kyoh)) + +- Some typo fixes [\#13](https://github.com/SwiftyJSON/SwiftyJSON/pull/13) ([gregbarbosa](https://github.com/gregbarbosa)) + +- Separate protocols implementation, refactor prettyString composing [\#6](https://github.com/SwiftyJSON/SwiftyJSON/pull/6) ([garnett](https://github.com/garnett)) + +- Add project with both OSX/iOS module targets [\#3](https://github.com/SwiftyJSON/SwiftyJSON/pull/3) ([garnett](https://github.com/garnett)) + + + +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file From 2fcc611d25114b119d552589b9b9babc55e4e117 Mon Sep 17 00:00:00 2001 From: Joel Parker Henderson Date: Wed, 11 Mar 2015 22:29:57 -0600 Subject: [PATCH 107/470] Update README for new Cocoapods Fix markup --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 64465f4d..1e418eb8 100644 --- a/README.md +++ b/README.md @@ -87,17 +87,19 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ##Integration ####Carthage -You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding -`github "SwiftyJSON/SwiftyJSON" >= 2.1.2` to your `Cartfile` +You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: +``` +github "SwiftyJSON/SwiftyJSON" >= 2.1.2 +``` ####CocoaPods -CocoaPods beta release now supports for Swift. +You can use [Cocoapods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: ```ruby -pod 'SwiftyJSON', '2.1.3' +pod "SwiftyJSON", ">= 2.1.3" ``` -Note that it needs you to install CocoaPods pre-released version, and requires your iOS deploy target >= 8.0: +Note that it needs you to install CocoaPods 36 version, and requires your iOS deploy target >= 8.0: ```bash -[sudo] gem install cocoapods --pre +[sudo] gem install cocoapods -v '>=0.36' ``` ####Manually From ad03f607d72955c0f6d0fd1c6ce4ed70d6413864 Mon Sep 17 00:00:00 2001 From: Ryan Romanchuk Date: Sun, 15 Mar 2015 14:35:53 -0700 Subject: [PATCH 108/470] Better support for carthage users --- SwiftyJSON.xcodeproj/project.pbxproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 902c045d..6e77dcd7 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -498,7 +498,7 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - CODE_SIGN_IDENTITY = "iPhone Distribution"; + CODE_SIGN_IDENTITY = "iPhone Developer"; COPY_PHASE_STRIP = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_NS_ASSERTIONS = NO; @@ -543,7 +543,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; - CODE_SIGN_IDENTITY = "iPhone Distribution"; + CODE_SIGN_IDENTITY = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -592,6 +592,7 @@ 9C7DFC6F1A9102BD005AA3F7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -615,6 +616,7 @@ 9C7DFC701A9102BD005AA3F7 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; From 7cad22145d30d9c8463d174e0ccb6ae96b577a60 Mon Sep 17 00:00:00 2001 From: Masayuki Ono Date: Thu, 19 Mar 2015 09:09:04 +0900 Subject: [PATCH 109/470] Fix int overflow compile error --- Tests/BaseTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 413447d5..d78abdcf 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -111,7 +111,7 @@ class BaseTests: XCTestCase { let created_at = json[0]["created_at"].string let id_str = json[0]["id_str"].string let favorited = json[0]["favorited"].bool - let id = json[0]["id"].int + let id = json[0]["id"].int64 let in_reply_to_user_id_str = json[0]["in_reply_to_user_id_str"] XCTAssertEqual(created_at!, "Tue Aug 28 21:16:23 +0000 2012") XCTAssertEqual(id_str!,"240558470661799936") From 1e0a02944e17dc8a62eb33fa6e7594c3e7960b7d Mon Sep 17 00:00:00 2001 From: Christian Noon Date: Wed, 25 Mar 2015 11:15:20 -0700 Subject: [PATCH 110/470] Removed code signing identity from OSX target and tests. --- SwiftyJSON.xcodeproj/project.pbxproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 6e77dcd7..fda17ec2 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -592,7 +592,7 @@ 9C7DFC6F1A9102BD005AA3F7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -616,7 +616,7 @@ 9C7DFC701A9102BD005AA3F7 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; @@ -637,6 +637,7 @@ 9C7DFC721A9102BD005AA3F7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ( "$(DEVELOPER_FRAMEWORKS_DIR)", @@ -657,6 +658,7 @@ 9C7DFC731A9102BD005AA3F7 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ( From 4b0ec44b7114f1263917181fca70391b0610c53a Mon Sep 17 00:00:00 2001 From: Christian Noon Date: Wed, 25 Mar 2015 11:24:41 -0700 Subject: [PATCH 111/470] Fixed the buildable name in the OSX scheme. --- .../xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme index 6c1e44bc..4c4226a8 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -15,7 +15,7 @@ @@ -57,7 +57,7 @@ @@ -76,7 +76,7 @@ @@ -94,7 +94,7 @@ From 68e18284ff77daf6f4554b22fafc3a4f16262795 Mon Sep 17 00:00:00 2001 From: manijshrestha Date: Sun, 5 Apr 2015 13:05:56 -0500 Subject: [PATCH 112/470] Update README.md Updated Carthage note to show the latest version 2.1.3 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c1089b0b..710719c1 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ####Carthage You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` -github "SwiftyJSON/SwiftyJSON" >= 2.1.2 +github "SwiftyJSON/SwiftyJSON" >= 2.1.3 ``` ####CocoaPods From c569b21d81b1fbe63fef3c711e70810d0aac3847 Mon Sep 17 00:00:00 2001 From: Christian Schuster Date: Fri, 10 Apr 2015 23:37:39 +0200 Subject: [PATCH 113/470] Avoid using subscript on AnyObject in Swift 1.2 --- Source/SwiftyJSON.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 40fef595..4b0b20b2 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -247,7 +247,8 @@ extension JSON { get { var returnJSON = JSON.nullJSON if self.type == .Dictionary { - if let object_: AnyObject = self.object[key] { + let dictionary_ = self.object as! [String : AnyObject] + if let object_: AnyObject = dictionary_[key] { returnJSON = JSON(object_) } else { returnJSON._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) From fbd135e0535a8635573e1118da3594040fc824ca Mon Sep 17 00:00:00 2001 From: Sommer Panage Date: Sun, 12 Apr 2015 22:19:50 -0700 Subject: [PATCH 114/470] Only building tests for testing --- .../xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme | 4 ++-- .../xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme index 6c1e44bc..c0b43a0d 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -22,10 +22,10 @@ + buildForAnalyzing = "NO"> + buildForAnalyzing = "NO"> Date: Mon, 13 Apr 2015 14:42:58 +0800 Subject: [PATCH 115/470] Update README.md --- README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 710719c1..62028ee6 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Raw object](#raw-object) - [Literal convertibles](#literal-convertibles) 1. [Work with Alamofire](#work-with-alamofire) - + ##Why is the typical JSON handling in Swift NOT good? Swift is very strict about types. But although explicit typing is good for saving us from mistakes, it becomes painful when dealing with JSON and other areas that are, by nature, implicit about types. @@ -32,7 +32,7 @@ if let statusesArray = jsonObject as? NSArray{ if let user = aStatus["user"] as? NSDictionary{ if let userName = user["name"] as? NSString{ //Finally We Got The Name - + } } } @@ -89,13 +89,13 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ####Carthage You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` -github "SwiftyJSON/SwiftyJSON" >= 2.1.3 +github "SwiftyJSON/SwiftyJSON" >= 2.2 ``` ####CocoaPods You can use [Cocoapods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: ```ruby -pod "SwiftyJSON", ">= 2.1.3" +pod "SwiftyJSON", ">= 2.2" ``` Note that it needs you to install CocoaPods 36 version, and requires your iOS deploy target >= 8.0: ```bash @@ -130,13 +130,13 @@ let name = json["name"].stringValue ```swift //With an array like path to the element let path = [1,"list",2,"name"] -let name = json[path].string +let name = json[path].string //Just the same let name = json[1]["list"][2]["name"].string ``` ```swift //With a literal array to the element -let name = json[1,"list",2,"name"].string +let name = json[1,"list",2,"name"].string //Just the same let name = json[1]["list"][2]["name"].string ``` @@ -163,7 +163,7 @@ for (index: String, subJson: JSON) in json { Use subscript to get/set value in Array or Dicitonary * If json is an array, the app may crash with "index out-of-bounds." -* If json is a dictionary, it will get `nil` without the reason. +* If json is a dictionary, it will get `nil` without the reason. * If json is not an array or a dictionary, the app may crash with the wrong selector exception. It will never happen in SwiftyJSON. From 87fa9e2432187629aae80cf89027f2a615af2c31 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Mon, 13 Apr 2015 14:50:54 +0800 Subject: [PATCH 116/470] Update podspec --- SwiftyJSON.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 0aa72e49..205c3f38 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.1.3" + s.version = "2.2.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -9,6 +9,6 @@ Pod::Spec.new do |s| s.requires_arc = true s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.1.3"} + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.2.0"} s.source_files = "Source/*.swift" end From c5554fa4f8559d2833d509e7f49f89479029245e Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Thu, 16 Apr 2015 14:55:03 +0800 Subject: [PATCH 117/470] Update swift's protocol to swift.protocol --- Source/SwiftyJSON.swift | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 7086e2da..5407e9aa 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -367,7 +367,7 @@ extension JSON { // MARK: - LiteralConvertible -extension JSON: StringLiteralConvertible { +extension JSON: Swift.StringLiteralConvertible { public init(stringLiteral value: StringLiteralType) { self.init(value) @@ -382,28 +382,28 @@ extension JSON: StringLiteralConvertible { } } -extension JSON: IntegerLiteralConvertible { +extension JSON: Swift.IntegerLiteralConvertible { public init(integerLiteral value: IntegerLiteralType) { self.init(value) } } -extension JSON: BooleanLiteralConvertible { +extension JSON: Swift.BooleanLiteralConvertible { public init(booleanLiteral value: BooleanLiteralType) { self.init(value) } } -extension JSON: FloatLiteralConvertible { +extension JSON: Swift.FloatLiteralConvertible { public init(floatLiteral value: FloatLiteralType) { self.init(value) } } -extension JSON: DictionaryLiteralConvertible { +extension JSON: Swift.DictionaryLiteralConvertible { public init(dictionaryLiteral elements: (String, AnyObject)...) { var dictionary_ = [String : AnyObject]() @@ -414,14 +414,14 @@ extension JSON: DictionaryLiteralConvertible { } } -extension JSON: ArrayLiteralConvertible { +extension JSON: Swift.ArrayLiteralConvertible { public init(arrayLiteral elements: AnyObject...) { self.init(elements) } } -extension JSON: NilLiteralConvertible { +extension JSON: Swift.NilLiteralConvertible { public init(nilLiteral: ()) { self.init(NSNull()) @@ -430,7 +430,7 @@ extension JSON: NilLiteralConvertible { // MARK: - Raw -extension JSON: RawRepresentable { +extension JSON: Swift.RawRepresentable { public init?(rawValue: AnyObject) { if JSON(rawValue).type == .Unknown { @@ -472,7 +472,7 @@ extension JSON: RawRepresentable { // MARK: - Printable, DebugPrintable -extension JSON: Printable, DebugPrintable { +extension JSON: Swift.Printable, Swift.DebugPrintable { public var description: String { if let string = self.rawString(options:.PrettyPrinted) { @@ -581,7 +581,7 @@ extension JSON { // MARK: - Bool -extension JSON: BooleanType { +extension JSON: Swift.BooleanType { //Optional bool public var bool: Bool? { @@ -1014,7 +1014,7 @@ extension JSON { } //MARK: - Comparable -extension JSON: Comparable {} +extension JSON: Swift.Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { @@ -1107,7 +1107,7 @@ private let falseObjCType = String.fromCString(falseNumber.objCType) // MARK: - NSNumber: Comparable -extension NSNumber: Comparable { +extension NSNumber: Swift.Comparable { var isBool:Bool { get { let objCType = String.fromCString(self.objCType) From ce369e35f803c6c01421e9ff5d36bad7b8fcc82d Mon Sep 17 00:00:00 2001 From: tangplin Date: Thu, 16 Apr 2015 17:40:09 +0800 Subject: [PATCH 118/470] Update README.md --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 62028ee6..f0a55ddf 100644 --- a/README.md +++ b/README.md @@ -141,8 +141,13 @@ let name = json[1,"list",2,"name"].string let name = json[1]["list"][2]["name"].string ``` ```swift -//With a Hard Way -let name = json[[1,"list",2,"name"]].string +//With a hard way +let name = json[].string +``` +```swift +//With a custom way +let keys:[SubscriptType] = [1,"list",2,"name"] +let name = json[keys].string ``` ####Loop ```swift From 018c6fbabf1f110582c0018e742655a8cf4b6003 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Thu, 16 Apr 2015 17:56:18 +0800 Subject: [PATCH 119/470] Add test - get value from [SubscriptType] --- Tests/SubscriptTests.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 5e2034a4..126be1f4 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -103,6 +103,8 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[1]["b"], JSON("B")) XCTAssertNotNil(json[2]["null"].null) XCTAssertNotNil(json[2,"null"].null) + let keys:[SubscriptType] = [1, "a"] + XCTAssertEqual(json[keys], JSON(rawValue: "A")!) } func testDictionaryAllNumber() { From 52c3c191ab175fb31d295324a1162ad6607d3c5d Mon Sep 17 00:00:00 2001 From: Peter Ryszkiewicz Date: Thu, 16 Apr 2015 23:01:26 -0500 Subject: [PATCH 120/470] Fixed spelling and grammar mistakes in README.md. Made some swift syntax more consistent. --- README.md | 51 ++++++++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index f0a55ddf..7b5eb4f7 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. ##Why is the typical JSON handling in Swift NOT good? Swift is very strict about types. But although explicit typing is good for saving us from mistakes, it becomes painful when dealing with JSON and other areas that are, by nature, implicit about types. -Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline). +Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline). The code would look like this: @@ -42,7 +42,7 @@ if let statusesArray = jsonObject as? NSArray{ It's not good. -Even if we use optional chaining, it would also cause a mess: +Even if we use optional chaining, it would be messy: ```swift @@ -120,25 +120,21 @@ let json = JSON(jsonObject) ####Subscript ```swift -//With a int from JSON supposed to an Array +//Getting a double from a JSON Array let name = json[0].double ``` ```swift -//With a string from JSON supposed to an Dictionary +//Getting a string from a JSON Dictionary let name = json["name"].stringValue ``` ```swift -//With an array like path to the element +//Getting a string using a path to the element let path = [1,"list",2,"name"] let name = json[path].string //Just the same let name = json[1]["list"][2]["name"].string -``` -```swift -//With a literal array to the element +//Alternatively let name = json[1,"list",2,"name"].string -//Just the same -let name = json[1]["list"][2]["name"].string ``` ```swift //With a hard way @@ -156,7 +152,7 @@ for (key: String, subJson: JSON) in json { //Do something you want } ``` -*The first element is always String, even if the JSON's object is Array* +*The first element is always a String, even if the JSON is an Array* ```swift //If json is .Array //The `index` is 0.. Date: Sun, 26 Apr 2015 23:02:24 +0200 Subject: [PATCH 121/470] Update the first two examples snippets - Use Swift 1.2 syntax: multiple if-let clauses - Use Swift objects, that is `[String; AnyObject]` instead of `NSDictionary` - In the second example, cast the final result to String - Don't use `NSJSONReadingOptions.MutableContainers`, it does make the example look more awful than it is, but it is rarely needed... --- README.md | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index f0a55ddf..743ce4d0 100644 --- a/README.md +++ b/README.md @@ -26,16 +26,13 @@ The code would look like this: ```swift -let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil) -if let statusesArray = jsonObject as? NSArray{ - if let aStatus = statusesArray[0] as? NSDictionary{ - if let user = aStatus["user"] as? NSDictionary{ - if let userName = user["name"] as? NSString{ - //Finally We Got The Name - - } - } - } +let JSONObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) + +if let statusesArray = JSONObject as? [AnyObject], + let status = statusesArray[0] as? [String: AnyObject], + let user = status["user"] as? [String: AnyObject], + let username = user["name"] as? String { + // Finally we got the username } ``` @@ -46,9 +43,10 @@ Even if we use optional chaining, it would also cause a mess: ```swift -let jsonObject : AnyObject! = NSJSONSerialization.JSONObjectWithData(dataFromTwitter, options: NSJSONReadingOptions.MutableContainers, error: nil) -if let userName = (((jsonObject as? NSArray)?[0] as? NSDictionary)?["user"] as? NSDictionary)?["name"]{ - //What A disaster above +let JSONObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) + +if let username = (((JSONObject as? [AnyObject])?[0] as? [String: AnyObject])?["user"] as? [String: AnyObject])?["name"] as? String { + // What a disaster } ``` From ed1521cade399598c24639b29c818bda27b2d3a0 Mon Sep 17 00:00:00 2001 From: tangplin Date: Fri, 1 May 2015 22:23:56 +0800 Subject: [PATCH 122/470] Update README.md --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0012c050..d97af879 100644 --- a/README.md +++ b/README.md @@ -84,13 +84,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ##Integration -####Carthage -You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: -``` -github "SwiftyJSON/SwiftyJSON" >= 2.2 -``` - -####CocoaPods +####CocoaPods (iOS 8+, OS X 10.9+) You can use [Cocoapods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: ```ruby pod "SwiftyJSON", ">= 2.2" @@ -99,12 +93,19 @@ Note that it needs you to install CocoaPods 36 version, and requires your iOS de ```bash [sudo] gem install cocoapods -v '>=0.36' ``` -####Manually + +####Carthage (iOS 8+, OS X 10.9+) +You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: +``` +github "SwiftyJSON/SwiftyJSON" >= 2.2 +``` + +####Manually (iOS 7+, OS X 10.9+) To use this library in your project manually you may: 1. for Projects, just drag SwiftyJSON.swift to the project tree -2. for Workspaces, include the whole SwiftyJSON.xcodeproj (as suggested by @garnett) +2. for Workspaces, include the whole SwiftyJSON.xcodeproj ## Usage From 2c96a3e69b5936b8abc34c776309936d5fa7fb6f Mon Sep 17 00:00:00 2001 From: Petr Korolev Date: Mon, 4 May 2015 09:12:31 +0300 Subject: [PATCH 123/470] update change log --- CHANGELOG.md | 100 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40bde729..7b15b869 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,10 +2,62 @@ ## [Unreleased](https://github.com/SwiftyJSON/SwiftyJSON/tree/HEAD) -[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.1.3...HEAD) +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.2.0...HEAD) **Closed issues:** +- 156 compiler errors Mavericks + Xcode 6.2 [\#220](https://github.com/SwiftyJSON/SwiftyJSON/issues/220) + +- 'AnyObject' is not convertible to 'String'; did you mean to use 'as!' to force downcast? [\#218](https://github.com/SwiftyJSON/SwiftyJSON/issues/218) + +- pod -\> SwiftyJSON \(2.1.3\) is out-of-date if we compare it to the version mentioned in README.md file. [\#212](https://github.com/SwiftyJSON/SwiftyJSON/issues/212) + +- 无法获取到 2.2版本的 [\#211](https://github.com/SwiftyJSON/SwiftyJSON/issues/211) + +- Publish Podspec for version 2.2.0 [\#210](https://github.com/SwiftyJSON/SwiftyJSON/issues/210) + +- dropping elements? or am I doing something wrong? [\#209](https://github.com/SwiftyJSON/SwiftyJSON/issues/209) + +- Not working with Swift 1.2 [\#208](https://github.com/SwiftyJSON/SwiftyJSON/issues/208) + +- 在 Mac 项目里用 Carthage 无法编译 [\#193](https://github.com/SwiftyJSON/SwiftyJSON/issues/193) + +- 使用中发现解析效率比较低 [\#190](https://github.com/SwiftyJSON/SwiftyJSON/issues/190) + +- Looks like it will require a change of "as"es to "as!" for Swift 1.2... [\#150](https://github.com/SwiftyJSON/SwiftyJSON/issues/150) + +- No response appeared [\#118](https://github.com/SwiftyJSON/SwiftyJSON/issues/118) + +- Swift Optional Values from JSON [\#116](https://github.com/SwiftyJSON/SwiftyJSON/issues/116) + +- It seems not easy to manipulate an array or dictionary? [\#110](https://github.com/SwiftyJSON/SwiftyJSON/issues/110) + +**Merged pull requests:** + +- Fix for xcode 6.3..1 issue [\#224](https://github.com/SwiftyJSON/SwiftyJSON/pull/224) ([datomnurdin](https://github.com/datomnurdin)) + +- Update the first two examples snippets [\#223](https://github.com/SwiftyJSON/SwiftyJSON/pull/223) ([kmikael](https://github.com/kmikael)) + +- Allow .number to parse number from string instead of just numberValue [\#219](https://github.com/SwiftyJSON/SwiftyJSON/pull/219) ([yonaskolb](https://github.com/yonaskolb)) + +- Fixed spelling and grammar mistakes in README.md. Made some swift syntax... [\#214](https://github.com/SwiftyJSON/SwiftyJSON/pull/214) ([pRizz](https://github.com/pRizz)) + +## [2.2.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.2.0) (2015-04-13) + +[Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.1.3...2.2.0) + +**Closed issues:** + +- init doesn't set type correctly [\#206](https://github.com/SwiftyJSON/SwiftyJSON/issues/206) + +- SwitfyJSON breaks with update to iOS 8.3 & Xcode 6.3 [\#200](https://github.com/SwiftyJSON/SwiftyJSON/issues/200) + +- 'NSString?' is not convertible to 'String?' error with Swift 1.2 [\#198](https://github.com/SwiftyJSON/SwiftyJSON/issues/198) + +- I can't install it by carthage [\#181](https://github.com/SwiftyJSON/SwiftyJSON/issues/181) + +- Can't compare JSON to Float [\#171](https://github.com/SwiftyJSON/SwiftyJSON/issues/171) + - extend data to results [\#160](https://github.com/SwiftyJSON/SwiftyJSON/issues/160) - Create JSON From String [\#159](https://github.com/SwiftyJSON/SwiftyJSON/issues/159) @@ -28,6 +80,42 @@ **Merged pull requests:** +- Only building tests for testing [\#207](https://github.com/SwiftyJSON/SwiftyJSON/pull/207) ([spanage](https://github.com/spanage)) + +- Added compatibility with Swift 1.2. [\#204](https://github.com/SwiftyJSON/SwiftyJSON/pull/204) ([jankaltoun](https://github.com/jankaltoun)) + +- Fix for issue \#200 [\#203](https://github.com/SwiftyJSON/SwiftyJSON/pull/203) ([chschu](https://github.com/chschu)) + +- Updated to Swift 1.2 [\#202](https://github.com/SwiftyJSON/SwiftyJSON/pull/202) ([scottdelly](https://github.com/scottdelly)) + +- Updated to Swift 1.2 [\#201](https://github.com/SwiftyJSON/SwiftyJSON/pull/201) ([scottdelly](https://github.com/scottdelly)) + +- Update to Swift 1.2 [\#199](https://github.com/SwiftyJSON/SwiftyJSON/pull/199) ([kimdv](https://github.com/kimdv)) + +- Should not get subscript from AnyObject. [\#196](https://github.com/SwiftyJSON/SwiftyJSON/pull/196) ([Candyroot](https://github.com/Candyroot)) + +- Update for Swift 1.2 [\#195](https://github.com/SwiftyJSON/SwiftyJSON/pull/195) ([justinmakaila](https://github.com/justinmakaila)) + +- Update README.md [\#194](https://github.com/SwiftyJSON/SwiftyJSON/pull/194) ([manijshrestha](https://github.com/manijshrestha)) + +- Optimize the code to avoid useless casts to swift arrays. [\#188](https://github.com/SwiftyJSON/SwiftyJSON/pull/188) ([mirion](https://github.com/mirion)) + +- Fixed the buildable name in the OSX scheme [\#187](https://github.com/SwiftyJSON/SwiftyJSON/pull/187) ([cnoon](https://github.com/cnoon)) + +- Updated code signing identities for OSX target and tests [\#186](https://github.com/SwiftyJSON/SwiftyJSON/pull/186) ([cnoon](https://github.com/cnoon)) + +- Fix int overflow compile error [\#178](https://github.com/SwiftyJSON/SwiftyJSON/pull/178) ([mono0926](https://github.com/mono0926)) + +- Fixed a bug when accessing a value directly via a string subscript when the current object is a dictionary [\#176](https://github.com/SwiftyJSON/SwiftyJSON/pull/176) ([JosephDuffy](https://github.com/JosephDuffy)) + +- Better support for carthage users [\#174](https://github.com/SwiftyJSON/SwiftyJSON/pull/174) ([rromanchuk](https://github.com/rromanchuk)) + +- Fixes a 32bit/64bit issue. [\#172](https://github.com/SwiftyJSON/SwiftyJSON/pull/172) ([enhorn](https://github.com/enhorn)) + +- Update README for new Cocoapods [\#170](https://github.com/SwiftyJSON/SwiftyJSON/pull/170) ([joelparkerhenderson](https://github.com/joelparkerhenderson)) + +- Fixed a crash when entering json\["NotExistPath"\] [\#167](https://github.com/SwiftyJSON/SwiftyJSON/pull/167) ([ybeapps](https://github.com/ybeapps)) + - Adding Swift 1.2 support [\#158](https://github.com/SwiftyJSON/SwiftyJSON/pull/158) ([Jasdev](https://github.com/Jasdev)) - Fix issues with the OS X target and scheme [\#156](https://github.com/SwiftyJSON/SwiftyJSON/pull/156) ([rastersize](https://github.com/rastersize)) @@ -38,8 +126,12 @@ - Change to not build test when building iOS framework target \[Xcode 6.3 + external tools\] [\#153](https://github.com/SwiftyJSON/SwiftyJSON/pull/153) ([rastersize](https://github.com/rastersize)) +- Fix tests not building for 32-bit \[Xcode 6.3\] [\#152](https://github.com/SwiftyJSON/SwiftyJSON/pull/152) ([rastersize](https://github.com/rastersize)) + - Swift 1.2 compatibility fixes [\#149](https://github.com/SwiftyJSON/SwiftyJSON/pull/149) ([darrarski](https://github.com/darrarski)) +- \[README.md\] Setter for JSON array should use arrayObject not array [\#146](https://github.com/SwiftyJSON/SwiftyJSON/pull/146) ([lwu](https://github.com/lwu)) + - add missing ` in comments [\#142](https://github.com/SwiftyJSON/SwiftyJSON/pull/142) ([zhxnlai](https://github.com/zhxnlai)) - Fix README.md nested example [\#139](https://github.com/SwiftyJSON/SwiftyJSON/pull/139) ([watsonbox](https://github.com/watsonbox)) @@ -54,6 +146,10 @@ - Fixed the broken Carthage OS X Support. [\#134](https://github.com/SwiftyJSON/SwiftyJSON/pull/134) ([remaerd](https://github.com/remaerd)) +- Prefixed "SequenceType" extension with Module name [\#124](https://github.com/SwiftyJSON/SwiftyJSON/pull/124) ([ravero](https://github.com/ravero)) + +- Code cleaning [\#123](https://github.com/SwiftyJSON/SwiftyJSON/pull/123) ([wiruzx](https://github.com/wiruzx)) + ## [2.1.3](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.1.3) (2015-01-10) [Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.1.2...2.1.3) @@ -208,8 +304,6 @@ - Update for new features \[Issue \#60\] [\#63](https://github.com/SwiftyJSON/SwiftyJSON/pull/63) ([tangplin](https://github.com/tangplin)) -- SwiftJSON update feature implemented [\#61](https://github.com/SwiftyJSON/SwiftyJSON/pull/61) ([k06a](https://github.com/k06a)) - ## [1.1.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/1.1.0) (2014-10-02) [Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/1.0.0...1.1.0) From f75736d83fb054ac1bef62388823ebe28ab80a6e Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Tue, 5 May 2015 10:25:27 +0800 Subject: [PATCH 124/470] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index d97af879..a4ec415a 100644 --- a/README.md +++ b/README.md @@ -116,6 +116,11 @@ let json = JSON(data: dataFromNetworking) ```swift let json = JSON(jsonObject) ``` +```swift +if let dataFromString = jsonString.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false) { + let json = JSON(data: dataFromString) +} +``` ####Subscript ```swift From af9b44cea4d639d7a677df80ea383e5e7f044159 Mon Sep 17 00:00:00 2001 From: Sergey Lukjanov Date: Wed, 13 May 2015 14:52:31 -0700 Subject: [PATCH 125/470] Add Carthage/Build to .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 6e137049..2731938e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ DerivedData #CocoaPods Pods + +#Carthage +Carthage/Build From 6af1f1635bbe4540b9da35b84e4ed2ab871bbd21 Mon Sep 17 00:00:00 2001 From: xgdgsc Date: Sat, 16 May 2015 22:46:16 +0800 Subject: [PATCH 126/470] add instruction on import to README It wasn' t clear what to import in the doc. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index a4ec415a..14a99837 100644 --- a/README.md +++ b/README.md @@ -111,6 +111,9 @@ To use this library in your project manually you may: ####Initialization ```swift +import SwiftyJSON +``` +```swift let json = JSON(data: dataFromNetworking) ``` ```swift From 5d0eb07b85e3adc698f81c09906a8eae145c4fc0 Mon Sep 17 00:00:00 2001 From: tangplin Date: Mon, 25 May 2015 12:26:52 +0800 Subject: [PATCH 127/470] Update README.md --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 14a99837..67cfe17b 100644 --- a/README.md +++ b/README.md @@ -87,17 +87,19 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ####CocoaPods (iOS 8+, OS X 10.9+) You can use [Cocoapods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: ```ruby -pod "SwiftyJSON", ">= 2.2" +platform :ios, '8.0' +use_frameworks! + +target 'MyApp' do + pod 'SwiftyJSON', '~> 2.2.0' +end ``` Note that it needs you to install CocoaPods 36 version, and requires your iOS deploy target >= 8.0: -```bash -[sudo] gem install cocoapods -v '>=0.36' -``` ####Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` -github "SwiftyJSON/SwiftyJSON" >= 2.2 +github "SwiftyJSON/SwiftyJSON" >= 2.2.0 ``` ####Manually (iOS 7+, OS X 10.9+) From d93505a2d0e27eeb74d8a0d1bdc8a987ce6ea85d Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sat, 13 Jun 2015 13:55:07 +0800 Subject: [PATCH 128/470] Update for xcode7 --- Example.xcodeproj/project.pbxproj | 60 +++--- Example/Base.lproj/Main.storyboard | 16 +- Example/Info.plist | 2 +- Example/ViewController.swift | 41 ++-- Source/Info-OSX.plist | 2 +- Source/Info-iOS.plist | 2 +- Source/SwiftyJSON.swift | 120 +++++------ SwiftyJSON.xcodeproj/project.pbxproj | 14 +- .../xcschemes/SwiftyJSON OSX.xcscheme | 5 +- .../xcschemes/SwiftyJSON iOS.xcscheme | 5 +- Tests/BaseTests.swift | 24 +-- Tests/ComparableTests.swift | 188 +++++++++--------- Tests/Info-OSX.plist | 2 +- Tests/Info-iOS.plist | 2 +- Tests/LiteralConvertibleTests.swift | 10 +- Tests/NumberTests.swift | 6 +- Tests/PerformanceTests.swift | 4 +- Tests/PrintableTests.swift | 16 +- Tests/RawRepresentableTests.swift | 8 +- Tests/RawTests.swift | 26 ++- 20 files changed, 295 insertions(+), 258 deletions(-) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index 7279d2bf..6f81456d 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -18,20 +18,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 4EC1C1C91A0C1A2D0026ED0B; - remoteInfo = SwiftyJSONOSX; - }; - 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 4EC1C1D31A0C1A2D0026ED0B; - remoteInfo = SwiftyJSONOSXTests; - }; A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; @@ -53,6 +39,20 @@ remoteGlobalIDString = 2E4FEFDA19575BE100351305; remoteInfo = SwiftyJSON; }; + A88A00351B2ABAC3002E3C22 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 9C7DFC5B1A9102BD005AA3F7; + remoteInfo = "SwiftyJSON OSX"; + }; + A88A00371B2ABAC3002E3C22 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 9C7DFC651A9102BD005AA3F7; + remoteInfo = "SwiftyJSON OSX Tests"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -136,9 +136,9 @@ isa = PBXGroup; children = ( A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */, - A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */, - 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */, - 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */, + A82A1C4F19D94E86009A653D /* SwiftyJSON iOS Tests.xctest */, + A88A00361B2ABAC3002E3C22 /* SwiftyJSON.framework */, + A88A00381B2ABAC3002E3C22 /* SwiftyJSON OSX Tests.xctest */, ); name = Products; sourceTree = ""; @@ -171,7 +171,8 @@ A82A1C1119D926B8009A653D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0600; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; ORGANIZATIONNAME = swiftyjson; TargetAttributes = { A82A1C1819D926B8009A653D = { @@ -204,32 +205,32 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ - 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */ = { + A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = SwiftyJSON.framework; - remoteRef = 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */; + remoteRef = A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */ = { + A82A1C4F19D94E86009A653D /* SwiftyJSON iOS Tests.xctest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; - path = SwiftyJSONOSXTests.xctest; - remoteRef = 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */; + path = "SwiftyJSON iOS Tests.xctest"; + remoteRef = A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */ = { + A88A00361B2ABAC3002E3C22 /* SwiftyJSON.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; path = SwiftyJSON.framework; - remoteRef = A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */; + remoteRef = A88A00351B2ABAC3002E3C22 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; - A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */ = { + A88A00381B2ABAC3002E3C22 /* SwiftyJSON OSX Tests.xctest */ = { isa = PBXReferenceProxy; fileType = wrapper.cfbundle; - path = SwiftyJSONTests.xctest; - remoteRef = A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */; + path = "SwiftyJSON OSX Tests.xctest"; + remoteRef = A88A00371B2ABAC3002E3C22 /* PBXContainerItemProxy */; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXReferenceProxy section */ @@ -309,6 +310,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -376,6 +378,7 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -388,6 +391,7 @@ CODE_SIGN_IDENTITY = "iPhone Distribution"; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/Example/Base.lproj/Main.storyboard b/Example/Base.lproj/Main.storyboard index 57c3bd89..68803970 100644 --- a/Example/Base.lproj/Main.storyboard +++ b/Example/Base.lproj/Main.storyboard @@ -1,8 +1,14 @@ - + - + + + + + HelveticaNeue + + @@ -30,17 +36,21 @@ + + - + diff --git a/Example/Info.plist b/Example/Info.plist index 55f9d4e3..40c6215d 100644 --- a/Example/Info.plist +++ b/Example/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 6c3cb19d..09ef34a8 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -43,9 +43,9 @@ class ViewController: UITableViewController { } override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier("JSONCell", forIndexPath: indexPath) as! UITableViewCell + let cell = tableView.dequeueReusableCellWithIdentifier("JSONCell", forIndexPath: indexPath) as UITableViewCell - var row = indexPath.row + let row = indexPath.row switch self.json.type { case .Array: @@ -68,34 +68,31 @@ class ViewController: UITableViewController { override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { - var object: AnyObject + var nextController: UIViewController? switch UIDevice.currentDevice().systemVersion.compare("8.0.0", options: NSStringCompareOptions.NumericSearch) { case .OrderedSame, .OrderedDescending: - object = segue.destinationViewController.topViewController + nextController = (segue.destinationViewController as! UINavigationController).topViewController case .OrderedAscending: - object = segue.destinationViewController + nextController = segue.destinationViewController } - if let nextController = object as? ViewController { + if let indexPath = self.tableView.indexPathForSelectedRow { + let row = indexPath.row + var nextJson: JSON = JSON.nullJSON - if let indexPath = self.tableView.indexPathForSelectedRow() { - var row = indexPath.row - var nextJson: JSON = JSON.nullJSON - - switch self.json.type { - case .Array: - nextJson = self.json[row] - case .Dictionary where row < self.json.dictionaryValue.count: - let key = self.json.dictionaryValue.keys.array[row] - if let value = self.json.dictionary?[key] { - nextJson = value - } - default: - print("") + switch self.json.type { + case .Array: + nextJson = self.json[row] + case .Dictionary where row < self.json.dictionaryValue.count: + let key = self.json.dictionaryValue.keys.array[row] + if let value = self.json.dictionary?[key] { + nextJson = value } - nextController.json = nextJson - print(nextJson) + default: + print("") } + (nextController as! ViewController).json = nextJson + print(nextJson) } } } diff --git a/Source/Info-OSX.plist b/Source/Info-OSX.plist index 5d09593a..d3de8eef 100644 --- a/Source/Info-OSX.plist +++ b/Source/Info-OSX.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Source/Info-iOS.plist b/Source/Info-iOS.plist index 051fe5f9..78122054 100644 --- a/Source/Info-iOS.plist +++ b/Source/Info-iOS.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5407e9aa..2e56535b 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -58,16 +58,18 @@ public struct JSON { /** Creates a JSON using the data. - :param: data The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - :param: opt The JSON serialization reading options. `.AllowFragments` by default. - :param: error error The NSErrorPointer used to return the error. `nil` by default. + - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary + - parameter opt: The JSON serialization reading options. `.AllowFragments` by default. + - parameter error: error The NSErrorPointer used to return the error. `nil` by default. - :returns: The created JSON + - returns: The created JSON */ public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { - if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error) { + do { + let object: AnyObject = try NSJSONSerialization.JSONObjectWithData(data, options: opt) self.init(object) - } else { + } catch let aError as NSError { + error.memory = aError self.init(NSNull()) } } @@ -75,9 +77,9 @@ public struct JSON { /** Creates a JSON using the object. - :param: object The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. + - parameter object: The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. - :returns: The created JSON + - returns: The created JSON */ public init(_ object: AnyObject) { self.object = object @@ -86,9 +88,9 @@ public struct JSON { /** Creates a JSON from a [JSON] - :param: jsonArray A Swift array of JSON objects + - parameter jsonArray: A Swift array of JSON objects - :returns: The created JSON + - returns: The created JSON */ public init(_ jsonArray:[JSON]) { self.init(jsonArray.map { $0.object }) @@ -115,13 +117,13 @@ public struct JSON { } else { _type = .Number } - case let string as NSString: + case _ as NSString: _type = .String - case let null as NSNull: + case _ as NSNull: _type = .Null - case let array as [AnyObject]: + case _ as [AnyObject]: _type = .Array - case let dictionary as [String : AnyObject]: + case _ as [String : AnyObject]: _type = .Dictionary default: _type = .Unknown @@ -176,15 +178,15 @@ extension JSON : Swift.SequenceType { /** If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary`, otherwise return a generator over empty. - :returns: Return a *generator* over the elements of this *sequence*. + - returns: Return a *generator* over the elements of this *sequence*. */ - public func generate() -> GeneratorOf <(String, JSON)> { + public func generate() -> AnyGenerator<(String, JSON)> { switch self.type { case .Array: let array_ = object as! [AnyObject] var generate_ = array_.generate() var index_: Int = 0 - return GeneratorOf<(String, JSON)> { + return anyGenerator { if let element_: AnyObject = generate_.next() { return ("\(index_++)", JSON(element_)) } else { @@ -194,15 +196,15 @@ extension JSON : Swift.SequenceType { case .Dictionary: let dictionary_ = object as! [String : AnyObject] var generate_ = dictionary_.generate() - return GeneratorOf<(String, JSON)> { - if let (key_: String, value_: AnyObject) = generate_.next() { + return anyGenerator { + if let (key_, value_): (String, AnyObject) = generate_.next() { return (key_, JSON(value_)) } else { return nil } } default: - return GeneratorOf<(String, JSON)> { + return anyGenerator { return nil } } @@ -223,7 +225,7 @@ extension String: SubscriptType {} extension JSON { /// If `type` is `.Array`, return json which's object is `array[index]`, otherwise return null json with error. - private subscript(#index: Int) -> JSON { + private subscript(index index: Int) -> JSON { get { if self.type != .Array { @@ -254,7 +256,7 @@ extension JSON { } /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. - private subscript(#key: String) -> JSON { + private subscript(key key: String) -> JSON { get { var returnJSON = JSON.nullJSON if self.type == .Dictionary { @@ -279,7 +281,7 @@ extension JSON { } /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. - private subscript(#sub: SubscriptType) -> JSON { + private subscript(sub sub: SubscriptType) -> JSON { get { if sub is String { return self[key:sub as! String] @@ -299,7 +301,7 @@ extension JSON { /** Find a json in the complex data structuresby using the Int/String's array. - :param: path The target json's path. Example: + - parameter path: The target json's path. Example: let json = JSON[data] let path = [9,"list","person","name"] @@ -307,7 +309,7 @@ extension JSON { The same as: let name = json[9]["list"]["person"]["name"] - :returns: Return a json found by the path or a null json with error + - returns: Return a json found by the path or a null json with error */ public subscript(path: [SubscriptType]) -> JSON { get { @@ -330,7 +332,7 @@ extension JSON { var last = newValue var newPath = path newPath.removeLast() - for sub in path.reverse() { + for sub in Array(path.reverse()) { var previousLast = self[newPath] previousLast[sub:sub] = last last = previousLast @@ -347,13 +349,13 @@ extension JSON { /** Find a json in the complex data structuresby using the Int/String's array. - :param: path The target json's path. Example: + - parameter path: The target json's path. Example: let name = json[9,"list","person","name"] The same as: let name = json[9]["list"]["person"]["name"] - :returns: Return a json found by the path or a null json with error + - returns: Return a json found by the path or a null json with error */ public subscript(path: SubscriptType...) -> JSON { get { @@ -444,16 +446,17 @@ extension JSON: Swift.RawRepresentable { return self.object } - public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(0), error: NSErrorPointer = nil) -> NSData? { - return NSJSONSerialization.dataWithJSONObject(self.object, options: opt, error:error) + public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(rawValue: 0)) throws -> NSData { + return try NSJSONSerialization.dataWithJSONObject(self.object, options: opt) } public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted) -> String? { switch self.type { case .Array, .Dictionary: - if let data = self.rawData(options: opt) { + do { + let data = try self.rawData(options: opt) return NSString(data: data, encoding: encoding) as? String - } else { + } catch _ { return nil } case .String: @@ -495,7 +498,7 @@ extension JSON { public var array: [JSON]? { get { if self.type == .Array { - return map(self.object as! [AnyObject]){ JSON($0) } + return (self.object as! [AnyObject]).map{ JSON($0) } } else { return nil } @@ -1111,7 +1114,8 @@ extension NSNumber: Swift.Comparable { var isBool:Bool { get { let objCType = String.fromCString(self.objCType) - if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ + if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) + || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ return true } else { return false @@ -1185,160 +1189,160 @@ public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { //MARK:- Unavailable -@availability(*, unavailable, renamed="JSON") +@available(*, unavailable, renamed="JSON") public typealias JSONValue = JSON extension JSON { - @availability(*, unavailable, message="use 'init(_ object:AnyObject)' instead") + @available(*, unavailable, message="use 'init(_ object:AnyObject)' instead") public init(object: AnyObject) { self = JSON(object) } - @availability(*, unavailable, renamed="dictionaryObject") + @available(*, unavailable, renamed="dictionaryObject") public var dictionaryObjects: [String : AnyObject]? { get { return self.dictionaryObject } } - @availability(*, unavailable, renamed="arrayObject") + @available(*, unavailable, renamed="arrayObject") public var arrayObjects: [AnyObject]? { get { return self.arrayObject } } - @availability(*, unavailable, renamed="int8") + @available(*, unavailable, renamed="int8") public var char: Int8? { get { return self.number?.charValue } } - @availability(*, unavailable, renamed="int8Value") + @available(*, unavailable, renamed="int8Value") public var charValue: Int8 { get { return self.numberValue.charValue } } - @availability(*, unavailable, renamed="uInt8") + @available(*, unavailable, renamed="uInt8") public var unsignedChar: UInt8? { get{ return self.number?.unsignedCharValue } } - @availability(*, unavailable, renamed="uInt8Value") + @available(*, unavailable, renamed="uInt8Value") public var unsignedCharValue: UInt8 { get{ return self.numberValue.unsignedCharValue } } - @availability(*, unavailable, renamed="int16") + @available(*, unavailable, renamed="int16") public var short: Int16? { get{ return self.number?.shortValue } } - @availability(*, unavailable, renamed="int16Value") + @available(*, unavailable, renamed="int16Value") public var shortValue: Int16 { get{ return self.numberValue.shortValue } } - @availability(*, unavailable, renamed="uInt16") + @available(*, unavailable, renamed="uInt16") public var unsignedShort: UInt16? { get{ return self.number?.unsignedShortValue } } - @availability(*, unavailable, renamed="uInt16Value") + @available(*, unavailable, renamed="uInt16Value") public var unsignedShortValue: UInt16 { get{ return self.numberValue.unsignedShortValue } } - @availability(*, unavailable, renamed="int") + @available(*, unavailable, renamed="int") public var long: Int? { get{ return self.number?.longValue } } - @availability(*, unavailable, renamed="intValue") + @available(*, unavailable, renamed="intValue") public var longValue: Int { get{ return self.numberValue.longValue } } - @availability(*, unavailable, renamed="uInt") + @available(*, unavailable, renamed="uInt") public var unsignedLong: UInt? { get{ return self.number?.unsignedLongValue } } - @availability(*, unavailable, renamed="uIntValue") + @available(*, unavailable, renamed="uIntValue") public var unsignedLongValue: UInt { get{ return self.numberValue.unsignedLongValue } } - @availability(*, unavailable, renamed="int64") + @available(*, unavailable, renamed="int64") public var longLong: Int64? { get{ return self.number?.longLongValue } } - @availability(*, unavailable, renamed="int64Value") + @available(*, unavailable, renamed="int64Value") public var longLongValue: Int64 { get{ return self.numberValue.longLongValue } } - @availability(*, unavailable, renamed="uInt64") + @available(*, unavailable, renamed="uInt64") public var unsignedLongLong: UInt64? { get{ return self.number?.unsignedLongLongValue } } - @availability(*, unavailable, renamed="uInt64Value") + @available(*, unavailable, renamed="uInt64Value") public var unsignedLongLongValue: UInt64 { get{ return self.numberValue.unsignedLongLongValue } } - @availability(*, unavailable, renamed="int") + @available(*, unavailable, renamed="int") public var integer: Int? { get { return self.number?.integerValue } } - @availability(*, unavailable, renamed="intValue") + @available(*, unavailable, renamed="intValue") public var integerValue: Int { get { return self.numberValue.integerValue } } - @availability(*, unavailable, renamed="uInt") + @available(*, unavailable, renamed="uInt") public var unsignedInteger: Int? { get { return self.number?.unsignedIntegerValue } } - @availability(*, unavailable, renamed="uIntValue") + @available(*, unavailable, renamed="uIntValue") public var unsignedIntegerValue: Int { get { return self.numberValue.unsignedIntegerValue diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index fda17ec2..20c72f44 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -291,7 +291,8 @@ 2E4FEFD219575BE100351305 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0600; + LastSwiftUpdateCheck = 0700; + LastUpgradeCheck = 0700; TargetAttributes = { 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; @@ -455,6 +456,7 @@ COPY_PHASE_STRIP = NO; CURRENT_PROJECT_VERSION = 1; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -469,7 +471,6 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -510,7 +511,6 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.10; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -534,6 +534,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; }; @@ -552,6 +553,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; }; @@ -571,6 +573,7 @@ INFOPLIST_FILE = "Tests/Info-iOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -585,6 +588,7 @@ INFOPLIST_FILE = "Tests/Info-iOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; @@ -607,6 +611,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -628,6 +633,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; @@ -650,6 +656,7 @@ INFOPLIST_FILE = "Tests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; @@ -668,6 +675,7 @@ INFOPLIST_FILE = "Tests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; }; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme index 5f5ee34a..1441778e 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -1,6 +1,6 @@ + + + + = -37434) - var jsonL2:JSON = 8773 - var jsonR2:JSON = JSON(-87343) + let jsonL2:JSON = 8773 + let jsonR2:JSON = JSON(-87343) XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) XCTAssertTrue(jsonR2 >= -988343) - var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - var jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) XCTAssertGreaterThanOrEqual(jsonL3, jsonR3) XCTAssertTrue(jsonR3 >= 0.3232) } func testNumberLessThanOrEqual() { - var jsonL1:JSON = 1234567890.876623 - var jsonR1:JSON = JSON(123.123) + let jsonL1:JSON = 1234567890.876623 + let jsonR1:JSON = JSON(123.123) XCTAssertLessThanOrEqual(jsonR1, jsonL1) XCTAssertFalse(83487343.3493 <= jsonR1) - var jsonL2:JSON = 8773 - var jsonR2:JSON = JSON(-123.23) + let jsonL2:JSON = 8773 + let jsonR2:JSON = JSON(-123.23) XCTAssertLessThanOrEqual(jsonR2, jsonL2) XCTAssertFalse(9348343 <= jsonR2) - var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - var jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) XCTAssertLessThanOrEqual(jsonR3, jsonL3) XCTAssertTrue(87621.12345678 <= jsonR3) } func testNumberGreaterThan() { - var jsonL1:JSON = 1234567890.876623 - var jsonR1:JSON = JSON(123.123) + let jsonL1:JSON = 1234567890.876623 + let jsonR1:JSON = JSON(123.123) XCTAssertGreaterThan(jsonL1, jsonR1) XCTAssertFalse(jsonR1 > 192388843.0988) - var jsonL2:JSON = 8773 - var jsonR2:JSON = JSON(123.23) + let jsonL2:JSON = 8773 + let jsonR2:JSON = JSON(123.23) XCTAssertGreaterThan(jsonL2, jsonR2) XCTAssertFalse(jsonR2 > 877434) - var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - var jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) + let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) XCTAssertGreaterThan(jsonL3, jsonR3) XCTAssertFalse(-7799 > jsonR3) } func testNumberLessThan() { - var jsonL1:JSON = 1234567890.876623 - var jsonR1:JSON = JSON(123.123) + let jsonL1:JSON = 1234567890.876623 + let jsonR1:JSON = JSON(123.123) XCTAssertLessThan(jsonR1, jsonL1) XCTAssertTrue(jsonR1 < 192388843.0988) - var jsonL2:JSON = 8773 - var jsonR2:JSON = JSON(123.23) + let jsonL2:JSON = 8773 + let jsonR2:JSON = JSON(123.23) XCTAssertLessThan(jsonR2, jsonL2) XCTAssertTrue(jsonR2 < 877434) - var jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - var jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) + let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) XCTAssertLessThan(jsonR3, jsonL3) XCTAssertTrue(-7799 < jsonR3) } func testBoolEqual() { - var jsonL1:JSON = true - var jsonR1:JSON = JSON(true) + let jsonL1:JSON = true + let jsonR1:JSON = JSON(true) XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 == true) - var jsonL2:JSON = false - var jsonR2:JSON = JSON(false) + let jsonL2:JSON = false + let jsonR2:JSON = JSON(false) XCTAssertEqual(jsonL2, jsonR2) XCTAssertTrue(jsonL2 == false) } func testBoolNotEqual() { - var jsonL1:JSON = true - var jsonR1:JSON = JSON(false) + let jsonL1:JSON = true + let jsonR1:JSON = JSON(false) XCTAssertNotEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 != false) - var jsonL2:JSON = false - var jsonR2:JSON = JSON(true) + let jsonL2:JSON = false + let jsonR2:JSON = JSON(true) XCTAssertNotEqual(jsonL2, jsonR2) XCTAssertTrue(jsonL2 != true) } func testBoolGreaterThanOrEqual() { - var jsonL1:JSON = true - var jsonR1:JSON = JSON(true) + let jsonL1:JSON = true + let jsonR1:JSON = JSON(true) XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 >= true) - var jsonL2:JSON = false - var jsonR2:JSON = JSON(false) + let jsonL2:JSON = false + let jsonR2:JSON = JSON(false) XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) XCTAssertFalse(jsonL2 >= true) } func testBoolLessThanOrEqual() { - var jsonL1:JSON = true - var jsonR1:JSON = JSON(true) + let jsonL1:JSON = true + let jsonR1:JSON = JSON(true) XCTAssertLessThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(true <= jsonR1) - var jsonL2:JSON = false - var jsonR2:JSON = JSON(false) + let jsonL2:JSON = false + let jsonR2:JSON = JSON(false) XCTAssertLessThanOrEqual(jsonL2, jsonR2) XCTAssertFalse(jsonL2 <= true) } func testBoolGreaterThan() { - var jsonL1:JSON = true - var jsonR1:JSON = JSON(true) + let jsonL1:JSON = true + let jsonR1:JSON = JSON(true) XCTAssertFalse(jsonL1 > jsonR1) XCTAssertFalse(jsonL1 > true) XCTAssertFalse(jsonR1 > false) - var jsonL2:JSON = false - var jsonR2:JSON = JSON(false) + let jsonL2:JSON = false + let jsonR2:JSON = JSON(false) XCTAssertFalse(jsonL2 > jsonR2) XCTAssertFalse(jsonL2 > false) XCTAssertFalse(jsonR2 > true) - var jsonL3:JSON = true - var jsonR3:JSON = JSON(false) + let jsonL3:JSON = true + let jsonR3:JSON = JSON(false) XCTAssertFalse(jsonL3 > jsonR3) XCTAssertFalse(jsonL3 > false) XCTAssertFalse(jsonR3 > true) - var jsonL4:JSON = false - var jsonR4:JSON = JSON(true) + let jsonL4:JSON = false + let jsonR4:JSON = JSON(true) XCTAssertFalse(jsonL4 > jsonR4) XCTAssertFalse(jsonL4 > false) XCTAssertFalse(jsonR4 > true) } func testBoolLessThan() { - var jsonL1:JSON = true - var jsonR1:JSON = JSON(true) + let jsonL1:JSON = true + let jsonR1:JSON = JSON(true) XCTAssertFalse(jsonL1 < jsonR1) XCTAssertFalse(jsonL1 < true) XCTAssertFalse(jsonR1 < false) - var jsonL2:JSON = false - var jsonR2:JSON = JSON(false) + let jsonL2:JSON = false + let jsonR2:JSON = JSON(false) XCTAssertFalse(jsonL2 < jsonR2) XCTAssertFalse(jsonL2 < false) XCTAssertFalse(jsonR2 < true) - var jsonL3:JSON = true - var jsonR3:JSON = JSON(false) + let jsonL3:JSON = true + let jsonR3:JSON = JSON(false) XCTAssertFalse(jsonL3 < jsonR3) XCTAssertFalse(jsonL3 < false) XCTAssertFalse(jsonR3 < true) - var jsonL4:JSON = false - var jsonR4:JSON = JSON(true) + let jsonL4:JSON = false + let jsonR4:JSON = JSON(true) XCTAssertFalse(jsonL4 < jsonR4) XCTAssertFalse(jsonL4 < false) XCTAssertFalse(true < jsonR4) } func testStringEqual() { - var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 == "abcdefg 123456789 !@#$%^&*()") } func testStringNotEqual() { - var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - var jsonR1:JSON = JSON("-=[]\\\"987654321") + let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1:JSON = JSON("-=[]\\\"987654321") XCTAssertNotEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 != "not equal") } func testStringGreaterThanOrEqual() { - var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 >= "abcdefg 123456789 !@#$%^&*()") - var jsonL2:JSON = "z-+{}:" - var jsonR2:JSON = JSON("a<>?:") + let jsonL2:JSON = "z-+{}:" + let jsonR2:JSON = JSON("a<>?:") XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) XCTAssertTrue(jsonL2 >= "mnbvcxz") } func testStringLessThanOrEqual() { - var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertLessThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 <= "abcdefg 123456789 !@#$%^&*()") - var jsonL2:JSON = "z-+{}:" - var jsonR2:JSON = JSON("a<>?:") + let jsonL2:JSON = "z-+{}:" + let jsonR2:JSON = JSON("a<>?:") XCTAssertLessThanOrEqual(jsonR2, jsonL2) XCTAssertTrue("mnbvcxz" <= jsonL2) } func testStringGreaterThan() { - var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertFalse(jsonL1 > jsonR1) XCTAssertFalse(jsonL1 > "abcdefg 123456789 !@#$%^&*()") - var jsonL2:JSON = "z-+{}:" - var jsonR2:JSON = JSON("a<>?:") + let jsonL2:JSON = "z-+{}:" + let jsonR2:JSON = JSON("a<>?:") XCTAssertGreaterThan(jsonL2, jsonR2) XCTAssertFalse("87663434" > jsonL2) } func testStringLessThan() { - var jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - var jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertFalse(jsonL1 < jsonR1) XCTAssertFalse(jsonL1 < "abcdefg 123456789 !@#$%^&*()") - var jsonL2:JSON = "98774" - var jsonR2:JSON = JSON("123456") + let jsonL2:JSON = "98774" + let jsonR2:JSON = JSON("123456") XCTAssertLessThan(jsonR2, jsonL2) XCTAssertFalse(jsonL2 < "09") } func testNil() { - var jsonL1:JSON = nil - var jsonR1:JSON = JSON(NSNull()) + let jsonL1:JSON = nil + let jsonR1:JSON = JSON(NSNull()) XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 != "123") XCTAssertFalse(jsonL1 > "abcd") @@ -310,8 +310,8 @@ class ComparableTests: XCTestCase { } func testArray() { - var jsonL1:JSON = [1,2,"4",5,"6"] - var jsonR1:JSON = JSON([1,2,"4",5,"6"]) + let jsonL1:JSON = [1,2,"4",5,"6"] + let jsonR1:JSON = JSON([1,2,"4",5,"6"]) XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 == [1,2,"4",5,"6"]) XCTAssertTrue(jsonL1 != ["abcd","efg"]) @@ -323,8 +323,8 @@ class ComparableTests: XCTestCase { } func testDictionary() { - var jsonL1:JSON = ["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]] - var jsonR1:JSON = JSON(["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]]) + let jsonL1:JSON = ["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]] + let jsonR1:JSON = JSON(["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]]) XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 != ["1":2,"Hello":"World","Koo":"Foo"]) diff --git a/Tests/Info-OSX.plist b/Tests/Info-OSX.plist index 75bab451..ba72822e 100644 --- a/Tests/Info-OSX.plist +++ b/Tests/Info-OSX.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Tests/Info-iOS.plist b/Tests/Info-iOS.plist index 84bb0558..6d32c15c 100644 --- a/Tests/Info-iOS.plist +++ b/Tests/Info-iOS.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.swiftyjson.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift index bc9d0e47..ecbfb3fc 100644 --- a/Tests/LiteralConvertibleTests.swift +++ b/Tests/LiteralConvertibleTests.swift @@ -51,22 +51,22 @@ class LiteralConvertibleTests: XCTestCase { } func testNil() { - var jsonNil_1:JSON = nil + let jsonNil_1:JSON = nil XCTAssert(jsonNil_1 == nil) - var jsonNil_2:JSON = JSON(NSNull) + let jsonNil_2:JSON = JSON(NSNull) XCTAssert(jsonNil_2 != nil) - var jsonNil_3:JSON = JSON([1:2]) + let jsonNil_3:JSON = JSON([1:2]) XCTAssert(jsonNil_3 != nil) } func testArray() { - var json:JSON = [1,2,"4",5,"6"] + let json:JSON = [1,2,"4",5,"6"] XCTAssertEqual(json.array!, [1,2,"4",5,"6"]) XCTAssertEqual(json.arrayValue, [1,2,"4",5,"6"]) } func testDictionary() { - var json:JSON = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] + let json:JSON = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] XCTAssertEqual(json.dictionary!, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) XCTAssertEqual(json.dictionaryValue, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) } diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 5254c348..fb82f350 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -93,7 +93,7 @@ class NumberTests: XCTestCase { var json = JSON(54321.12345) XCTAssertTrue(json.float! == 54321.12345) XCTAssertTrue(json.floatValue == 54321.12345) - println(json.numberValue.doubleValue) + print(json.numberValue.doubleValue) XCTAssertEqual(json.numberValue, 54321.12345) XCTAssertEqual(json.stringValue, "54321.12345") @@ -179,7 +179,7 @@ class NumberTests: XCTestCase { json.int8Value = n0.charValue XCTAssertTrue(json.int8! == n0.charValue) XCTAssertTrue(json.int8Value == n0.charValue) - println(json.number) + print(json.number) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) #if (arch(x86_64) || arch(arm64)) @@ -258,7 +258,7 @@ class NumberTests: XCTestCase { json.int16Value = n0.shortValue XCTAssertTrue(json.int16! == n0.shortValue) XCTAssertTrue(json.int16Value == n0.shortValue) - println(json.number) + print(json.number) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) XCTAssertEqual(json.stringValue, "0") diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index 598f3a6d..5b4e9243 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -78,7 +78,7 @@ class PerformanceTests: XCTestCase { self.measureBlock() { for _ in 1...100 { autoreleasepool{ - var dictionary = json.dictionary + let dictionary = json.dictionary XCTAssertTrue(dictionary?.count > 0) } } @@ -90,7 +90,7 @@ class PerformanceTests: XCTestCase { self.measureBlock() { for _ in 1...100 { autoreleasepool{ - var string = json.rawString() + let string = json.rawString() XCTAssertTrue(string != nil) } } diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index ef22802a..2a4203d7 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -25,37 +25,37 @@ import SwiftyJSON class PrintableTests: XCTestCase { func testNumber() { - var json:JSON = 1234567890.876623 + let json:JSON = 1234567890.876623 XCTAssertEqual(json.description, "1234567890.876623") XCTAssertEqual(json.debugDescription, "1234567890.876623") } func testBool() { - var jsonTrue:JSON = true + let jsonTrue:JSON = true XCTAssertEqual(jsonTrue.description, "true") XCTAssertEqual(jsonTrue.debugDescription, "true") - var jsonFalse:JSON = false + let jsonFalse:JSON = false XCTAssertEqual(jsonFalse.description, "false") XCTAssertEqual(jsonFalse.debugDescription, "false") } func testString() { - var json:JSON = "abcd efg, HIJK;LMn" + let json:JSON = "abcd efg, HIJK;LMn" XCTAssertEqual(json.description, "abcd efg, HIJK;LMn") XCTAssertEqual(json.debugDescription, "abcd efg, HIJK;LMn") } func testNil() { - var jsonNil_1:JSON = nil + let jsonNil_1:JSON = nil XCTAssertEqual(jsonNil_1.description, "null") XCTAssertEqual(jsonNil_1.debugDescription, "null") - var jsonNil_2:JSON = JSON(NSNull()) + let jsonNil_2:JSON = JSON(NSNull()) XCTAssertEqual(jsonNil_2.description, "null") XCTAssertEqual(jsonNil_2.debugDescription, "null") } func testArray() { - var json:JSON = [1,2,"4",5,"6"] + let json:JSON = [1,2,"4",5,"6"] var description = json.description.stringByReplacingOccurrencesOfString("\n", withString: "") description = description.stringByReplacingOccurrencesOfString(" ", withString: "") XCTAssertEqual(description, "[1,2,\"4\",5,\"6\"]") @@ -64,7 +64,7 @@ class PrintableTests: XCTestCase { } func testDictionary() { - var json:JSON = ["1":2,"2":"two", "3":3] + let json:JSON = ["1":2,"2":"two", "3":3] var debugDescription = json.debugDescription.stringByReplacingOccurrencesOfString("\n", withString: "") debugDescription = debugDescription.stringByReplacingOccurrencesOfString(" ", withString: "") XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index 038264e0..59397f50 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -34,7 +34,7 @@ class RawRepresentableTests: XCTestCase { XCTAssertTrue(json.float! == 948394394.347384) XCTAssertTrue(json.floatValue == 948394394.347384) - var object: AnyObject = json.rawValue + let object: AnyObject = json.rawValue XCTAssertEqual(object as! Int, 948394394) XCTAssertEqual(object as! Double, 948394394.347384) XCTAssertTrue(object as! Float == 948394394.347384) @@ -50,13 +50,13 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(jsonFalse.bool!, false) XCTAssertEqual(jsonFalse.boolValue, false) - var objectTrue: AnyObject = jsonTrue.rawValue + let objectTrue: AnyObject = jsonTrue.rawValue XCTAssertEqual(objectTrue as! Int, 1) XCTAssertEqual(objectTrue as! Double, 1.0) XCTAssertEqual(objectTrue as! Bool, true) XCTAssertEqual(objectTrue as! NSNumber, NSNumber(bool: true)) - var objectFalse: AnyObject = jsonFalse.rawValue + let objectFalse: AnyObject = jsonFalse.rawValue XCTAssertEqual(objectFalse as! Int, 0) XCTAssertEqual(objectFalse as! Double, 0.0) XCTAssertEqual(objectFalse as! Bool, false) @@ -83,7 +83,7 @@ class RawRepresentableTests: XCTestCase { } func testNil() { - if let json = JSON(rawValue: NSObject()) { + if let _ = JSON(rawValue: NSObject()) { XCTFail("Should not run into here") } } diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index d92ba3ac..171af007 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -27,43 +27,53 @@ class RawTests: XCTestCase { func testArray() { let json:JSON = [1, "2", 3.12, NSNull(), true, ["name": "Jack"]] - let data = json.rawData() + let data: NSData? + do { + data = try json.rawData() + } catch _ { + data = nil + } let string = json.rawString() XCTAssertTrue (data != nil) XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) - println(string!) + print(string!) } func testDictionary() { let json:JSON = ["number":111111.23456789, "name":"Jack", "list":[1,2,3,4], "bool":false, "null":NSNull()] - let data = json.rawData() + let data: NSData? + do { + data = try json.rawData() + } catch _ { + data = nil + } let string = json.rawString() XCTAssertTrue (data != nil) XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) - println(string!) + print(string!) } func testString() { let json:JSON = "I'm a json" - println(json.rawString()) + print(json.rawString()) XCTAssertTrue(json.rawString() == "I'm a json") } func testNumber() { let json:JSON = 123456789.123 - println(json.rawString()) + print(json.rawString()) XCTAssertTrue(json.rawString() == "123456789.123") } func testBool() { let json:JSON = true - println(json.rawString()) + print(json.rawString()) XCTAssertTrue(json.rawString() == "true") } func testNull() { let json:JSON = nil - println(json.rawString()) + print(json.rawString()) XCTAssertTrue(json.rawString() == "null") } } From 62b581e14c5a813b1195d43faf61efe035a114c1 Mon Sep 17 00:00:00 2001 From: tangplin Date: Sat, 13 Jun 2015 13:58:19 +0800 Subject: [PATCH 129/470] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67cfe17b..df96815d 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ## Requirements - iOS 7.0+ / Mac OS X 10.9+ -- Xcode 6.1 +- Xcode 6.3 ##Integration From e85218625a90aa8f329899c746d79616464bcdf7 Mon Sep 17 00:00:00 2001 From: Rameez Remsudeen Date: Tue, 16 Jun 2015 17:59:42 +0800 Subject: [PATCH 130/470] Updated Readme to swift 2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 67cfe17b..0d60fa30 100644 --- a/README.md +++ b/README.md @@ -157,7 +157,7 @@ let name = json[keys].string ####Loop ```swift //If json is .Dictionary -for (key: String, subJson: JSON) in json { +for (key,subJson):(String, JSON) in json { //Do something you want } ``` @@ -165,7 +165,7 @@ for (key: String, subJson: JSON) in json { ```swift //If json is .Array //The `index` is 0.. Date: Fri, 19 Jun 2015 16:25:26 +0800 Subject: [PATCH 131/470] Update subscript(path: [SubscriptType]) --- Source/SwiftyJSON.swift | 35 ++++++++++++----------------------- Tests/SubscriptTests.swift | 26 +++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 24 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 2e56535b..9dd875b0 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -313,35 +313,24 @@ extension JSON { */ public subscript(path: [SubscriptType]) -> JSON { get { - if path.count == 0 { - return JSON.nullJSON - } - - var next = self - for sub in path { - next = next[sub:sub] + switch path.count { + case 0: return JSON.nullJSON + case 1: return self[sub: path[0]] + default: + var aPath = path; aPath.removeAtIndex(0) + let nextJSON = self[sub: path[0]] + return nextJSON[aPath] } - return next } set { - switch path.count { case 0: return - case 1: self[sub:path[0]] = newValue + case 1: self[sub:path[0]].object = newValue.object default: - var last = newValue - var newPath = path - newPath.removeLast() - for sub in Array(path.reverse()) { - var previousLast = self[newPath] - previousLast[sub:sub] = last - last = previousLast - if newPath.count <= 1 { - break - } - newPath.removeLast() - } - self[sub:newPath[0]] = last + var aPath = path; aPath.removeAtIndex(0) + var nextJSON = self[sub: path[0]] + nextJSON[aPath] = newValue + self[sub: path[0]] = nextJSON } } } diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 126be1f4..1f294fa2 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -220,7 +220,7 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[0][0][0][0]["one"].int!, 1) } - func testMultilevelSetter() { + func testMultilevelSetter1() { var json:JSON = [[[[["num":1]]]]] json[0, 0, 0, 0, "num"] = 2 XCTAssertEqual(json[[0, 0, 0, 0, "num"]].intValue, 2) @@ -238,4 +238,28 @@ class SubscriptTests: XCTestCase { json[path].string = "Jim" XCTAssertEqual(json[path].stringValue, "Jim") } + + func testMultilevelSetter2() { + var json:JSON = ["user":["id":987654, "info":["name":"jack","email":"jack@gmail.com"], "feeds":[98833,23443,213239,23232]]] + json["user","info","name"] = "jim" + XCTAssertEqual(json["user","id"], 987654) + XCTAssertEqual(json["user","info","name"], "jim") + XCTAssertEqual(json["user","info","email"], "jack@gmail.com") + XCTAssertEqual(json["user","feeds"], [98833,23443,213239,23232]) + json["user","info","email"] = "jim@hotmail.com" + XCTAssertEqual(json["user","id"], 987654) + XCTAssertEqual(json["user","info","name"], "jim") + XCTAssertEqual(json["user","info","email"], "jim@hotmail.com") + XCTAssertEqual(json["user","feeds"], [98833,23443,213239,23232]) + json["user","info"] = ["name":"tom","email":"tom@qq.com"] + XCTAssertEqual(json["user","id"], 987654) + XCTAssertEqual(json["user","info","name"], "tom") + XCTAssertEqual(json["user","info","email"], "tom@qq.com") + XCTAssertEqual(json["user","feeds"], [98833,23443,213239,23232]) + json["user","feeds"] = [77323,2313,4545,323] + XCTAssertEqual(json["user","id"], 987654) + XCTAssertEqual(json["user","info","name"], "tom") + XCTAssertEqual(json["user","info","email"], "tom@qq.com") + XCTAssertEqual(json["user","feeds"], [77323,2313,4545,323]) + } } From fb9f6b43cd8d3684c3129793057eb2a2564e2430 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Fri, 19 Jun 2015 17:19:45 +0800 Subject: [PATCH 132/470] Update nullJSON to null --- Source/SwiftyJSON.swift | 13 +++++++------ Tests/DictionaryTests.swift | 4 ++-- Tests/PerformanceTests.swift | 2 +- Tests/SubscriptTests.swift | 10 +++++----- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 9dd875b0..d9e7e87e 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -140,8 +140,9 @@ public struct JSON { public var error: NSError? { get { return self._error } } /// The static null json - public static var nullJSON: JSON { get { return JSON(NSNull()) } } - + @available(*, unavailable, renamed="null") + public static var nullJSON: JSON { get { return null } } + public static var null: JSON { get { return JSON(NSNull()) } } } // MARK: - SequenceType @@ -229,7 +230,7 @@ extension JSON { get { if self.type != .Array { - var errorResult_ = JSON.nullJSON + var errorResult_ = JSON.null errorResult_._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) return errorResult_ } @@ -240,7 +241,7 @@ extension JSON { return JSON(array_[index]) } - var errorResult_ = JSON.nullJSON + var errorResult_ = JSON.null errorResult_._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) return errorResult_ } @@ -258,7 +259,7 @@ extension JSON { /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. private subscript(key key: String) -> JSON { get { - var returnJSON = JSON.nullJSON + var returnJSON = JSON.null if self.type == .Dictionary { let dictionary_ = self.object as! [String : AnyObject] if let object_: AnyObject = dictionary_[key] { @@ -314,7 +315,7 @@ extension JSON { public subscript(path: [SubscriptType]) -> JSON { get { switch path.count { - case 0: return JSON.nullJSON + case 0: return JSON.null case 1: return self[sub: path[0]] default: var aPath = path; aPath.removeAtIndex(0) diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index b0d26b38..b384bfae 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -39,11 +39,11 @@ class DictionaryTests: XCTestCase { XCTAssertEqual(((((json.dictionaryValue)["object"]! as JSON).dictionaryValue)["sub_name"]! as JSON).string!, "sub_name") XCTAssertEqual((json.dictionaryValue["bool"]! as JSON).bool!, true) XCTAssertTrue(json.dictionaryValue["null"] == nil) - XCTAssertTrue(JSON.nullJSON.dictionaryValue == [:]) + XCTAssertTrue(JSON.null.dictionaryValue == [:]) //dictionaryObject XCTAssertEqual(json.dictionaryObject!["number"]! as! Double, 9823.212) XCTAssertTrue(json.dictionaryObject!["null"] == nil) - XCTAssertTrue(JSON.nullJSON.dictionaryObject == nil) + XCTAssertTrue(JSON.null.dictionaryObject == nil) } func testSetter() { diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index 5b4e9243..c7cd7450 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -46,7 +46,7 @@ class PerformanceTests: XCTestCase { self.measureBlock() { for _ in 1...100 { let json = JSON(data:self.testData) - XCTAssertTrue(json != JSON.nullJSON) + XCTAssertTrue(json != JSON.null) } } } diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 1f294fa2..9d86e81a 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -179,10 +179,10 @@ class SubscriptTests: XCTestCase { func testOutOfBounds() { let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) - XCTAssertEqual(json[9], JSON.nullJSON) + XCTAssertEqual(json[9], JSON.null) XCTAssertEqual(json[-2].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) - XCTAssertEqual(json[9][8], JSON.nullJSON) + XCTAssertEqual(json[9][8], JSON.null) XCTAssertEqual(json[8][7].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[8,7].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[999].error!.code, ErrorIndexOutOfBounds) @@ -190,10 +190,10 @@ class SubscriptTests: XCTestCase { func testErrorWrongType() { let json = JSON(12345) - XCTAssertEqual(json[9], JSON.nullJSON) + XCTAssertEqual(json[9], JSON.null) XCTAssertEqual(json[9].error!.code, ErrorWrongType) XCTAssertEqual(json[8][7].error!.code, ErrorWrongType) - XCTAssertEqual(json["name"], JSON.nullJSON) + XCTAssertEqual(json["name"], JSON.null) XCTAssertEqual(json["name"].error!.code, ErrorWrongType) XCTAssertEqual(json[0]["name"].error!.code, ErrorWrongType) XCTAssertEqual(json["type"]["name"].error!.code, ErrorWrongType) @@ -205,7 +205,7 @@ class SubscriptTests: XCTestCase { func testErrorNotExist() { let json:JSON = ["name":"NAME", "age":15] - XCTAssertEqual(json["Type"], JSON.nullJSON) + XCTAssertEqual(json["Type"], JSON.null) XCTAssertEqual(json["Type"].error!.code, ErrorNotExist) XCTAssertEqual(json["Type"][1].error!.code, ErrorNotExist) XCTAssertEqual(json["Type", 1].error!.code, ErrorNotExist) From 999ae8340492d6e9b42f28f332cbd591509de079 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Tue, 14 Jul 2015 14:16:43 +0800 Subject: [PATCH 133/470] Update JSON.nullJSON to JSON.null --- Example/AppDelegate.swift | 2 +- Example/ViewController.swift | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index 8086ee3f..77c528ff 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let json = JSON(data:data) viewController.json = json } else { - viewController.json = JSON.nullJSON + viewController.json = JSON.null } return true diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 09ef34a8..07754d0d 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -25,7 +25,7 @@ import SwiftyJSON class ViewController: UITableViewController { - var json: JSON = JSON.nullJSON + var json: JSON = JSON.null // MARK: - Table view data source @@ -78,8 +78,7 @@ class ViewController: UITableViewController { if let indexPath = self.tableView.indexPathForSelectedRow { let row = indexPath.row - var nextJson: JSON = JSON.nullJSON - + var nextJson: JSON = JSON.null switch self.json.type { case .Array: nextJson = self.json[row] From 141f17d2026dd4ba9b20705e231b2e2e644855f1 Mon Sep 17 00:00:00 2001 From: Xu Mingzhao Date: Tue, 14 Jul 2015 15:41:25 +0800 Subject: [PATCH 134/470] Allow construction of JSON from [String: JSON] --- Source/SwiftyJSON.swift | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5407e9aa..f0d7802e 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -94,6 +94,21 @@ public struct JSON { self.init(jsonArray.map { $0.object }) } + /** + Creates a JSON from a [String: JSON] + + :param: jsonDictionary A Swift dictionary of JSON objects + + :returns: The created JSON + */ + public init(_ jsonDictionary:[String: JSON]) { + var dictionary = [String: AnyObject]() + for (key, json) in jsonDictionary { + dictionary[key] = json.object + } + self.init(dictionary) + } + /// Private object private var _object: AnyObject = NSNull() /// Private type From 7f8b896812a3352c00a03302dda1bd3d848ef725 Mon Sep 17 00:00:00 2001 From: kai60 Date: Fri, 24 Jul 2015 16:10:50 +0800 Subject: [PATCH 135/470] example bug fix The order of elements of two array self.json.dictionaryValue.keys.array and (self.json.object as! NSDictionary).allKeysn is different , so it causes a bug in appearance i turn them into the same one --- Example/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index 6c3cb19d..3d8b1ad3 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -52,7 +52,7 @@ class ViewController: UITableViewController { cell.textLabel?.text = "\(row)" cell.detailTextLabel?.text = self.json.arrayValue.description case .Dictionary: - let key: AnyObject = (self.json.object as! NSDictionary).allKeys[row] + let key: AnyObject = self.json.dictionaryValue.keys.array[row] let value = self.json[key as! String] cell.textLabel?.text = "\(key)" cell.detailTextLabel?.text = value.description From 1cac8860c80e3b7f905f71ba748ba8d034f6937e Mon Sep 17 00:00:00 2001 From: Javier Date: Sat, 25 Jul 2015 11:36:11 +0800 Subject: [PATCH 136/470] Optimize performance of count --- Source/SwiftyJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5407e9aa..15ba3ab5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -164,9 +164,9 @@ extension JSON : Swift.SequenceType { get { switch self.type { case .Array: - return self.arrayValue.count + return (self.object as! [AnyObject]).count case .Dictionary: - return self.dictionaryValue.count + return (self.object as! [String : AnyObject]).count default: return 0 } From ebbc30d640ce93e8e3e57405c8081a80e9afb932 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Tue, 28 Jul 2015 23:59:37 +0800 Subject: [PATCH 137/470] Use reduce to get subscript json. --- Source/SwiftyJSON.swift | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index d9e7e87e..b875914c 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -314,14 +314,7 @@ extension JSON { */ public subscript(path: [SubscriptType]) -> JSON { get { - switch path.count { - case 0: return JSON.null - case 1: return self[sub: path[0]] - default: - var aPath = path; aPath.removeAtIndex(0) - let nextJSON = self[sub: path[0]] - return nextJSON[aPath] - } + return path.reduce(self) { $0[sub: $1] } } set { switch path.count { From 213e53a9ec80e6264efa4b1bc45e2d6876b09b65 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Wed, 29 Jul 2015 00:02:19 +0800 Subject: [PATCH 138/470] Add WorkingspaceSettings.xcsettings. --- .../xcshareddata/WorkspaceSettings.xcsettings | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 SwiftyJSON.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings diff --git a/SwiftyJSON.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/SwiftyJSON.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 00000000..54782e32 --- /dev/null +++ b/SwiftyJSON.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,8 @@ + + + + + IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded + + + From 11f1be4af08b8fbcc7af8834be4d8b8844b33d88 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Wed, 29 Jul 2015 00:19:48 +0800 Subject: [PATCH 139/470] Change example path for carthage. #276 --- .../Example.xcodeproj}/project.pbxproj | 101 +----------------- .../contents.xcworkspacedata | 7 ++ Example/{ => Example}/AppDelegate.swift | 0 .../{ => Example}/Base.lproj/LaunchScreen.xib | 0 .../{ => Example}/Base.lproj/Main.storyboard | 0 .../AppIcon.appiconset/Contents.json | 0 .../LaunchImage.launchimage/Contents.json | 0 .../LaunchImage.launchimage/Default@2x.png | Bin Example/{ => Example}/Info.plist | 0 Example/{ => Example}/SwiftyJSONTests.json | 0 Example/{ => Example}/ViewController.swift | 0 .../contents.xcworkspacedata | 2 +- 12 files changed, 9 insertions(+), 101 deletions(-) rename {Example.xcodeproj => Example/Example.xcodeproj}/project.pbxproj (74%) create mode 100644 Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename Example/{ => Example}/AppDelegate.swift (100%) rename Example/{ => Example}/Base.lproj/LaunchScreen.xib (100%) rename Example/{ => Example}/Base.lproj/Main.storyboard (100%) rename Example/{ => Example}/Images.xcassets/AppIcon.appiconset/Contents.json (100%) rename Example/{ => Example}/Images.xcassets/LaunchImage.launchimage/Contents.json (100%) rename Example/{ => Example}/Images.xcassets/LaunchImage.launchimage/Default@2x.png (100%) rename Example/{ => Example}/Info.plist (100%) rename Example/{ => Example}/SwiftyJSONTests.json (100%) rename Example/{ => Example}/ViewController.swift (100%) diff --git a/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj similarity index 74% rename from Example.xcodeproj/project.pbxproj rename to Example/Example.xcodeproj/project.pbxproj index 6f81456d..643cc320 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -12,49 +12,9 @@ A82A1C2619D926B8009A653D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2519D926B8009A653D /* Images.xcassets */; }; A82A1C2919D926B8009A653D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2719D926B8009A653D /* LaunchScreen.xib */; }; A82A1C4019D94AE5009A653D /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */; }; - A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; }; - A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A82A1C5619D95606009A653D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C5519D95606009A653D /* ViewController.swift */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFDB19575BE100351305; - remoteInfo = SwiftyJSON; - }; - A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFE619575BE100351305; - remoteInfo = SwiftyJSONTests; - }; - A82A1C5219D94E96009A653D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 2E4FEFDA19575BE100351305; - remoteInfo = SwiftyJSON; - }; - A88A00351B2ABAC3002E3C22 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9C7DFC5B1A9102BD005AA3F7; - remoteInfo = "SwiftyJSON OSX"; - }; - A88A00371B2ABAC3002E3C22 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9C7DFC651A9102BD005AA3F7; - remoteInfo = "SwiftyJSON OSX Tests"; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXCopyFilesBuildPhase section */ A82A1C5419D94E97009A653D /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; @@ -62,7 +22,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -77,7 +36,7 @@ A82A1C2519D926B8009A653D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; A82A1C2819D926B8009A653D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; - A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = SwiftyJSON.xcodeproj; sourceTree = ""; }; + A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftyJSON.xcodeproj; path = ../SwiftyJSON.xcodeproj; sourceTree = ""; }; A82A1C5519D95606009A653D /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -86,7 +45,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -132,17 +90,6 @@ name = "Supporting Files"; sourceTree = ""; }; - A82A1C4819D94E86009A653D /* Products */ = { - isa = PBXGroup; - children = ( - A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */, - A82A1C4F19D94E86009A653D /* SwiftyJSON iOS Tests.xctest */, - A88A00361B2ABAC3002E3C22 /* SwiftyJSON.framework */, - A88A00381B2ABAC3002E3C22 /* SwiftyJSON OSX Tests.xctest */, - ); - name = Products; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -158,7 +105,6 @@ buildRules = ( ); dependencies = ( - A82A1C5319D94E96009A653D /* PBXTargetDependency */, ); name = Example; productName = Example; @@ -191,12 +137,6 @@ mainGroup = A82A1C1019D926B8009A653D; productRefGroup = A82A1C1A19D926B8009A653D /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = A82A1C4819D94E86009A653D /* Products */; - ProjectRef = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - }, - ); projectRoot = ""; targets = ( A82A1C1819D926B8009A653D /* Example */, @@ -204,37 +144,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A82A1C4F19D94E86009A653D /* SwiftyJSON iOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON iOS Tests.xctest"; - remoteRef = A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A88A00361B2ABAC3002E3C22 /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = A88A00351B2ABAC3002E3C22 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A88A00381B2ABAC3002E3C22 /* SwiftyJSON OSX Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON OSX Tests.xctest"; - remoteRef = A88A00371B2ABAC3002E3C22 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ A82A1C1719D926B8009A653D /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -261,14 +170,6 @@ }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - A82A1C5319D94E96009A653D /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = SwiftyJSON; - targetProxy = A82A1C5219D94E96009A653D /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin PBXVariantGroup section */ A82A1C2219D926B8009A653D /* Main.storyboard */ = { isa = PBXVariantGroup; diff --git a/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift similarity index 100% rename from Example/AppDelegate.swift rename to Example/Example/AppDelegate.swift diff --git a/Example/Base.lproj/LaunchScreen.xib b/Example/Example/Base.lproj/LaunchScreen.xib similarity index 100% rename from Example/Base.lproj/LaunchScreen.xib rename to Example/Example/Base.lproj/LaunchScreen.xib diff --git a/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard similarity index 100% rename from Example/Base.lproj/Main.storyboard rename to Example/Example/Base.lproj/Main.storyboard diff --git a/Example/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from Example/Images.xcassets/AppIcon.appiconset/Contents.json rename to Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json diff --git a/Example/Images.xcassets/LaunchImage.launchimage/Contents.json b/Example/Example/Images.xcassets/LaunchImage.launchimage/Contents.json similarity index 100% rename from Example/Images.xcassets/LaunchImage.launchimage/Contents.json rename to Example/Example/Images.xcassets/LaunchImage.launchimage/Contents.json diff --git a/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png b/Example/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png similarity index 100% rename from Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png rename to Example/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png diff --git a/Example/Info.plist b/Example/Example/Info.plist similarity index 100% rename from Example/Info.plist rename to Example/Example/Info.plist diff --git a/Example/SwiftyJSONTests.json b/Example/Example/SwiftyJSONTests.json similarity index 100% rename from Example/SwiftyJSONTests.json rename to Example/Example/SwiftyJSONTests.json diff --git a/Example/ViewController.swift b/Example/Example/ViewController.swift similarity index 100% rename from Example/ViewController.swift rename to Example/Example/ViewController.swift diff --git a/SwiftyJSON.xcworkspace/contents.xcworkspacedata b/SwiftyJSON.xcworkspace/contents.xcworkspacedata index 4f20b228..1ef2d2fa 100644 --- a/SwiftyJSON.xcworkspace/contents.xcworkspacedata +++ b/SwiftyJSON.xcworkspace/contents.xcworkspacedata @@ -5,6 +5,6 @@ location = "group:SwiftyJSON.xcodeproj"> + location = "group:Example/Example.xcodeproj"> From 88c3f8ca078a0c74df8d94bb1d85df69b649e7ad Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Wed, 29 Jul 2015 00:37:12 +0800 Subject: [PATCH 140/470] Update for xcode7. #276 #272 #263 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0d60fa30..92567359 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string{ ## Requirements - iOS 7.0+ / Mac OS X 10.9+ -- Xcode 6.1 +- Xcode 7 ##Integration @@ -91,7 +91,7 @@ platform :ios, '8.0' use_frameworks! target 'MyApp' do - pod 'SwiftyJSON', '~> 2.2.0' + pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'xcode7' end ``` Note that it needs you to install CocoaPods 36 version, and requires your iOS deploy target >= 8.0: @@ -99,7 +99,7 @@ Note that it needs you to install CocoaPods 36 version, and requires your iOS de ####Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` -github "SwiftyJSON/SwiftyJSON" >= 2.2.0 +github "SwiftyJSON/SwiftyJSON" "xcode7" ``` ####Manually (iOS 7+, OS X 10.9+) From 4cf6f023d4023848914b6e35baa655d278f34ef6 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Wed, 29 Jul 2015 00:19:48 +0800 Subject: [PATCH 141/470] Change example path for carthage. #140 #177 #140 --- .../Example.xcodeproj}/project.pbxproj | 101 +----------------- .../contents.xcworkspacedata | 7 ++ Example/{ => Example}/AppDelegate.swift | 0 .../{ => Example}/Base.lproj/LaunchScreen.xib | 0 .../{ => Example}/Base.lproj/Main.storyboard | 0 .../AppIcon.appiconset/Contents.json | 0 .../LaunchImage.launchimage/Contents.json | 0 .../LaunchImage.launchimage/Default@2x.png | Bin Example/{ => Example}/Info.plist | 0 Example/{ => Example}/SwiftyJSONTests.json | 0 Example/{ => Example}/ViewController.swift | 0 .../contents.xcworkspacedata | 2 +- 12 files changed, 9 insertions(+), 101 deletions(-) rename {Example.xcodeproj => Example/Example.xcodeproj}/project.pbxproj (74%) create mode 100644 Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata rename Example/{ => Example}/AppDelegate.swift (100%) rename Example/{ => Example}/Base.lproj/LaunchScreen.xib (100%) rename Example/{ => Example}/Base.lproj/Main.storyboard (100%) rename Example/{ => Example}/Images.xcassets/AppIcon.appiconset/Contents.json (100%) rename Example/{ => Example}/Images.xcassets/LaunchImage.launchimage/Contents.json (100%) rename Example/{ => Example}/Images.xcassets/LaunchImage.launchimage/Default@2x.png (100%) rename Example/{ => Example}/Info.plist (100%) rename Example/{ => Example}/SwiftyJSONTests.json (100%) rename Example/{ => Example}/ViewController.swift (100%) diff --git a/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj similarity index 74% rename from Example.xcodeproj/project.pbxproj rename to Example/Example.xcodeproj/project.pbxproj index 7279d2bf..21381fb1 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -12,49 +12,9 @@ A82A1C2619D926B8009A653D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2519D926B8009A653D /* Images.xcassets */; }; A82A1C2919D926B8009A653D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2719D926B8009A653D /* LaunchScreen.xib */; }; A82A1C4019D94AE5009A653D /* SwiftyJSONTests.json in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */; }; - A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; }; - A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A82A1C5619D95606009A653D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C5519D95606009A653D /* ViewController.swift */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 4EC1C1C91A0C1A2D0026ED0B; - remoteInfo = SwiftyJSONOSX; - }; - 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 4EC1C1D31A0C1A2D0026ED0B; - remoteInfo = SwiftyJSONOSXTests; - }; - A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFDB19575BE100351305; - remoteInfo = SwiftyJSON; - }; - A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFE619575BE100351305; - remoteInfo = SwiftyJSONTests; - }; - A82A1C5219D94E96009A653D /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 2E4FEFDA19575BE100351305; - remoteInfo = SwiftyJSON; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXCopyFilesBuildPhase section */ A82A1C5419D94E97009A653D /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; @@ -62,7 +22,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - A82A1C5119D94E96009A653D /* SwiftyJSON.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -77,7 +36,7 @@ A82A1C2519D926B8009A653D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; A82A1C2819D926B8009A653D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; - A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; path = SwiftyJSON.xcodeproj; sourceTree = ""; }; + A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftyJSON.xcodeproj; path = ../SwiftyJSON.xcodeproj; sourceTree = ""; }; A82A1C5519D95606009A653D /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -86,7 +45,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A82A1C5019D94E96009A653D /* SwiftyJSON.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -132,17 +90,6 @@ name = "Supporting Files"; sourceTree = ""; }; - A82A1C4819D94E86009A653D /* Products */ = { - isa = PBXGroup; - children = ( - A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */, - A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */, - 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */, - 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */, - ); - name = Products; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -158,7 +105,6 @@ buildRules = ( ); dependencies = ( - A82A1C5319D94E96009A653D /* PBXTargetDependency */, ); name = Example; productName = Example; @@ -190,12 +136,6 @@ mainGroup = A82A1C1019D926B8009A653D; productRefGroup = A82A1C1A19D926B8009A653D /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = A82A1C4819D94E86009A653D /* Products */; - ProjectRef = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - }, - ); projectRoot = ""; targets = ( A82A1C1819D926B8009A653D /* Example */, @@ -203,37 +143,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 7C5E10871A2E1CBA00333E8B /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = 7C5E10861A2E1CBA00333E8B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 7C5E10891A2E1CBA00333E8B /* SwiftyJSONOSXTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = SwiftyJSONOSXTests.xctest; - remoteRef = 7C5E10881A2E1CBA00333E8B /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A82A1C4D19D94E86009A653D /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = A82A1C4C19D94E86009A653D /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A82A1C4F19D94E86009A653D /* SwiftyJSONTests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = SwiftyJSONTests.xctest; - remoteRef = A82A1C4E19D94E86009A653D /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ A82A1C1719D926B8009A653D /* Resources */ = { isa = PBXResourcesBuildPhase; @@ -260,14 +169,6 @@ }; /* End PBXSourcesBuildPhase section */ -/* Begin PBXTargetDependency section */ - A82A1C5319D94E96009A653D /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - name = SwiftyJSON; - targetProxy = A82A1C5219D94E96009A653D /* PBXContainerItemProxy */; - }; -/* End PBXTargetDependency section */ - /* Begin PBXVariantGroup section */ A82A1C2219D926B8009A653D /* Main.storyboard */ = { isa = PBXVariantGroup; diff --git a/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..919434a6 --- /dev/null +++ b/Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift similarity index 100% rename from Example/AppDelegate.swift rename to Example/Example/AppDelegate.swift diff --git a/Example/Base.lproj/LaunchScreen.xib b/Example/Example/Base.lproj/LaunchScreen.xib similarity index 100% rename from Example/Base.lproj/LaunchScreen.xib rename to Example/Example/Base.lproj/LaunchScreen.xib diff --git a/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard similarity index 100% rename from Example/Base.lproj/Main.storyboard rename to Example/Example/Base.lproj/Main.storyboard diff --git a/Example/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from Example/Images.xcassets/AppIcon.appiconset/Contents.json rename to Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json diff --git a/Example/Images.xcassets/LaunchImage.launchimage/Contents.json b/Example/Example/Images.xcassets/LaunchImage.launchimage/Contents.json similarity index 100% rename from Example/Images.xcassets/LaunchImage.launchimage/Contents.json rename to Example/Example/Images.xcassets/LaunchImage.launchimage/Contents.json diff --git a/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png b/Example/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png similarity index 100% rename from Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png rename to Example/Example/Images.xcassets/LaunchImage.launchimage/Default@2x.png diff --git a/Example/Info.plist b/Example/Example/Info.plist similarity index 100% rename from Example/Info.plist rename to Example/Example/Info.plist diff --git a/Example/SwiftyJSONTests.json b/Example/Example/SwiftyJSONTests.json similarity index 100% rename from Example/SwiftyJSONTests.json rename to Example/Example/SwiftyJSONTests.json diff --git a/Example/ViewController.swift b/Example/Example/ViewController.swift similarity index 100% rename from Example/ViewController.swift rename to Example/Example/ViewController.swift diff --git a/SwiftyJSON.xcworkspace/contents.xcworkspacedata b/SwiftyJSON.xcworkspace/contents.xcworkspacedata index 4f20b228..1ef2d2fa 100644 --- a/SwiftyJSON.xcworkspace/contents.xcworkspacedata +++ b/SwiftyJSON.xcworkspace/contents.xcworkspacedata @@ -5,6 +5,6 @@ location = "group:SwiftyJSON.xcodeproj"> + location = "group:Example/Example.xcodeproj"> From dd9551eab0d09026676a57a0e0fd762af8465f03 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Wed, 29 Jul 2015 00:56:02 +0800 Subject: [PATCH 142/470] Update for 2.2.1 --- README.md | 4 ++-- SwiftyJSON.podspec | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index df96815d..b148796b 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ platform :ios, '8.0' use_frameworks! target 'MyApp' do - pod 'SwiftyJSON', '~> 2.2.0' + pod 'SwiftyJSON', '~> 2.2.1' end ``` Note that it needs you to install CocoaPods 36 version, and requires your iOS deploy target >= 8.0: @@ -99,7 +99,7 @@ Note that it needs you to install CocoaPods 36 version, and requires your iOS de ####Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` -github "SwiftyJSON/SwiftyJSON" >= 2.2.0 +github "SwiftyJSON/SwiftyJSON" >= 2.2.1 ``` ####Manually (iOS 7+, OS X 10.9+) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 205c3f38..fbd99fe8 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.2.0" + s.version = "2.2.1" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -9,6 +9,6 @@ Pod::Spec.new do |s| s.requires_arc = true s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.2.0"} + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.2.1"} s.source_files = "Source/*.swift" end From c069c0dc207cbd1fbb057e930413121081313ebe Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Thu, 30 Jul 2015 23:19:41 +0800 Subject: [PATCH 143/470] Delete unnecessary cast. Implement SequenceType completely. --- Source/SwiftyJSON.swift | 425 +++++++++++++------------------------ Tests/SubscriptTests.swift | 4 +- 2 files changed, 149 insertions(+), 280 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index b875914c..7687cd07 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -97,19 +97,36 @@ public struct JSON { } /// Private object - private var _object: AnyObject = NSNull() + private var rawArray: [AnyObject] = [] + private var rawDictionary: [String : AnyObject] = [:] + private var rawString: String = "" + private var rawNumber: NSNumber = 0 + private var rawNull: NSNull = NSNull() /// Private type private var _type: Type = .Null /// prviate error - private var _error: NSError? + private var _error: NSError? = nil /// Object in JSON public var object: AnyObject { get { - return _object + switch self.type { + case .Array: + return self.rawArray + case .Dictionary: + return self.rawDictionary + case .String: + return self.rawString + case .Number: + return self.rawNumber + case .Bool: + return self.rawNumber + default: + return self.rawNull + } } set { - _object = newValue + _error = nil switch newValue { case let number as NSNumber: if number.isBool { @@ -117,17 +134,20 @@ public struct JSON { } else { _type = .Number } - case _ as NSString: + self.rawNumber = number + case let string as String: _type = .String + self.rawString = string case _ as NSNull: _type = .Null - case _ as [AnyObject]: + case let array as [AnyObject]: _type = .Array - case _ as [String : AnyObject]: + self.rawArray = array + case let dictionary as [String : AnyObject]: _type = .Dictionary + self.rawDictionary = dictionary default: _type = .Unknown - _object = NSNull() _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) } } @@ -148,31 +168,42 @@ public struct JSON { // MARK: - SequenceType extension JSON : Swift.SequenceType { + public typealias Generator = JSONGenerator + /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. public var isEmpty: Bool { get { switch self.type { case .Array: - return (self.object as! [AnyObject]).isEmpty + return self.rawArray.isEmpty case .Dictionary: - return (self.object as! [String : AnyObject]).isEmpty + return self.rawDictionary.isEmpty default: - return false + return true } } } /// If `type` is `.Array` or `.Dictionary`, return `array.count` or `dictonary.count` otherwise return `0`. public var count: Int { - get { - switch self.type { - case .Array: - return self.arrayValue.count - case .Dictionary: - return self.dictionaryValue.count - default: - return 0 - } + switch self.type { + case .Array: + return self.rawArray.count + case .Dictionary: + return self.rawDictionary.count + default: + return 0 + } + } + + public func underestimateCount() -> Int { + switch self.type { + case .Array: + return self.rawArray.underestimateCount() + case .Dictionary: + return self.rawDictionary.underestimateCount() + default: + return 0 } } @@ -181,33 +212,45 @@ extension JSON : Swift.SequenceType { - returns: Return a *generator* over the elements of this *sequence*. */ - public func generate() -> AnyGenerator<(String, JSON)> { + public func generate() -> JSON.Generator { + return JSON.Generator(self) + } +} + +public struct JSONGenerator : Swift.GeneratorType { + + public typealias Element = (String, JSON) + + private let type: Type + private var dictionayGenerate: DictionaryGenerator? + private var arrayGenerate: IndexingGenerator<[AnyObject]>? + private var arrayIndex: Int = 0 + + init(_ json: JSON) { + self.type = json.type + if type == .Array { + self.arrayGenerate = json.rawArray.generate() + }else { + self.dictionayGenerate = json.rawDictionary.generate() + } + } + + public mutating func next() -> JSONGenerator.Element? { switch self.type { case .Array: - let array_ = object as! [AnyObject] - var generate_ = array_.generate() - var index_: Int = 0 - return anyGenerator { - if let element_: AnyObject = generate_.next() { - return ("\(index_++)", JSON(element_)) - } else { - return nil - } + if let o = self.arrayGenerate!.next() { + return (String(self.arrayIndex++), JSON(o)) + } else { + return nil } case .Dictionary: - let dictionary_ = object as! [String : AnyObject] - var generate_ = dictionary_.generate() - return anyGenerator { - if let (key_, value_): (String, AnyObject) = generate_.next() { - return (key_, JSON(value_)) - } else { - return nil - } - } - default: - return anyGenerator { + if let (k, v): (String, AnyObject) = self.dictionayGenerate!.next() { + return (k, JSON(v)) + } else { return nil } + default: + return nil } } } @@ -217,40 +260,33 @@ extension JSON : Swift.SequenceType { /** * To mark both String and Int can be used in subscript. */ -public protocol SubscriptType {} +public protocol JSONSubscriptType {} -extension Int: SubscriptType {} +extension Int: JSONSubscriptType {} -extension String: SubscriptType {} +extension String: JSONSubscriptType {} extension JSON { /// If `type` is `.Array`, return json which's object is `array[index]`, otherwise return null json with error. private subscript(index index: Int) -> JSON { get { - if self.type != .Array { - var errorResult_ = JSON.null - errorResult_._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) - return errorResult_ - } - - let array_ = self.object as! [AnyObject] - - if index >= 0 && index < array_.count { - return JSON(array_[index]) + var r = JSON.null + r._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) + return r + } else if index >= 0 && index < self.rawArray.count { + return JSON(self.rawArray[index]) + } else { + var r = JSON.null + r._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) + return r } - - var errorResult_ = JSON.null - errorResult_._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) - return errorResult_ } set { if self.type == .Array { - var array_ = self.object as! [AnyObject] - if array_.count > index { - array_[index] = newValue.object - self.object = array_ + if self.rawArray.count > index && newValue.error == nil { + self.rawArray[index] = newValue.object } } } @@ -259,30 +295,27 @@ extension JSON { /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. private subscript(key key: String) -> JSON { get { - var returnJSON = JSON.null + var r = JSON.null if self.type == .Dictionary { - let dictionary_ = self.object as! [String : AnyObject] - if let object_: AnyObject = dictionary_[key] { - returnJSON = JSON(object_) + if let o = self.rawDictionary[key] { + r = JSON(o) } else { - returnJSON._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) + r._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) } } else { - returnJSON._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] failure, It is not an dictionary"]) + r._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] failure, It is not an dictionary"]) } - return returnJSON + return r } set { - if self.type == .Dictionary { - var dictionary_ = self.object as! [String : AnyObject] - dictionary_[key] = newValue.object - self.object = dictionary_ + if self.type == .Dictionary && newValue.error == nil { + self.rawDictionary[key] = newValue.object } } } /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. - private subscript(sub sub: SubscriptType) -> JSON { + private subscript(sub sub: JSONSubscriptType) -> JSON { get { if sub is String { return self[key:sub as! String] @@ -312,14 +345,16 @@ extension JSON { - returns: Return a json found by the path or a null json with error */ - public subscript(path: [SubscriptType]) -> JSON { + public subscript(path: [JSONSubscriptType]) -> JSON { get { return path.reduce(self) { $0[sub: $1] } } set { switch path.count { - case 0: return - case 1: self[sub:path[0]].object = newValue.object + case 0: + return + case 1: + self[sub:path[0]].object = newValue.object default: var aPath = path; aPath.removeAtIndex(0) var nextJSON = self[sub: path[0]] @@ -340,7 +375,7 @@ extension JSON { - returns: Return a json found by the path or a null json with error */ - public subscript(path: SubscriptType...) -> JSON { + public subscript(path: JSONSubscriptType...) -> JSON { get { return self[path] } @@ -391,11 +426,16 @@ extension JSON: Swift.FloatLiteralConvertible { extension JSON: Swift.DictionaryLiteralConvertible { public init(dictionaryLiteral elements: (String, AnyObject)...) { - var dictionary_ = [String : AnyObject]() - for (key_, value) in elements { - dictionary_[key_] = value - } - self.init(dictionary_) +// var dictionary = [String : AnyObject]() +// for (key_, value) in elements { +// dictionary_[key_] = value +// } +// self.init(dictionary_) + self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in + var d = dictionary + d[element.0] = element.1 + return d + }) } } @@ -443,11 +483,11 @@ extension JSON: Swift.RawRepresentable { return nil } case .String: - return (self.object as! String) + return self.rawString case .Number: - return (self.object as! NSNumber).stringValue + return self.rawNumber.stringValue case .Bool: - return (self.object as! Bool).description + return self.rawNumber.boolValue.description case .Null: return "null" default: @@ -481,7 +521,7 @@ extension JSON { public var array: [JSON]? { get { if self.type == .Array { - return (self.object as! [AnyObject]).map{ JSON($0) } + return self.rawArray.map{ JSON($0) } } else { return nil } @@ -500,14 +540,14 @@ extension JSON { get { switch self.type { case .Array: - return self.object as? [AnyObject] + return self.rawArray default: return nil } } set { - if newValue != nil { - self.object = NSMutableArray(array: newValue!, copyItems: true) + if let array = newValue { + self.object = array } else { self.object = NSNull() } @@ -519,30 +559,22 @@ extension JSON { extension JSON { - private func _map(source: [Key: Value], transform: Value -> NewValue) -> [Key: NewValue] { - var result = [Key: NewValue](minimumCapacity:source.count) - for (key,value) in source { - result[key] = transform(value) - } - return result - } - //Optional [String : JSON] public var dictionary: [String : JSON]? { - get { - if self.type == .Dictionary { - return _map(self.object as! [String : AnyObject]){ JSON($0) } - } else { - return nil + if self.type == .Dictionary { + return self.rawDictionary.reduce([String : JSON]()) { (dictionary: [String : JSON], element: (String, AnyObject)) -> [String : JSON] in + var d = dictionary + d[element.0] = JSON(element.1) + return d } + } else { + return nil } } //Non-optional [String : JSON] public var dictionaryValue: [String : JSON] { - get { - return self.dictionary ?? [:] - } + return self.dictionary ?? [:] } //Optional [String : AnyObject] @@ -550,14 +582,14 @@ extension JSON { get { switch self.type { case .Dictionary: - return self.object as? [String : AnyObject] + return self.rawDictionary default: return nil } } set { - if newValue != nil { - self.object = NSMutableDictionary(dictionary: newValue!, copyItems: true) + if let v = newValue { + self.object = v } else { self.object = NSNull() } @@ -574,7 +606,7 @@ extension JSON: Swift.BooleanType { get { switch self.type { case .Bool: - return self.object.boolValue + return self.rawNumber.boolValue default: return nil } @@ -655,13 +687,13 @@ extension JSON { get { switch self.type { case .Number, .Bool: - return self.object as? NSNumber + return self.rawNumber default: return nil } } set { - self.object = newValue?.copy() ?? NSNull() + self.object = newValue ?? NSNull() } } @@ -684,7 +716,7 @@ extension JSON { } } set { - self.object = newValue.copy() + self.object = newValue } } } @@ -696,7 +728,7 @@ extension JSON { get { switch self.type { case .Null: - return NSNull() + return self.rawNull default: return nil } @@ -715,7 +747,7 @@ extension JSON { get { switch self.type { case .String: - if let encodedString_ = self.object.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { + if let encodedString_ = self.rawString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { return NSURL(string: encodedString_) } else { return nil @@ -1169,166 +1201,3 @@ public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { return lhs.compare(rhs) != NSComparisonResult.OrderedAscending } } - -//MARK:- Unavailable - -@available(*, unavailable, renamed="JSON") -public typealias JSONValue = JSON - -extension JSON { - - @available(*, unavailable, message="use 'init(_ object:AnyObject)' instead") - public init(object: AnyObject) { - self = JSON(object) - } - - @available(*, unavailable, renamed="dictionaryObject") - public var dictionaryObjects: [String : AnyObject]? { - get { return self.dictionaryObject } - } - - @available(*, unavailable, renamed="arrayObject") - public var arrayObjects: [AnyObject]? { - get { return self.arrayObject } - } - - @available(*, unavailable, renamed="int8") - public var char: Int8? { - get { - return self.number?.charValue - } - } - - @available(*, unavailable, renamed="int8Value") - public var charValue: Int8 { - get { - return self.numberValue.charValue - } - } - - @available(*, unavailable, renamed="uInt8") - public var unsignedChar: UInt8? { - get{ - return self.number?.unsignedCharValue - } - } - - @available(*, unavailable, renamed="uInt8Value") - public var unsignedCharValue: UInt8 { - get{ - return self.numberValue.unsignedCharValue - } - } - - @available(*, unavailable, renamed="int16") - public var short: Int16? { - get{ - return self.number?.shortValue - } - } - - @available(*, unavailable, renamed="int16Value") - public var shortValue: Int16 { - get{ - return self.numberValue.shortValue - } - } - - @available(*, unavailable, renamed="uInt16") - public var unsignedShort: UInt16? { - get{ - return self.number?.unsignedShortValue - } - } - - @available(*, unavailable, renamed="uInt16Value") - public var unsignedShortValue: UInt16 { - get{ - return self.numberValue.unsignedShortValue - } - } - - @available(*, unavailable, renamed="int") - public var long: Int? { - get{ - return self.number?.longValue - } - } - - @available(*, unavailable, renamed="intValue") - public var longValue: Int { - get{ - return self.numberValue.longValue - } - } - - @available(*, unavailable, renamed="uInt") - public var unsignedLong: UInt? { - get{ - return self.number?.unsignedLongValue - } - } - - @available(*, unavailable, renamed="uIntValue") - public var unsignedLongValue: UInt { - get{ - return self.numberValue.unsignedLongValue - } - } - - @available(*, unavailable, renamed="int64") - public var longLong: Int64? { - get{ - return self.number?.longLongValue - } - } - - @available(*, unavailable, renamed="int64Value") - public var longLongValue: Int64 { - get{ - return self.numberValue.longLongValue - } - } - - @available(*, unavailable, renamed="uInt64") - public var unsignedLongLong: UInt64? { - get{ - return self.number?.unsignedLongLongValue - } - } - - @available(*, unavailable, renamed="uInt64Value") - public var unsignedLongLongValue: UInt64 { - get{ - return self.numberValue.unsignedLongLongValue - } - } - - @available(*, unavailable, renamed="int") - public var integer: Int? { - get { - return self.number?.integerValue - } - } - - @available(*, unavailable, renamed="intValue") - public var integerValue: Int { - get { - return self.numberValue.integerValue - } - } - - @available(*, unavailable, renamed="uInt") - public var unsignedInteger: Int? { - get { - return self.number?.unsignedIntegerValue - } - } - - @available(*, unavailable, renamed="uIntValue") - public var unsignedIntegerValue: Int { - get { - return self.numberValue.unsignedIntegerValue - } - } -} diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index 9d86e81a..c5803664 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -103,7 +103,7 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[1]["b"], JSON("B")) XCTAssertNotNil(json[2]["null"].null) XCTAssertNotNil(json[2,"null"].null) - let keys:[SubscriptType] = [1, "a"] + let keys:[JSONSubscriptType] = [1, "a"] XCTAssertEqual(json[keys], JSON(rawValue: "A")!) } @@ -234,7 +234,7 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[[0,0,0,0,"name"]].stringValue, "Jack") json[[0,0,0,0,"name"]].string = "Mike" XCTAssertEqual(json[0,0,0,0,"name"].stringValue, "Mike") - let path:[SubscriptType] = [0,0,0,0,"name"] + let path:[JSONSubscriptType] = [0,0,0,0,"name"] json[path].string = "Jim" XCTAssertEqual(json[path].stringValue, "Jim") } From d1b287c5d788e862479b606425c529a75a0be7d3 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Fri, 31 Jul 2015 11:06:43 +0800 Subject: [PATCH 144/470] Implement CollectionType. --- Source/SwiftyJSON.swift | 143 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 133 insertions(+), 10 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 7687cd07..5ae66b0d 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -165,11 +165,47 @@ public struct JSON { public static var null: JSON { get { return JSON(NSNull()) } } } -// MARK: - SequenceType -extension JSON : Swift.SequenceType { - +// MARK: - CollectionType, SequenceType, Indexable +extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { + public typealias Generator = JSONGenerator + public typealias Index = JSONIndex + + public var startIndex: JSON.Index { + switch self.type { + case .Array: + return JSONIndex(arrayIndex: self.rawArray.startIndex) + case .Dictionary: + return JSONIndex(dictionaryIndex: self.rawDictionary.startIndex) + default: + return JSONIndex() + } + } + + public var endIndex: JSON.Index { + switch self.type { + case .Array: + return JSONIndex(arrayIndex: self.rawArray.endIndex) + case .Dictionary: + return JSONIndex(dictionaryIndex: self.rawDictionary.endIndex) + default: + return JSONIndex() + } + } + + public subscript (position: JSON.Index) -> JSON.Generator.Element { + switch self.type { + case .Array: + return (String(position.arrayIndex), JSON(self.rawArray[position.arrayIndex!])) + case .Dictionary: + let (key, value) = self.rawDictionary[position.dictionaryIndex!] + return (key, JSON(value)) + default: + return ("", JSON.null) + } + } + /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. public var isEmpty: Bool { get { @@ -210,14 +246,106 @@ extension JSON : Swift.SequenceType { /** If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary`, otherwise return a generator over empty. - - returns: Return a *generator* over the elements of this *sequence*. + - returns: Return a *generator* over the elements of JSON. */ public func generate() -> JSON.Generator { return JSON.Generator(self) } } -public struct JSONGenerator : Swift.GeneratorType { +public struct JSONIndex: ForwardIndexType, _Incrementable, Equatable, Comparable { + + let arrayIndex: Int? + let dictionaryIndex: DictionaryIndex? + + let type: Type + + init(){ + self.arrayIndex = nil + self.dictionaryIndex = nil + self.type = .Unknown + } + + init(arrayIndex: Int) { + self.arrayIndex = arrayIndex + self.dictionaryIndex = nil + self.type = .Array + } + + init(dictionaryIndex: DictionaryIndex) { + self.arrayIndex = nil + self.dictionaryIndex = dictionaryIndex + self.type = .Dictionary + } + + public func successor() -> JSONIndex { + switch self.type { + case .Array: + return JSONIndex(arrayIndex: self.arrayIndex!.successor()) + case .Dictionary: + return JSONIndex(dictionaryIndex: self.dictionaryIndex!.successor()) + default: + return JSONIndex() + } + } +} + +public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { + switch (lhs.type, rhs.type) { + case (.Array, .Array): + return lhs.arrayIndex == rhs.arrayIndex + case (.Dictionary, .Dictionary): + return lhs.dictionaryIndex == rhs.dictionaryIndex + default: + return false + } +} + +public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool { + switch (lhs.type, rhs.type) { + case (.Array, .Array): + return lhs.arrayIndex < rhs.arrayIndex + case (.Dictionary, .Dictionary): + return lhs.dictionaryIndex < rhs.dictionaryIndex + default: + return false + } +} + +public func <=(lhs: JSONIndex, rhs: JSONIndex) -> Bool { + switch (lhs.type, rhs.type) { + case (.Array, .Array): + return lhs.arrayIndex <= rhs.arrayIndex + case (.Dictionary, .Dictionary): + return lhs.dictionaryIndex <= rhs.dictionaryIndex + default: + return false + } +} + +public func >=(lhs: JSONIndex, rhs: JSONIndex) -> Bool { + switch (lhs.type, rhs.type) { + case (.Array, .Array): + return lhs.arrayIndex >= rhs.arrayIndex + case (.Dictionary, .Dictionary): + return lhs.dictionaryIndex >= rhs.dictionaryIndex + default: + return false + } +} + +public func >(lhs: JSONIndex, rhs: JSONIndex) -> Bool { + switch (lhs.type, rhs.type) { + case (.Array, .Array): + return lhs.arrayIndex > rhs.arrayIndex + case (.Dictionary, .Dictionary): + return lhs.dictionaryIndex > rhs.dictionaryIndex + default: + return false + } +} + +public struct JSONGenerator : GeneratorType { public typealias Element = (String, JSON) @@ -426,11 +554,6 @@ extension JSON: Swift.FloatLiteralConvertible { extension JSON: Swift.DictionaryLiteralConvertible { public init(dictionaryLiteral elements: (String, AnyObject)...) { -// var dictionary = [String : AnyObject]() -// for (key_, value) in elements { -// dictionary_[key_] = value -// } -// self.init(dictionary_) self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in var d = dictionary d[element.0] = element.1 From 45ca854ce75948858f65e31fbc58cbf214669250 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Sat, 1 Aug 2015 21:55:59 +0800 Subject: [PATCH 145/470] Remove cast code in JSON compare. --- Source/SwiftyJSON.swift | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index af12303f..fcb5cebc 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1176,15 +1176,15 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as! NSNumber) == (rhs.object as! NSNumber) + return lhs.rawNumber == rhs.rawNumber case (.String, .String): - return (lhs.object as! String) == (rhs.object as! String) + return lhs.rawString == rhs.rawString case (.Bool, .Bool): - return (lhs.object as! Bool) == (rhs.object as! Bool) + return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue case (.Array, .Array): - return (lhs.object as! NSArray) == (rhs.object as! NSArray) + return lhs.rawArray as NSArray == rhs.rawArray as NSArray case (.Dictionary, .Dictionary): - return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) + return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary case (.Null, .Null): return true default: @@ -1196,15 +1196,15 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as! NSNumber) <= (rhs.object as! NSNumber) + return lhs.rawNumber <= rhs.rawNumber case (.String, .String): - return (lhs.object as! String) <= (rhs.object as! String) + return lhs.rawString <= rhs.rawString case (.Bool, .Bool): - return (lhs.object as! Bool) == (rhs.object as! Bool) + return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue case (.Array, .Array): - return (lhs.object as! NSArray) == (rhs.object as! NSArray) + return lhs.rawArray as NSArray == rhs.rawArray as NSArray case (.Dictionary, .Dictionary): - return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) + return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary case (.Null, .Null): return true default: @@ -1216,15 +1216,15 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as! NSNumber) >= (rhs.object as! NSNumber) + return lhs.rawNumber >= rhs.rawNumber case (.String, .String): - return (lhs.object as! String) >= (rhs.object as! String) + return lhs.rawString >= rhs.rawString case (.Bool, .Bool): - return (lhs.object as! Bool) == (rhs.object as! Bool) + return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue case (.Array, .Array): - return (lhs.object as! NSArray) == (rhs.object as! NSArray) + return lhs.rawArray as NSArray == rhs.rawArray as NSArray case (.Dictionary, .Dictionary): - return (lhs.object as! NSDictionary) == (rhs.object as! NSDictionary) + return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary case (.Null, .Null): return true default: @@ -1236,9 +1236,9 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as! NSNumber) > (rhs.object as! NSNumber) + return lhs.rawNumber > rhs.rawNumber case (.String, .String): - return (lhs.object as! String) > (rhs.object as! String) + return lhs.rawString > rhs.rawString default: return false } @@ -1248,9 +1248,9 @@ public func <(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.Number, .Number): - return (lhs.object as! NSNumber) < (rhs.object as! NSNumber) + return lhs.rawNumber < rhs.rawNumber case (.String, .String): - return (lhs.object as! String) < (rhs.object as! String) + return lhs.rawString < rhs.rawString default: return false } From a208ce8237d996cf7e3922a828ea8d76ac5752a5 Mon Sep 17 00:00:00 2001 From: Brian Kracoff Date: Thu, 6 Aug 2015 10:16:01 -0400 Subject: [PATCH 146/470] Check if error pointer exists before setting memory --- Source/SwiftyJSON.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fcb5cebc..8f5de441 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -69,7 +69,9 @@ public struct JSON { let object: AnyObject = try NSJSONSerialization.JSONObjectWithData(data, options: opt) self.init(object) } catch let aError as NSError { - error.memory = aError + if error != nil { + error.memory = aError + } self.init(NSNull()) } } From 70ddb5419b5b05511ac9db41b128e50e37313206 Mon Sep 17 00:00:00 2001 From: condaatje Date: Sat, 8 Aug 2015 16:47:28 -0400 Subject: [PATCH 147/470] Update Deprecated Function stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) is deprecated as of Xcode 7 beta (build 5). This is Apple's recommended replacement. --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fcb5cebc..8c6ccd19 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -885,7 +885,7 @@ extension JSON { get { switch self.type { case .String: - if let encodedString_ = self.rawString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { + if let encodedString_ = self.rawString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.alphanumericCharacterSet()) { return NSURL(string: encodedString_) } else { return nil From 1aa183ed3dae717f78312163aef501130b2850c1 Mon Sep 17 00:00:00 2001 From: condaatje Date: Sat, 8 Aug 2015 17:04:34 -0400 Subject: [PATCH 148/470] URL charset, not alphanumeric --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 8c6ccd19..08df8008 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -885,7 +885,7 @@ extension JSON { get { switch self.type { case .String: - if let encodedString_ = self.rawString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.alphanumericCharacterSet()) { + if let encodedString_ = self.rawString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) { return NSURL(string: encodedString_) } else { return nil From dbd02fd60d48c36714bbc83dc7ad3a8c05557fe7 Mon Sep 17 00:00:00 2001 From: Andreas Grauel Date: Mon, 10 Aug 2015 07:40:10 +0200 Subject: [PATCH 149/470] fixes compiler warning fixes compiler warning for Xcode7b5 --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fcb5cebc..08df8008 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -885,7 +885,7 @@ extension JSON { get { switch self.type { case .String: - if let encodedString_ = self.rawString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) { + if let encodedString_ = self.rawString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) { return NSURL(string: encodedString_) } else { return nil From 770667461d7b8f763f0941a0c6eee567f59a3297 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Tue, 11 Aug 2015 19:59:08 +0100 Subject: [PATCH 150/470] Fix bad memory access with optional error pointer The NSErrorPointer is optional, but the memory it would point to was always used in the case of an NSJSONSerialization parsing error. --- Source/SwiftyJSON.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fcb5cebc..8f5de441 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -69,7 +69,9 @@ public struct JSON { let object: AnyObject = try NSJSONSerialization.JSONObjectWithData(data, options: opt) self.init(object) } catch let aError as NSError { - error.memory = aError + if error != nil { + error.memory = aError + } self.init(NSNull()) } } From 14e486ea2ff4a91b5135d3f492f9cf97bd4d4ead Mon Sep 17 00:00:00 2001 From: Tobias Due Munk Date: Thu, 13 Aug 2015 13:38:30 +0200 Subject: [PATCH 151/470] Fix syntax style error --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b148796b..5f585727 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ With SwiftyJSON all you have to do is: ```swift let json = JSON(data: dataFromNetworking) -if let userName = json[0]["user"]["name"].string{ +if let userName = json[0]["user"]["name"].string { //Now you got your value } @@ -68,7 +68,7 @@ And don't worry about the Optional Wrapping thing. It's done for you automatical ```swift let json = JSON(data: dataFromNetworking) -if let userName = json[999999]["wrong_key"]["wrong_name"].string{ +if let userName = json[999999]["wrong_key"]["wrong_name"].string { //Calm down, take it easy, the ".string" property still produces the correct Optional String type with safety } else { //Print the error From 1609d5a7fc5ee84bd69cf253b19f0a15c264042d Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Fri, 7 Aug 2015 23:19:18 +0800 Subject: [PATCH 152/470] Re-Indent --- Source/SwiftyJSON.swift | 156 ++++++++++++++++++++-------------------- 1 file changed, 78 insertions(+), 78 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 8f5de441..f9028768 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -54,7 +54,7 @@ public enum Type :Int{ // MARK: - JSON Base public struct JSON { - + /** Creates a JSON using the data. @@ -86,7 +86,7 @@ public struct JSON { public init(_ object: AnyObject) { self.object = object } - + /** Creates a JSON from a [JSON] @@ -97,7 +97,7 @@ public struct JSON { public init(_ jsonArray:[JSON]) { self.init(jsonArray.map { $0.object }) } - + /** Creates a JSON from a [String: JSON] @@ -112,7 +112,7 @@ public struct JSON { } self.init(dictionary) } - + /// Private object private var rawArray: [AnyObject] = [] private var rawDictionary: [String : AnyObject] = [:] @@ -123,7 +123,7 @@ public struct JSON { private var _type: Type = .Null /// prviate error private var _error: NSError? = nil - + /// Object in JSON public var object: AnyObject { get { @@ -172,7 +172,7 @@ public struct JSON { /// json type public var type: Type { get { return _type } } - + /// Error in JSON public var error: NSError? { get { return self._error } } @@ -184,7 +184,7 @@ public struct JSON { // MARK: - CollectionType, SequenceType, Indexable extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { - + public typealias Generator = JSONGenerator public typealias Index = JSONIndex @@ -199,7 +199,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { return JSONIndex() } } - + public var endIndex: JSON.Index { switch self.type { case .Array: @@ -271,7 +271,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { } public struct JSONIndex: ForwardIndexType, _Incrementable, Equatable, Comparable { - + let arrayIndex: Int? let dictionaryIndex: DictionaryIndex? @@ -436,7 +436,7 @@ extension JSON { } } } - + /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. private subscript(key key: String) -> JSON { get { @@ -480,13 +480,13 @@ extension JSON { /** Find a json in the complex data structuresby using the Int/String's array. - - parameter path: The target json's path. Example: - - let json = JSON[data] - let path = [9,"list","person","name"] - let name = json[path] + - parameter path: The target json's path. Example: + + let json = JSON[data] + let path = [9,"list","person","name"] + let name = json[path] - The same as: let name = json[9]["list"]["person"]["name"] + The same as: let name = json[9]["list"]["person"]["name"] - returns: Return a json found by the path or a null json with error */ @@ -514,9 +514,9 @@ extension JSON { - parameter path: The target json's path. Example: - let name = json[9,"list","person","name"] + let name = json[9,"list","person","name"] - The same as: let name = json[9]["list"]["person"]["name"] + The same as: let name = json[9]["list"]["person"]["name"] - returns: Return a json found by the path or a null json with error */ @@ -533,82 +533,82 @@ extension JSON { // MARK: - LiteralConvertible extension JSON: Swift.StringLiteralConvertible { - - public init(stringLiteral value: StringLiteralType) { - self.init(value) - } - - public init(extendedGraphemeClusterLiteral value: StringLiteralType) { - self.init(value) - } - - public init(unicodeScalarLiteral value: StringLiteralType) { - self.init(value) - } + + public init(stringLiteral value: StringLiteralType) { + self.init(value) + } + + public init(extendedGraphemeClusterLiteral value: StringLiteralType) { + self.init(value) + } + + public init(unicodeScalarLiteral value: StringLiteralType) { + self.init(value) + } } extension JSON: Swift.IntegerLiteralConvertible { - - public init(integerLiteral value: IntegerLiteralType) { - self.init(value) - } + + public init(integerLiteral value: IntegerLiteralType) { + self.init(value) + } } extension JSON: Swift.BooleanLiteralConvertible { - - public init(booleanLiteral value: BooleanLiteralType) { - self.init(value) - } + + public init(booleanLiteral value: BooleanLiteralType) { + self.init(value) + } } extension JSON: Swift.FloatLiteralConvertible { - - public init(floatLiteral value: FloatLiteralType) { - self.init(value) - } + + public init(floatLiteral value: FloatLiteralType) { + self.init(value) + } } extension JSON: Swift.DictionaryLiteralConvertible { - - public init(dictionaryLiteral elements: (String, AnyObject)...) { + + public init(dictionaryLiteral elements: (String, AnyObject)...) { self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in var d = dictionary d[element.0] = element.1 return d - }) - } + }) + } } extension JSON: Swift.ArrayLiteralConvertible { - - public init(arrayLiteral elements: AnyObject...) { - self.init(elements) - } + + public init(arrayLiteral elements: AnyObject...) { + self.init(elements) + } } extension JSON: Swift.NilLiteralConvertible { - - public init(nilLiteral: ()) { - self.init(NSNull()) - } + + public init(nilLiteral: ()) { + self.init(NSNull()) + } } // MARK: - Raw extension JSON: Swift.RawRepresentable { - - public init?(rawValue: AnyObject) { - if JSON(rawValue).type == .Unknown { - return nil - } else { - self.init(rawValue) - } - } - - public var rawValue: AnyObject { - return self.object - } - + + public init?(rawValue: AnyObject) { + if JSON(rawValue).type == .Unknown { + return nil + } else { + self.init(rawValue) + } + } + + public var rawValue: AnyObject { + return self.object + } + public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(rawValue: 0)) throws -> NSData { return try NSJSONSerialization.dataWithJSONObject(self.object, options: opt) } @@ -656,7 +656,7 @@ extension JSON: Swift.Printable, Swift.DebugPrintable { // MARK: - Array extension JSON { - + //Optional [JSON] public var array: [JSON]? { get { @@ -714,7 +714,7 @@ extension JSON { //Non-optional [String : JSON] public var dictionaryValue: [String : JSON] { - return self.dictionary ?? [:] + return self.dictionary ?? [:] } //Optional [String : AnyObject] @@ -759,7 +759,7 @@ extension JSON: Swift.BooleanType { } } } - + //Non-optional bool public var boolValue: Bool { get { @@ -779,7 +779,7 @@ extension JSON: Swift.BooleanType { // MARK: - String extension JSON { - + //Optional string public var string: String? { get { @@ -863,7 +863,7 @@ extension JSON { //MARK: - Null extension JSON { - + public var null: NSNull? { get { switch self.type { @@ -993,7 +993,7 @@ extension JSON { self.object = NSNumber(unsignedLong: newValue) } } - + public var int8: Int8? { get { return self.number?.charValue @@ -1081,7 +1081,7 @@ extension JSON { self.object = NSNumber(unsignedShort: newValue) } } - + public var int32: Int32? { get { return self.number?.intValue @@ -1172,7 +1172,7 @@ extension JSON { } //MARK: - Comparable -extension JSON: Swift.Comparable {} +extension JSON : Swift.Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { @@ -1271,7 +1271,7 @@ extension NSNumber: Swift.Comparable { let objCType = String.fromCString(self.objCType) if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ - return true + return true } else { return false } @@ -1319,7 +1319,7 @@ public func >(lhs: NSNumber, rhs: NSNumber) -> Bool { } public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1331,7 +1331,7 @@ public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { } public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false From f269523ac572979245baa99c8475eab73caf1e9b Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Fri, 21 Aug 2015 16:53:51 +0800 Subject: [PATCH 153/470] Fix xcode beta5 warning. --- Example/Example.xcodeproj/project.pbxproj | 79 +++++++++++++++++++++++ SwiftyJSON.xcodeproj/project.pbxproj | 8 --- Tests/DictionaryTests.swift | 2 +- Tests/NumberTests.swift | 6 +- Tests/RawRepresentableTests.swift | 26 ++++---- Tests/SequenceTypeTests.swift | 24 +++---- Tests/StringTests.swift | 2 +- 7 files changed, 109 insertions(+), 38 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 643cc320..1095dcdb 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -15,6 +15,37 @@ A82A1C5619D95606009A653D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C5519D95606009A653D /* ViewController.swift */; }; /* End PBXBuildFile section */ +/* Begin PBXContainerItemProxy section */ + A8BF45AA1B871E100066C032 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 2E4FEFDB19575BE100351305; + remoteInfo = "SwiftyJSON iOS"; + }; + A8BF45AC1B871E100066C032 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 2E4FEFE619575BE100351305; + remoteInfo = "SwiftyJSON iOS Tests"; + }; + A8BF45AE1B871E100066C032 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 9C7DFC5B1A9102BD005AA3F7; + remoteInfo = "SwiftyJSON OSX"; + }; + A8BF45B01B871E100066C032 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 9C7DFC651A9102BD005AA3F7; + remoteInfo = "SwiftyJSON OSX Tests"; + }; +/* End PBXContainerItemProxy section */ + /* Begin PBXCopyFilesBuildPhase section */ A82A1C5419D94E97009A653D /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; @@ -90,6 +121,17 @@ name = "Supporting Files"; sourceTree = ""; }; + A8BF45A41B871E0F0066C032 /* Products */ = { + isa = PBXGroup; + children = ( + A8BF45AB1B871E100066C032 /* SwiftyJSON.framework */, + A8BF45AD1B871E100066C032 /* SwiftyJSON iOS Tests.xctest */, + A8BF45AF1B871E100066C032 /* SwiftyJSON.framework */, + A8BF45B11B871E100066C032 /* SwiftyJSON OSX Tests.xctest */, + ); + name = Products; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -137,6 +179,12 @@ mainGroup = A82A1C1019D926B8009A653D; productRefGroup = A82A1C1A19D926B8009A653D /* Products */; projectDirPath = ""; + projectReferences = ( + { + ProductGroup = A8BF45A41B871E0F0066C032 /* Products */; + ProjectRef = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + }, + ); projectRoot = ""; targets = ( A82A1C1819D926B8009A653D /* Example */, @@ -144,6 +192,37 @@ }; /* End PBXProject section */ +/* Begin PBXReferenceProxy section */ + A8BF45AB1B871E100066C032 /* SwiftyJSON.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftyJSON.framework; + remoteRef = A8BF45AA1B871E100066C032 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + A8BF45AD1B871E100066C032 /* SwiftyJSON iOS Tests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "SwiftyJSON iOS Tests.xctest"; + remoteRef = A8BF45AC1B871E100066C032 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + A8BF45AF1B871E100066C032 /* SwiftyJSON.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftyJSON.framework; + remoteRef = A8BF45AE1B871E100066C032 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + A8BF45B11B871E100066C032 /* SwiftyJSON OSX Tests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "SwiftyJSON OSX Tests.xctest"; + remoteRef = A8BF45B01B871E100066C032 /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; +/* End PBXReferenceProxy section */ + /* Begin PBXResourcesBuildPhase section */ A82A1C1719D926B8009A653D /* Resources */ = { isa = PBXResourcesBuildPhase; diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 20c72f44..c52fbc53 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -562,10 +562,6 @@ 2E4FEFF519575BE100351305 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -581,10 +577,6 @@ 2E4FEFF619575BE100351305 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); INFOPLIST_FILE = "Tests/Info-iOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index b384bfae..84d110d3 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -41,7 +41,7 @@ class DictionaryTests: XCTestCase { XCTAssertTrue(json.dictionaryValue["null"] == nil) XCTAssertTrue(JSON.null.dictionaryValue == [:]) //dictionaryObject - XCTAssertEqual(json.dictionaryObject!["number"]! as! Double, 9823.212) + XCTAssertEqual(json.dictionaryObject!["number"]! as? Double, 9823.212) XCTAssertTrue(json.dictionaryObject!["null"] == nil) XCTAssertTrue(JSON.null.dictionaryObject == nil) } diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index fb82f350..d0257ef3 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -37,7 +37,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 123456789.0987654321) json.number = nil XCTAssertEqual(json.numberValue, 0) - XCTAssertEqual(json.object as! NSNull, NSNull()) + XCTAssertEqual(json.object as? NSNull, NSNull()) XCTAssertTrue(json.number == nil) json.numberValue = 2.9876 XCTAssertEqual(json.number!, 2.9876) @@ -119,7 +119,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.boolValue == false) XCTAssertTrue(json.intValue == 0) XCTAssertEqual(json.numberValue, 0) - XCTAssertEqual(json.object as! NSNull, NSNull()) + XCTAssertEqual(json.object as? NSNull, NSNull()) XCTAssertTrue(json.int == nil) json.intValue = 76543 @@ -144,7 +144,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.boolValue == false) XCTAssertTrue(json.uIntValue == 0) XCTAssertEqual(json.numberValue, 0) - XCTAssertEqual(json.object as! NSNull, NSNull()) + XCTAssertEqual(json.object as? NSNull, NSNull()) XCTAssertTrue(json.uInt == nil) json.uIntValue = 76543 diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index 59397f50..149246db 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -35,10 +35,10 @@ class RawRepresentableTests: XCTestCase { XCTAssertTrue(json.floatValue == 948394394.347384) let object: AnyObject = json.rawValue - XCTAssertEqual(object as! Int, 948394394) - XCTAssertEqual(object as! Double, 948394394.347384) + XCTAssertEqual(object as? Int, 948394394) + XCTAssertEqual(object as? Double, 948394394.347384) XCTAssertTrue(object as! Float == 948394394.347384) - XCTAssertEqual(object as! NSNumber, 948394394.347384) + XCTAssertEqual(object as? NSNumber, 948394394.347384) } func testBool() { @@ -51,16 +51,16 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(jsonFalse.boolValue, false) let objectTrue: AnyObject = jsonTrue.rawValue - XCTAssertEqual(objectTrue as! Int, 1) - XCTAssertEqual(objectTrue as! Double, 1.0) - XCTAssertEqual(objectTrue as! Bool, true) - XCTAssertEqual(objectTrue as! NSNumber, NSNumber(bool: true)) + XCTAssertEqual(objectTrue as? Int, 1) + XCTAssertEqual(objectTrue as? Double, 1.0) + XCTAssertEqual(objectTrue as? Bool, true) + XCTAssertEqual(objectTrue as? NSNumber, NSNumber(bool: true)) let objectFalse: AnyObject = jsonFalse.rawValue - XCTAssertEqual(objectFalse as! Int, 0) - XCTAssertEqual(objectFalse as! Double, 0.0) - XCTAssertEqual(objectFalse as! Bool, false) - XCTAssertEqual(objectFalse as! NSNumber, NSNumber(bool: false)) + XCTAssertEqual(objectFalse as? Int, 0) + XCTAssertEqual(objectFalse as? Double, 0.0) + XCTAssertEqual(objectFalse as? Bool, false) + XCTAssertEqual(objectFalse as? NSNumber, NSNumber(bool: false)) } func testString() { @@ -73,13 +73,13 @@ class RawRepresentableTests: XCTestCase { XCTAssertTrue(json.null == nil) XCTAssertTrue(json.error == nil) XCTAssertTrue(json.type == .String) - XCTAssertEqual(json.object as! String, string) + XCTAssertEqual(json.object as? String, string) } else { XCTFail("Should not run into here") } let object: AnyObject = JSON(rawValue: string)!.rawValue - XCTAssertEqual(object as! String, string) + XCTAssertEqual(object as? String, string) } func testNil() { diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index 526281d9..6711a221 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -107,8 +107,8 @@ class SequenceTypeTests: XCTestCase { index++ } XCTAssertEqual(index, 4) - XCTAssertEqual(array[0] as! String, "aoo") - XCTAssertEqual(array[2] as! NSNull, NSNull()) + XCTAssertEqual(array[0] as? String, "aoo") + XCTAssertEqual(array[2] as? NSNull, NSNull()) } func testArrayAllDictionary() { @@ -195,9 +195,9 @@ class SequenceTypeTests: XCTestCase { } XCTAssertEqual(index, 4) - XCTAssertEqual(dictionary["a"]! as! String, "aoo") - XCTAssertEqual(dictionary["bb"]! as! String, "bpp") - XCTAssertEqual(dictionary["null"]! as! NSNull, NSNull()) + XCTAssertEqual(dictionary["a"]! as? String, "aoo") + XCTAssertEqual(dictionary["bb"]! as? String, "bpp") + XCTAssertEqual(dictionary["null"]! as? NSNull, NSNull()) } func testDictionaryAllArray() { @@ -214,12 +214,12 @@ class SequenceTypeTests: XCTestCase { } XCTAssertEqual(index, 3) - XCTAssertEqual((dictionary["Number"] as! NSArray)[0] as! Int, 1) - XCTAssertEqual((dictionary["Number"] as! NSArray)[1] as! Double, 2.123456) - XCTAssertEqual((dictionary["String"] as! NSArray)[0] as! String, "aa") - XCTAssertEqual((dictionary["Mix"] as! NSArray)[0] as! Bool, true) - XCTAssertEqual((dictionary["Mix"] as! NSArray)[1] as! String, "766") - XCTAssertEqual((dictionary["Mix"] as! NSArray)[2] as! NSNull, NSNull()) - XCTAssertEqual((dictionary["Mix"] as! NSArray)[3] as! Double, 655231.9823) + XCTAssertEqual((dictionary["Number"] as! NSArray)[0] as? Int, 1) + XCTAssertEqual((dictionary["Number"] as! NSArray)[1] as? Double, 2.123456) + XCTAssertEqual((dictionary["String"] as! NSArray)[0] as? String, "aa") + XCTAssertEqual((dictionary["Mix"] as! NSArray)[0] as? Bool, true) + XCTAssertEqual((dictionary["Mix"] as! NSArray)[1] as? String, "766") + XCTAssertEqual((dictionary["Mix"] as! NSArray)[2] as? NSNull, NSNull()) + XCTAssertEqual((dictionary["Mix"] as! NSArray)[3] as? Double, 655231.9823) } } diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index c47357b1..229349a9 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -44,7 +44,7 @@ class StringTests: XCTestCase { func testURLPercentEscapes() { let emDash = "\\u2014" let urlString = "http://examble.com/unencoded" + emDash + "string" - let encodedURLString = urlString.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding) + let encodedURLString = urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) let json = JSON(urlString) XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!)!, "Wrong unpacked ") } From 12397b44a3483659df3ed5c7a8e2633809ce8936 Mon Sep 17 00:00:00 2001 From: bassrock Date: Fri, 21 Aug 2015 20:08:47 -0700 Subject: [PATCH 154/470] Adding watchOS --- SwiftyJSON.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index fbd99fe8..f31e2d3c 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -9,6 +9,7 @@ Pod::Spec.new do |s| s.requires_arc = true s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" + s.watchos.deployment_target = "2.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.2.1"} s.source_files = "Source/*.swift" end From 69cf31343909e6001012884848c4904462801a24 Mon Sep 17 00:00:00 2001 From: Saagar Jha Date: Mon, 24 Aug 2015 22:12:53 -0700 Subject: [PATCH 155/470] Fixed some minor grammar errors in the README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5f585727..d018e322 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ target 'MyApp' do pod 'SwiftyJSON', '~> 2.2.1' end ``` -Note that it needs you to install CocoaPods 36 version, and requires your iOS deploy target >= 8.0: +Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 8.0: ####Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: @@ -172,12 +172,12 @@ for (index: String, subJson: JSON) in json { ####Error Use a subscript to get/set a value in an Array or Dictionary -If the json is: +If the JSON is: * an array, the app may crash with "index out-of-bounds." -* a dictionary, it will get `nil` without a reason. +* a dictionary, it will be assigned `nil` without a reason. * not an array or a dictionary, the app may crash with an "unrecognised selector" exception. -It will never happen in SwiftyJSON. +This will never happen in SwiftyJSON. ```swift let json = JSON(["name", "age"]) From b1efa67f190bdd25f82372dac2f37a717525029e Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Mon, 31 Aug 2015 12:40:05 +0200 Subject: [PATCH 156/470] watchOS target added. --- Info-watchOS.plist | 26 +++++ SwiftyJSON.xcodeproj/project.pbxproj | 104 ++++++++++++++++++ .../xcschemes/SwiftyJSON watchOS.xcscheme | 80 ++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 Info-watchOS.plist create mode 100644 SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme diff --git a/Info-watchOS.plist b/Info-watchOS.plist new file mode 100644 index 00000000..78122054 --- /dev/null +++ b/Info-watchOS.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index c52fbc53..7b6b79f8 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -41,6 +41,8 @@ A885D1DC19CFCFF0002FD4C3 /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; + E4D7CCE01B9465A700EE7221 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + E4D7CCE31B9465A700EE7221 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -85,6 +87,8 @@ A885D1DA19CFCFF0002FD4C3 /* Tests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Tests.json; sourceTree = ""; }; A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryTests.swift; sourceTree = ""; }; A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTests.swift; sourceTree = ""; }; + E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-watchOS.plist"; path = "/Users/tobiasottenweller/Code/SwiftyJSON/Info-watchOS.plist"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -118,6 +122,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E4D7CCE11B9465A700EE7221 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ @@ -137,6 +148,7 @@ 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */, 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */, 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */, + E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */, ); name = Products; sourceTree = ""; @@ -156,6 +168,7 @@ children = ( 2E4FEFDF19575BE100351305 /* Info-iOS.plist */, 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */, + E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -210,6 +223,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E4D7CCE21B9465A700EE7221 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + E4D7CCE31B9465A700EE7221 /* SwiftyJSON.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -285,6 +306,24 @@ productReference = 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + E4D7CCDE1B9465A700EE7221 /* SwiftyJSON watchOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = E4D7CCE51B9465A700EE7221 /* Build configuration list for PBXNativeTarget "SwiftyJSON watchOS" */; + buildPhases = ( + E4D7CCDF1B9465A700EE7221 /* Sources */, + E4D7CCE11B9465A700EE7221 /* Frameworks */, + E4D7CCE21B9465A700EE7221 /* Headers */, + E4D7CCE41B9465A700EE7221 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "SwiftyJSON watchOS"; + productName = SwiftyJSON; + productReference = E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */; + productType = "com.apple.product-type.framework"; + }; /* End PBXNativeTarget section */ /* Begin PBXProject section */ @@ -325,6 +364,7 @@ 2E4FEFE519575BE100351305 /* SwiftyJSON iOS Tests */, 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */, 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON OSX Tests */, + E4D7CCDE1B9465A700EE7221 /* SwiftyJSON watchOS */, ); }; /* End PBXProject section */ @@ -360,6 +400,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E4D7CCE41B9465A700EE7221 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXResourcesBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -419,6 +466,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + E4D7CCDF1B9465A700EE7221 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + E4D7CCE01B9465A700EE7221 /* SwiftyJSON.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -673,6 +728,46 @@ }; name = Release; }; + E4D7CCE61B9465A700EE7221 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "$(SRCROOT)/Info-watchOS.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = SwiftyJSON; + SDKROOT = watchos; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "watchsimulator watchos"; + }; + name = Debug; + }; + E4D7CCE71B9465A700EE7221 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "$(SRCROOT)/Info-watchOS.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = SwiftyJSON; + SDKROOT = watchos; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "watchsimulator watchos"; + }; + name = Release; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -721,6 +816,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + E4D7CCE51B9465A700EE7221 /* Build configuration list for PBXNativeTarget "SwiftyJSON watchOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + E4D7CCE61B9465A700EE7221 /* Debug */, + E4D7CCE71B9465A700EE7221 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; /* End XCConfigurationList section */ }; rootObject = 2E4FEFD219575BE100351305 /* Project object */; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme new file mode 100644 index 00000000..03b1b95f --- /dev/null +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 7cc7dd88223fae5c9f675e79b33f6beb5c502717 Mon Sep 17 00:00:00 2001 From: Tobias Ottenweller Date: Mon, 31 Aug 2015 14:32:32 +0200 Subject: [PATCH 157/470] Updated BuilableName --- .../xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme index 03b1b95f..7dacc905 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme @@ -15,7 +15,7 @@ @@ -46,7 +46,7 @@ @@ -64,7 +64,7 @@ From 8ccb619ffd942141347a92dc6fd47fa093a089c4 Mon Sep 17 00:00:00 2001 From: okohtenko Date: Wed, 2 Sep 2015 17:08:32 +0300 Subject: [PATCH 158/470] Existance check + tests + readme --- README.md | 6 ++++++ Source/SwiftyJSON.swift | 6 ++++++ Tests/BaseTests.swift | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/README.md b/README.md index d018e322..68d20a66 100644 --- a/README.md +++ b/README.md @@ -300,6 +300,12 @@ if let data = json.rawData() { if let string = json.rawString() { //Do something you want } + +####Existance +```swift +//shows you whether value specified in JSON or not +if json["name"].isExists() +``` ``` ####Literal convertibles For more info about literal convertibles: [Swift Literal Convertibles](http://nshipster.com/swift-literal-convertible/) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3a5e8a06..b6611510 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -734,6 +734,12 @@ extension JSON { self.object = NSNull() } } + public func isExists() -> Bool{ + if let errorValue = error where errorValue.code == ErrorNotExist{ + return false + } + return true + } } //MARK: - URL diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index d78abdcf..0fe18e9d 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -228,6 +228,13 @@ class BaseTests: XCTestCase { } } + func testExistance() { + let dictionary = ["number":1111] + let json = JSON(dictionary) + XCTAssertFalse(json["unspecifiedValue"].isExists()) + XCTAssertTrue(json["number"].isExists()) + } + func testErrorHandle() { let json = JSON(data:self.testData) if let wrongType = json["wrong-type"].string { From 7df89b7a1be8301ce858e5fe0d410b1209702ecb Mon Sep 17 00:00:00 2001 From: Paul Cantrell Date: Wed, 9 Sep 2015 10:11:09 -0500 Subject: [PATCH 159/470] Parse string numbers as NSDecimalNumber instead of double --- Source/SwiftyJSON.swift | 10 ++++------ Tests/BaseTests.swift | 2 +- Tests/NumberTests.swift | 9 +++++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3a5e8a06..35489de4 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -699,13 +699,11 @@ extension JSON { get { switch self.type { case .String: - let scanner = NSScanner(string: self.object as! String) - if scanner.scanDouble(nil){ - if (scanner.atEnd) { - return NSNumber(double:(self.object as! NSString).doubleValue) - } + let decimal = NSDecimalNumber(string: self.object as? String) + if decimal == NSDecimalNumber.notANumber() { // indicates parse error + return NSDecimalNumber.zero() } - return NSNumber(double: 0.0) + return decimal case .Number, .Bool: return self.object as! NSNumber default: diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index d78abdcf..138a2c2b 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -167,7 +167,7 @@ class BaseTests: XCTestCase { XCTAssertLessThanOrEqual(JSON(-8763), JSON(-8763)) } - func testNumberConverToString(){ + func testNumberConvertToString(){ XCTAssertEqual(JSON(true).stringValue, "true") XCTAssertEqual(JSON(999.9823).stringValue, "999.9823") XCTAssertEqual(JSON(true).number!.stringValue, "1") diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 5254c348..10fc9fb7 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -31,14 +31,23 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 9876543210.123456789) XCTAssertEqual(json.stringValue, "9876543210.123457") + json.string = "1000000000000000000000000000.1" + XCTAssertNil(json.number) + XCTAssertEqual(json.numberValue.description, "1000000000000000000000000000.1") + + json.string = "1e+27" + XCTAssertEqual(json.numberValue.description, "1000000000000000000000000000") + //setter json.number = NSNumber(double: 123456789.0987654321) XCTAssertEqual(json.number!, 123456789.0987654321) XCTAssertEqual(json.numberValue, 123456789.0987654321) + json.number = nil XCTAssertEqual(json.numberValue, 0) XCTAssertEqual(json.object as! NSNull, NSNull()) XCTAssertTrue(json.number == nil) + json.numberValue = 2.9876 XCTAssertEqual(json.number!, 2.9876) } From 06a5bdc52354c27bbc11e36bd62cc5e037eb69d3 Mon Sep 17 00:00:00 2001 From: Robert Otani Date: Thu, 10 Sep 2015 10:55:03 -0700 Subject: [PATCH 160/470] XCode 7 GM: NSNumber now already conforms to Swift.Comparable --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 61423a35..ebf02ada 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1265,7 +1265,7 @@ private let falseObjCType = String.fromCString(falseNumber.objCType) // MARK: - NSNumber: Comparable -extension NSNumber: Swift.Comparable { +extension NSNumber { var isBool:Bool { get { let objCType = String.fromCString(self.objCType) From 18f12d17e4a02723b34df7cdc6c5a0aff82a3d31 Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Fri, 11 Sep 2015 17:59:21 -0400 Subject: [PATCH 161/470] Move watchOS info plist to correct directory. --- Info-watchOS.plist => Source/Info-watchOS.plist | 0 SwiftyJSON.xcodeproj/project.pbxproj | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename Info-watchOS.plist => Source/Info-watchOS.plist (100%) diff --git a/Info-watchOS.plist b/Source/Info-watchOS.plist similarity index 100% rename from Info-watchOS.plist rename to Source/Info-watchOS.plist diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 7b6b79f8..f43f39e8 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -737,7 +737,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Info-watchOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info-watchOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; @@ -757,7 +757,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Info-watchOS.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Source/Info-watchOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; From 3ea43c86d105022999d5737908bbdc3a44cbf857 Mon Sep 17 00:00:00 2001 From: Scott Penrose Date: Fri, 11 Sep 2015 17:59:47 -0400 Subject: [PATCH 162/470] Fix carthage not being able to build the watchOS scheme for simulator --- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index f43f39e8..41f64450 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -745,6 +745,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; + TARGETED_DEVICE_FAMILY = 4; }; name = Debug; }; @@ -765,6 +766,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; + TARGETED_DEVICE_FAMILY = 4; }; name = Release; }; From 9178db058e814b5ac8d86f3a3c9bba2d86deaf60 Mon Sep 17 00:00:00 2001 From: Robert Otani Date: Sat, 12 Sep 2015 19:50:46 -0700 Subject: [PATCH 163/470] XCTAssertLessThan and XCTAssertGreaterThan are now more strict about NSNumber types --- Tests/BaseTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index b51a1321..5a297916 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -254,8 +254,8 @@ class BaseTests: XCTestCase { func testNumberCompare(){ XCTAssertEqual(NSNumber(double: 888332), NSNumber(int:888332)) XCTAssertNotEqual(NSNumber(double: 888332.1), NSNumber(int:888332)) - XCTAssertLessThan(NSNumber(int: 888332), NSNumber(double:888332.1)) - XCTAssertGreaterThan(NSNumber(double: 888332.1), NSNumber(int:888332)) + XCTAssertLessThan(NSNumber(int: 888332).doubleValue, NSNumber(double:888332.1).doubleValue) + XCTAssertGreaterThan(NSNumber(double: 888332.1).doubleValue, NSNumber(int:888332).doubleValue) XCTAssertFalse(NSNumber(double: 1) == NSNumber(bool:true)) XCTAssertFalse(NSNumber(int: 0) == NSNumber(bool:false)) XCTAssertEqual(NSNumber(bool: false), NSNumber(bool:false)) From b8482065c435129ccd815d2ce2544753007cef78 Mon Sep 17 00:00:00 2001 From: Robert Otani Date: Sat, 12 Sep 2015 19:54:30 -0700 Subject: [PATCH 164/470] While NSJSONSerialization states that it will throw, invalid JSON will make it throw prior to parsing. Apple recommends checking for valid JSON first. In practice, I've seen the case where do/try on rawData is never caught on exception, presumably because of the parsing issue (at least in XCode 7 GM.) --- Source/SwiftyJSON.swift | 5 +++++ Tests/RawTests.swift | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index ebf02ada..f5ddb594 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -32,6 +32,7 @@ public let ErrorUnsupportedType: Int! = 999 public let ErrorIndexOutOfBounds: Int! = 900 public let ErrorWrongType: Int! = 901 public let ErrorNotExist: Int! = 500 +public let ErrorInvalidJSON: Int! = 490 // MARK: - JSON Type @@ -610,6 +611,10 @@ extension JSON: Swift.RawRepresentable { } public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(rawValue: 0)) throws -> NSData { + guard NSJSONSerialization.isValidJSONObject(self.object) else { + throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "JSON is invalid"]) + } + return try NSJSONSerialization.dataWithJSONObject(self.object, options: opt) } diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index 171af007..18393c2d 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -25,6 +25,28 @@ import SwiftyJSON class RawTests: XCTestCase { + func testRawData() { + let json: JSON = ["somekey" : "some string value"] + let expectedRawData = "{\"somekey\":\"some string value\"}".dataUsingEncoding(NSUTF8StringEncoding) + do { + let data: NSData = try json.rawData() + XCTAssertEqual(expectedRawData, data) + } catch _ { + XCTFail() + } + } + + func testInvalidJSONForRawData() { + let json: JSON = "...xyz" + do { + try json.rawData() + } catch let error as NSError { + XCTAssertEqual(error.code, ErrorInvalidJSON) + } catch { + XCTFail() + } + } + func testArray() { let json:JSON = [1, "2", 3.12, NSNull(), true, ["name": "Jack"]] let data: NSData? From a669e50c7108de5d15e4646755e603312c7f634d Mon Sep 17 00:00:00 2001 From: Robert Otani Date: Sat, 12 Sep 2015 20:15:49 -0700 Subject: [PATCH 165/470] remove superfluous catch frame --- Tests/RawTests.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index 18393c2d..86669a66 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -42,8 +42,6 @@ class RawTests: XCTestCase { try json.rawData() } catch let error as NSError { XCTAssertEqual(error.code, ErrorInvalidJSON) - } catch { - XCTFail() } } From 50583adf21de1f84a4a06f6dff1b2bb09fe0b03b Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Wed, 16 Sep 2015 19:26:54 +0800 Subject: [PATCH 166/470] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed2298dd..6c772d92 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ platform :ios, '8.0' use_frameworks! target 'MyApp' do - pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git', :branch => 'xcode7' + pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git' end ``` Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 8.0: @@ -99,7 +99,7 @@ Note that this requires CocoaPods version 36, and your iOS deployment target to ####Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` -github "SwiftyJSON/SwiftyJSON" "xcode7" +github "SwiftyJSON/SwiftyJSON" ``` ####Manually (iOS 7+, OS X 10.9+) From 3b5d0d4e0c19173b1bf0dc823bde25ad870f70c0 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Fri, 18 Sep 2015 11:08:25 +0800 Subject: [PATCH 167/470] Update podspec --- SwiftyJSON.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index fbd99fe8..90e6fb41 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.2.1" + s.version = "2.3.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -9,6 +9,6 @@ Pod::Spec.new do |s| s.requires_arc = true s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.2.1"} + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.0"} s.source_files = "Source/*.swift" end From 4af1fc66bdca22652b6d99c38f266a35229c6657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Fri, 18 Sep 2015 11:45:10 +0200 Subject: [PATCH 168/470] Adds support for tvOS --- Info-tvOS.plist | 26 +++++ SwiftyJSON.xcodeproj/project.pbxproj | 108 ++++++++++++++++++ .../xcschemes/SwiftyJSON tvOS.xcscheme | 80 +++++++++++++ 3 files changed, 214 insertions(+) create mode 100644 Info-tvOS.plist create mode 100644 SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme diff --git a/Info-tvOS.plist b/Info-tvOS.plist new file mode 100644 index 00000000..78122054 --- /dev/null +++ b/Info-tvOS.plist @@ -0,0 +1,26 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + ${CURRENT_PROJECT_VERSION} + NSPrincipalClass + + + diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 41f64450..81e55e83 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; + 7236B4EE1BAC14150020529B /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + 7236B4F11BAC14150020529B /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9C459EF41A910334008C9A41 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9C459EF51A910361008C9A41 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; 9C459EF81A9103C1008C9A41 /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; @@ -68,6 +70,8 @@ 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7236B4F61BAC14150020529B /* SwiftyJSON tvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = "SwiftyJSON tvOS.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-tvOS.plist"; path = "/Users/simonbs/Developer/SwiftyJSON/Info-tvOS.plist"; sourceTree = ""; }; 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -107,6 +111,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7236B4EF1BAC14150020529B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 9C7DFC571A9102BD005AA3F7 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -149,6 +160,7 @@ 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */, 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */, E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */, + 7236B4F61BAC14150020529B /* SwiftyJSON tvOS.framework */, ); name = Products; sourceTree = ""; @@ -166,6 +178,7 @@ 2E4FEFDE19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( + 7236B4F71BAC14150020529B /* Info-tvOS.plist */, 2E4FEFDF19575BE100351305 /* Info-iOS.plist */, 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */, E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */, @@ -215,6 +228,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7236B4F01BAC14150020529B /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + 7236B4F11BAC14150020529B /* SwiftyJSON.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 9C7DFC581A9102BD005AA3F7 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -270,6 +291,24 @@ productReference = 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + 7236B4EC1BAC14150020529B /* SwiftyJSON tvOS */ = { + isa = PBXNativeTarget; + buildConfigurationList = 7236B4F31BAC14150020529B /* Build configuration list for PBXNativeTarget "SwiftyJSON tvOS" */; + buildPhases = ( + 7236B4ED1BAC14150020529B /* Sources */, + 7236B4EF1BAC14150020529B /* Frameworks */, + 7236B4F01BAC14150020529B /* Headers */, + 7236B4F21BAC14150020529B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "SwiftyJSON tvOS"; + productName = SwiftyJSON; + productReference = 7236B4F61BAC14150020529B /* SwiftyJSON tvOS.framework */; + productType = "com.apple.product-type.framework"; + }; 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */ = { isa = PBXNativeTarget; buildConfigurationList = 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */; @@ -365,6 +404,7 @@ 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */, 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON OSX Tests */, E4D7CCDE1B9465A700EE7221 /* SwiftyJSON watchOS */, + 7236B4EC1BAC14150020529B /* SwiftyJSON tvOS */, ); }; /* End PBXProject section */ @@ -385,6 +425,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7236B4F21BAC14150020529B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 9C7DFC591A9102BD005AA3F7 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -438,6 +485,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 7236B4ED1BAC14150020529B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 7236B4EE1BAC14150020529B /* SwiftyJSON.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 9C7DFC561A9102BD005AA3F7 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -640,6 +695,50 @@ }; name = Release; }; + 7236B4F41BAC14150020529B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "$(SRCROOT)/Info-tvOS.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = 3; + TVOS_DEPLOYMENT_TARGET = 9.0; + }; + name = Debug; + }; + 7236B4F51BAC14150020529B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CODE_SIGN_IDENTITY = "iPhone Developer"; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = "$(SRCROOT)/Info-tvOS.plist"; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; + SKIP_INSTALL = YES; + TARGETED_DEVICE_FAMILY = 3; + TVOS_DEPLOYMENT_TARGET = 9.0; + }; + name = Release; + }; 9C7DFC6F1A9102BD005AA3F7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -800,6 +899,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 7236B4F31BAC14150020529B /* Build configuration list for PBXNativeTarget "SwiftyJSON tvOS" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 7236B4F41BAC14150020529B /* Debug */, + 7236B4F51BAC14150020529B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme new file mode 100644 index 00000000..55eb664b --- /dev/null +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 75cc8c7d58510433e505103da21deadbfbf38869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Fri, 18 Sep 2015 11:48:34 +0200 Subject: [PATCH 169/470] Changes PRODUCT_NAME of tvOS target to SwiftyJSON --- SwiftyJSON.xcodeproj/project.pbxproj | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 81e55e83..07c3d0d7 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -70,7 +70,7 @@ 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 7236B4F61BAC14150020529B /* SwiftyJSON tvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = "SwiftyJSON tvOS.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7236B4F61BAC14150020529B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-tvOS.plist"; path = "/Users/simonbs/Developer/SwiftyJSON/Info-tvOS.plist"; sourceTree = ""; }; 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -160,7 +160,7 @@ 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */, 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */, E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */, - 7236B4F61BAC14150020529B /* SwiftyJSON tvOS.framework */, + 7236B4F61BAC14150020529B /* SwiftyJSON.framework */, ); name = Products; sourceTree = ""; @@ -306,7 +306,7 @@ ); name = "SwiftyJSON tvOS"; productName = SwiftyJSON; - productReference = 7236B4F61BAC14150020529B /* SwiftyJSON tvOS.framework */; + productReference = 7236B4F61BAC14150020529B /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; }; 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */ = { @@ -709,7 +709,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = SwiftyJSON; SDKROOT = appletvos; SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = 3; @@ -731,7 +731,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = SwiftyJSON; SDKROOT = appletvos; SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = 3; From e69270e3f36f688ef9ac986dd7447b8427911770 Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 23 Sep 2015 11:00:30 +0200 Subject: [PATCH 170/470] Updated comments to the new Swift 2.0 style --- Source/SwiftyJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 61423a35..cc5ca67d 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -101,9 +101,9 @@ public struct JSON { /** Creates a JSON from a [String: JSON] - :param: jsonDictionary A Swift dictionary of JSON objects + - parameter jsonDictionary: A Swift dictionary of JSON objects - :returns: The created JSON + - returns: The created JSON */ public init(_ jsonDictionary:[String: JSON]) { var dictionary = [String: AnyObject]() From fd9e866118f8ac8121e4a30da122bb76f031173d Mon Sep 17 00:00:00 2001 From: Andrey Date: Sat, 3 Oct 2015 03:33:33 +0300 Subject: [PATCH 171/470] println -> print in README.md Little change for Swift 2. --- README.md | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6c772d92..7fdaf798 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { //Calm down, take it easy, the ".string" property still produces the correct Optional String type with safety } else { //Print the error - println(json[999999]["wrong_key"]["wrong_name"]) + print(json[999999]["wrong_key"]["wrong_name"]) } ``` @@ -184,7 +184,7 @@ let json = JSON(["name", "age"]) if let name = json[999].string { //Do something you want } else { - println(json[999].error) // "Array[999] is out of bounds" + print(json[999].error) // "Array[999] is out of bounds" } ``` ```swift @@ -192,7 +192,7 @@ let json = JSON(["name":"Jack", "age": 25]) if let name = json["address"].string { //Do something you want } else { - println(json["address"].error) // "Dictionary["address"] does not exist" + print(json["address"].error) // "Dictionary["address"] does not exist" } ``` ```swift @@ -200,15 +200,15 @@ let json = JSON(12345) if let age = json[0].string { //Do something you want } else { - println(json[0]) // "Array[0] failure, It is not an array" - println(json[0].error) // "Array[0] failure, It is not an array" + print(json[0]) // "Array[0] failure, It is not an array" + print(json[0].error) // "Array[0] failure, It is not an array" } if let name = json["name"].string { //Do something you want } else { - println(json["name"]) // "Dictionary[\"name"] failure, It is not an dictionary" - println(json["name"].error) // "Dictionary[\"name"] failure, It is not an dictionary" + print(json["name"]) // "Dictionary[\"name"] failure, It is not an dictionary" + print(json["name"].error) // "Dictionary[\"name"] failure, It is not an dictionary" } ``` @@ -219,7 +219,7 @@ if let id = json["user"]["favourites_count"].number { //Do something you want } else { //Print the error - println(json["user"]["favourites_count"].error) + print(json["user"]["favourites_count"].error) } ``` ```swift @@ -228,7 +228,7 @@ if let id = json["user"]["name"].string { //Do something you want } else { //Print the error - println(json["user"]["name"]) + print(json["user"]["name"]) } ``` ```swift @@ -237,7 +237,7 @@ if let id = json["user"]["is_translator"].bool { //Do something you want } else { //Print the error - println(json["user"]["is_translator"]) + print(json["user"]["is_translator"]) } ``` ```swift @@ -246,7 +246,7 @@ if let id = json["user"]["id"].int { //Do something you want } else { //Print the error - println(json["user"]["id"]) + print(json["user"]["id"]) } ... ``` @@ -362,8 +362,8 @@ Alamofire.request(.GET, url, parameters: parameters) .responseJSON { (req, res, json, error) in if(error != nil) { NSLog("Error: \(error)") - println(req) - println(res) + print(req) + print(res) } else { NSLog("Success: \(url)") From aade0fd6a0a8b26b95c8457520449a234c4ea4e2 Mon Sep 17 00:00:00 2001 From: Thomas Visser Date: Mon, 5 Oct 2015 16:45:03 +0200 Subject: [PATCH 172/470] Added Carthage bitcode support (see https://github.com/Carthage/Carthage/issues/535) --- SwiftyJSON.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 41f64450..19b35162 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -580,6 +580,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -599,6 +600,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -732,6 +734,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -753,6 +756,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; From d11cd7d8f9c226e5af95b2182367424a85380499 Mon Sep 17 00:00:00 2001 From: Tyler Long Date: Sat, 10 Oct 2015 14:10:24 +0800 Subject: [PATCH 173/470] MACOSX_DEPLOYMENT_TARGET = 10.9 --- SwiftyJSON.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 41f64450..d6a5305c 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -526,7 +526,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -566,7 +566,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; From a5a861b6e090efc1ddc7c434d6e76f31ca9a1dca Mon Sep 17 00:00:00 2001 From: bassrock Date: Fri, 21 Aug 2015 20:08:47 -0700 Subject: [PATCH 174/470] Adding watchOS. --- SwiftyJSON.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 90e6fb41..01441a15 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -9,6 +9,7 @@ Pod::Spec.new do |s| s.requires_arc = true s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" + s.watchos.deployment_target = "2.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.0"} s.source_files = "Source/*.swift" end From 35c94b244ceb3be1b1b89371642564e912d2ffbd Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Thu, 15 Oct 2015 13:06:05 +0800 Subject: [PATCH 175/470] Adding tvOS testing --- Info-tvOS.plist => Source/Info-tvOS.plist | 0 SwiftyJSON.xcodeproj/project.pbxproj | 149 +++++++++++++++++- .../xcschemes/SwiftyJSON tvOS.xcscheme | 19 +++ Tests/Info-tvOS.plist | 24 +++ 4 files changed, 184 insertions(+), 8 deletions(-) rename Info-tvOS.plist => Source/Info-tvOS.plist (100%) create mode 100644 Tests/Info-tvOS.plist diff --git a/Info-tvOS.plist b/Source/Info-tvOS.plist similarity index 100% rename from Info-tvOS.plist rename to Source/Info-tvOS.plist diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 1f7541d5..a8f5ee3f 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -32,7 +32,22 @@ A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; + A81CBA0B1BCF6B0200A649A2 /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; + A8580F791BCF5C5B00DA927B /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7236B4F61BAC14150020529B /* SwiftyJSON.framework */; }; + A8580F801BCF69A000DA927B /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; + A8580F811BCF69A000DA927B /* BaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */; }; + A8580F821BCF69A000DA927B /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; + A8580F831BCF69A000DA927B /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; + A8580F841BCF69A000DA927B /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; + A8580F851BCF69A000DA927B /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; + A8580F861BCF69A000DA927B /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; + A8580F871BCF69A000DA927B /* ComparableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E519E3DF7800CDE086 /* ComparableTests.swift */; }; + A8580F881BCF69A000DA927B /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E919E43C0700CDE086 /* StringTests.swift */; }; + A8580F891BCF69A000DA927B /* NumberTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E719E439DA00CDE086 /* NumberTests.swift */; }; + A8580F8A1BCF69A000DA927B /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; + A8580F8B1BCF69A000DA927B /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; + A8580F8C1BCF69A000DA927B /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; A863BE2819EED46F0092A41F /* RawTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A863BE2719EED46F0092A41F /* RawTests.swift */; }; A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */; }; @@ -62,6 +77,13 @@ remoteGlobalIDString = 9C7DFC5A1A9102BD005AA3F7; remoteInfo = "SwiftyJSON OSX"; }; + A8580F7A1BCF5C5B00DA927B /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 2E4FEFD219575BE100351305 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 7236B4EC1BAC14150020529B; + remoteInfo = "SwiftyJSON tvOS"; + }; /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ @@ -71,7 +93,7 @@ 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 7236B4F61BAC14150020529B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-tvOS.plist"; path = "/Users/simonbs/Developer/SwiftyJSON/Info-tvOS.plist"; sourceTree = ""; }; + 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -81,6 +103,8 @@ A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; + A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawTests.swift; sourceTree = ""; }; A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = ""; }; A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; @@ -92,7 +116,7 @@ A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryTests.swift; sourceTree = ""; }; A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTests.swift; sourceTree = ""; }; E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-watchOS.plist"; path = "/Users/tobiasottenweller/Code/SwiftyJSON/Info-watchOS.plist"; sourceTree = ""; }; + E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-watchOS.plist"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -133,6 +157,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A8580F711BCF5C5B00DA927B /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + A8580F791BCF5C5B00DA927B /* SwiftyJSON.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; E4D7CCE11B9465A700EE7221 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -161,6 +193,7 @@ 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */, E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */, 7236B4F61BAC14150020529B /* SwiftyJSON.framework */, + A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */, ); name = Products; sourceTree = ""; @@ -178,10 +211,10 @@ 2E4FEFDE19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( - 7236B4F71BAC14150020529B /* Info-tvOS.plist */, 2E4FEFDF19575BE100351305 /* Info-iOS.plist */, 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */, E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */, + 7236B4F71BAC14150020529B /* Info-tvOS.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -213,6 +246,7 @@ children = ( A82A1C0D19D922DC009A653D /* Info-iOS.plist */, 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */, + A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */, ); name = "Supporting Files"; sourceTree = ""; @@ -345,6 +379,24 @@ productReference = 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + A8580F731BCF5C5B00DA927B /* SwiftyJSON tvOS Tests */ = { + isa = PBXNativeTarget; + buildConfigurationList = A8580F7C1BCF5C5B00DA927B /* Build configuration list for PBXNativeTarget "SwiftyJSON tvOS Tests" */; + buildPhases = ( + A8580F701BCF5C5B00DA927B /* Sources */, + A8580F711BCF5C5B00DA927B /* Frameworks */, + A8580F721BCF5C5B00DA927B /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + A8580F7B1BCF5C5B00DA927B /* PBXTargetDependency */, + ); + name = "SwiftyJSON tvOS Tests"; + productName = "SwiftyJSON tvOS Tests"; + productReference = A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; E4D7CCDE1B9465A700EE7221 /* SwiftyJSON watchOS */ = { isa = PBXNativeTarget; buildConfigurationList = E4D7CCE51B9465A700EE7221 /* Build configuration list for PBXNativeTarget "SwiftyJSON watchOS" */; @@ -369,7 +421,7 @@ 2E4FEFD219575BE100351305 /* Project object */ = { isa = PBXProject; attributes = { - LastSwiftUpdateCheck = 0700; + LastSwiftUpdateCheck = 0710; LastUpgradeCheck = 0700; TargetAttributes = { 2E4FEFDA19575BE100351305 = { @@ -385,6 +437,9 @@ 9C7DFC641A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; }; + A8580F731BCF5C5B00DA927B = { + CreatedOnToolsVersion = 7.1; + }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -405,6 +460,7 @@ 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON OSX Tests */, E4D7CCDE1B9465A700EE7221 /* SwiftyJSON watchOS */, 7236B4EC1BAC14150020529B /* SwiftyJSON tvOS */, + A8580F731BCF5C5B00DA927B /* SwiftyJSON tvOS Tests */, ); }; /* End PBXProject section */ @@ -447,6 +503,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A8580F721BCF5C5B00DA927B /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A81CBA0B1BCF6B0200A649A2 /* Tests.json in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; E4D7CCE41B9465A700EE7221 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -521,6 +585,26 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + A8580F701BCF5C5B00DA927B /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A8580F801BCF69A000DA927B /* PerformanceTests.swift in Sources */, + A8580F811BCF69A000DA927B /* BaseTests.swift in Sources */, + A8580F821BCF69A000DA927B /* SequenceTypeTests.swift in Sources */, + A8580F831BCF69A000DA927B /* PrintableTests.swift in Sources */, + A8580F841BCF69A000DA927B /* SubscriptTests.swift in Sources */, + A8580F851BCF69A000DA927B /* LiteralConvertibleTests.swift in Sources */, + A8580F861BCF69A000DA927B /* RawRepresentableTests.swift in Sources */, + A8580F871BCF69A000DA927B /* ComparableTests.swift in Sources */, + A8580F881BCF69A000DA927B /* StringTests.swift in Sources */, + A8580F891BCF69A000DA927B /* NumberTests.swift in Sources */, + A8580F8A1BCF69A000DA927B /* RawTests.swift in Sources */, + A8580F8B1BCF69A000DA927B /* DictionaryTests.swift in Sources */, + A8580F8C1BCF69A000DA927B /* ArrayTests.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; E4D7CCDF1B9465A700EE7221 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -542,6 +626,11 @@ target = 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */; targetProxy = 9C7DFC671A9102BD005AA3F7 /* PBXContainerItemProxy */; }; + A8580F7B1BCF5C5B00DA927B /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 7236B4EC1BAC14150020529B /* SwiftyJSON tvOS */; + targetProxy = A8580F7A1BCF5C5B00DA927B /* PBXContainerItemProxy */; + }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -581,6 +670,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -621,6 +711,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -706,7 +797,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Info-tvOS.plist"; + INFOPLIST_FILE = "Source/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -728,7 +819,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Info-tvOS.plist"; + INFOPLIST_FILE = "Source/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -759,6 +850,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; + PLIST_FILE_OUTPUT_FORMAT = binary; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; @@ -781,6 +873,7 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; + PLIST_FILE_OUTPUT_FORMAT = binary; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; @@ -829,6 +922,37 @@ }; name = Release; }; + A8580F7D1BCF5C5B00DA927B /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + DEBUG_INFORMATION_FORMAT = dwarf; + GCC_NO_COMMON_BLOCKS = YES; + INFOPLIST_FILE = "Tests/Info-tvOS.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = YES; + PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; + TVOS_DEPLOYMENT_TARGET = 9.0; + }; + name = Debug; + }; + A8580F7E1BCF5C5B00DA927B /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_NO_COMMON_BLOCKS = YES; + INFOPLIST_FILE = "Tests/Info-tvOS.plist"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + MTL_ENABLE_DEBUG_INFO = NO; + PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = appletvos; + TVOS_DEPLOYMENT_TARGET = 9.0; + }; + name = Release; + }; E4D7CCE61B9465A700EE7221 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -839,7 +963,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-watchOS.plist"; + INFOPLIST_FILE = "Source/Info-OSX.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; @@ -861,7 +985,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = "$(SRCROOT)/Source/Info-watchOS.plist"; + INFOPLIST_FILE = "Source/Info-OSX.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; @@ -930,6 +1054,15 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + A8580F7C1BCF5C5B00DA927B /* Build configuration list for PBXNativeTarget "SwiftyJSON tvOS Tests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A8580F7D1BCF5C5B00DA927B /* Debug */, + A8580F7E1BCF5C5B00DA927B /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; E4D7CCE51B9465A700EE7221 /* Build configuration list for PBXNativeTarget "SwiftyJSON watchOS" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme index 5869fa7d..cabc9c76 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme @@ -28,7 +28,26 @@ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + + diff --git a/Tests/Info-tvOS.plist b/Tests/Info-tvOS.plist new file mode 100644 index 00000000..ba72822e --- /dev/null +++ b/Tests/Info-tvOS.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + From 10e2c2a8db16fc0d01c648255219dcb447b10545 Mon Sep 17 00:00:00 2001 From: Sam Easterby-Smith Date: Mon, 19 Oct 2015 23:29:19 +0100 Subject: [PATCH 176/470] Added tvOS deployment target to podspec --- SwiftyJSON.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 01441a15..277d5629 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -10,6 +10,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" s.watchos.deployment_target = "2.0" + s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.0"} s.source_files = "Source/*.swift" end From 4e0cc63562fe851b0314f6a9768d53c778e53944 Mon Sep 17 00:00:00 2001 From: Marcos Polanco Date: Mon, 19 Oct 2015 20:18:46 -0700 Subject: [PATCH 177/470] Update SwiftyJSON.podspec --- SwiftyJSON.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 01441a15..277d5629 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -10,6 +10,7 @@ Pod::Spec.new do |s| s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" s.watchos.deployment_target = "2.0" + s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.0"} s.source_files = "Source/*.swift" end From e43f400c39136e4fdeeb9c62db2e45b51c5805cf Mon Sep 17 00:00:00 2001 From: Rick Sanchez Date: Thu, 22 Oct 2015 19:49:33 +1100 Subject: [PATCH 178/470] Change key to index for array --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 20058d1b..622ae47c 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ for (key,subJson):(String, JSON) in json { ```swift //If json is .Array //The `index` is 0.. Date: Thu, 22 Oct 2015 15:47:18 -0500 Subject: [PATCH 179/470] Fix formatting issues in README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 20058d1b..6187876d 100644 --- a/README.md +++ b/README.md @@ -300,13 +300,13 @@ if let data = json.rawData() { if let string = json.rawString() { //Do something you want } - +``` ####Existance ```swift //shows you whether value specified in JSON or not if json["name"].isExists() ``` -``` + ####Literal convertibles For more info about literal convertibles: [Swift Literal Convertibles](http://nshipster.com/swift-literal-convertible/) ```swift From ddf8244d7ac92644ce3dc18f0b99984b845b1408 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Mon, 26 Oct 2015 17:28:34 +0800 Subject: [PATCH 180/470] update pod specs --- SwiftyJSON.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 277d5629..6a357e2b 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.3.0" + s.version = "2.3.1" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -11,6 +11,6 @@ Pod::Spec.new do |s| s.ios.deployment_target = "8.0" s.watchos.deployment_target = "2.0" s.tvos.deployment_target = "9.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.0"} + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.1"} s.source_files = "Source/*.swift" end From 5f5d00dbdcd256600a250765d9f674964080ceee Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Mon, 26 Oct 2015 17:53:15 +0800 Subject: [PATCH 181/470] We do return true if the JSON is neither an Array nor a Dictionary --- Source/SwiftyJSON.swift | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a63ef84f..cbb33c39 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -224,7 +224,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { } } - /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `false`. + /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `true`. public var isEmpty: Bool { get { switch self.type { diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index a8f5ee3f..3d4dad70 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -770,6 +770,7 @@ "$(inherited)", ); INFOPLIST_FILE = "Tests/Info-iOS.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; @@ -781,6 +782,7 @@ isa = XCBuildConfiguration; buildSettings = { INFOPLIST_FILE = "Tests/Info-iOS.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; From 662fff11a6d49b4b297d6f01262c871a22ffa110 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Wed, 28 Oct 2015 23:57:28 +0800 Subject: [PATCH 182/470] Adding Support for Custom JSONSubscriptType --- Source/SwiftyJSON.swift | 263 +++++++++++++++++++++------------------- 1 file changed, 138 insertions(+), 125 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index cbb33c39..289cbddc 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -42,7 +42,7 @@ JSON's type definitions. See http://tools.ietf.org/html/rfc7231#section-4.3 */ public enum Type :Int{ - + case Number case String case Bool @@ -55,14 +55,14 @@ public enum Type :Int{ // MARK: - JSON Base public struct JSON { - + /** Creates a JSON using the data. - + - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - parameter opt: The JSON serialization reading options. `.AllowFragments` by default. - parameter error: error The NSErrorPointer used to return the error. `nil` by default. - + - returns: The created JSON */ public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { @@ -76,34 +76,34 @@ public struct JSON { self.init(NSNull()) } } - + /** Creates a JSON using the object. - + - parameter object: The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. - + - returns: The created JSON */ public init(_ object: AnyObject) { self.object = object } - + /** Creates a JSON from a [JSON] - + - parameter jsonArray: A Swift array of JSON objects - + - returns: The created JSON */ public init(_ jsonArray:[JSON]) { self.init(jsonArray.map { $0.object }) } - + /** Creates a JSON from a [String: JSON] - + - parameter jsonDictionary: A Swift dictionary of JSON objects - + - returns: The created JSON */ public init(_ jsonDictionary:[String: JSON]) { @@ -113,7 +113,7 @@ public struct JSON { } self.init(dictionary) } - + /// Private object private var rawArray: [AnyObject] = [] private var rawDictionary: [String : AnyObject] = [:] @@ -124,7 +124,7 @@ public struct JSON { private var _type: Type = .Null /// prviate error private var _error: NSError? = nil - + /// Object in JSON public var object: AnyObject { get { @@ -170,13 +170,13 @@ public struct JSON { } } } - + /// json type public var type: Type { get { return _type } } - + /// Error in JSON public var error: NSError? { get { return self._error } } - + /// The static null json @available(*, unavailable, renamed="null") public static var nullJSON: JSON { get { return null } } @@ -185,11 +185,11 @@ public struct JSON { // MARK: - CollectionType, SequenceType, Indexable extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { - + public typealias Generator = JSONGenerator - + public typealias Index = JSONIndex - + public var startIndex: JSON.Index { switch self.type { case .Array: @@ -200,7 +200,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { return JSONIndex() } } - + public var endIndex: JSON.Index { switch self.type { case .Array: @@ -211,7 +211,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { return JSONIndex() } } - + public subscript (position: JSON.Index) -> JSON.Generator.Element { switch self.type { case .Array: @@ -223,7 +223,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { return ("", JSON.null) } } - + /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `true`. public var isEmpty: Bool { get { @@ -237,7 +237,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { } } } - + /// If `type` is `.Array` or `.Dictionary`, return `array.count` or `dictonary.count` otherwise return `0`. public var count: Int { switch self.type { @@ -249,7 +249,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { return 0 } } - + public func underestimateCount() -> Int { switch self.type { case .Array: @@ -260,10 +260,10 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { return 0 } } - + /** If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary`, otherwise return a generator over empty. - + - returns: Return a *generator* over the elements of JSON. */ public func generate() -> JSON.Generator { @@ -272,30 +272,30 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { } public struct JSONIndex: ForwardIndexType, _Incrementable, Equatable, Comparable { - + let arrayIndex: Int? let dictionaryIndex: DictionaryIndex? - + let type: Type - + init(){ self.arrayIndex = nil self.dictionaryIndex = nil self.type = .Unknown } - + init(arrayIndex: Int) { self.arrayIndex = arrayIndex self.dictionaryIndex = nil self.type = .Array } - + init(dictionaryIndex: DictionaryIndex) { self.arrayIndex = nil self.dictionaryIndex = dictionaryIndex self.type = .Dictionary } - + public func successor() -> JSONIndex { switch self.type { case .Array: @@ -364,14 +364,14 @@ public func >(lhs: JSONIndex, rhs: JSONIndex) -> Bool { } public struct JSONGenerator : GeneratorType { - + public typealias Element = (String, JSON) - + private let type: Type private var dictionayGenerate: DictionaryGenerator? private var arrayGenerate: IndexingGenerator<[AnyObject]>? private var arrayIndex: Int = 0 - + init(_ json: JSON) { self.type = json.type if type == .Array { @@ -380,7 +380,7 @@ public struct JSONGenerator : GeneratorType { self.dictionayGenerate = json.rawDictionary.generate() } } - + public mutating func next() -> JSONGenerator.Element? { switch self.type { case .Array: @@ -406,14 +406,29 @@ public struct JSONGenerator : GeneratorType { /** * To mark both String and Int can be used in subscript. */ -public protocol JSONSubscriptType {} +public enum JSONSubscriptKey { + case Index(Int) + case Key(String) +} -extension Int: JSONSubscriptType {} +public protocol JSONSubscriptType { + var jsonKey:JSONSubscriptKey { get } +} + +extension Int: JSONSubscriptType { + public var jsonKey:JSONSubscriptKey { + return JSONSubscriptKey.Index(self) + } +} -extension String: JSONSubscriptType {} +extension String: JSONSubscriptType { + public var jsonKey:JSONSubscriptKey { + return JSONSubscriptKey.Key(self) + } +} extension JSON { - + /// If `type` is `.Array`, return json which's object is `array[index]`, otherwise return null json with error. private subscript(index index: Int) -> JSON { get { @@ -437,7 +452,7 @@ extension JSON { } } } - + /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. private subscript(key key: String) -> JSON { get { @@ -459,36 +474,34 @@ extension JSON { } } } - + /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. private subscript(sub sub: JSONSubscriptType) -> JSON { get { - if sub is String { - return self[key:sub as! String] - } else { - return self[index:sub as! Int] + switch sub.jsonKey { + case .Index(let index): return self[index: index] + case .Key(let key): return self[key: key] } } set { - if sub is String { - self[key:sub as! String] = newValue - } else { - self[index:sub as! Int] = newValue + switch sub.jsonKey { + case .Index(let index): self[index: index] = newValue + case .Key(let key): self[key: key] = newValue } } } - + /** Find a json in the complex data structuresby using the Int/String's array. - + - parameter path: The target json's path. Example: - + let json = JSON[data] let path = [9,"list","person","name"] let name = json[path] - + The same as: let name = json[9]["list"]["person"]["name"] - + - returns: Return a json found by the path or a null json with error */ public subscript(path: [JSONSubscriptType]) -> JSON { @@ -509,16 +522,16 @@ extension JSON { } } } - + /** Find a json in the complex data structuresby using the Int/String's array. - + - parameter path: The target json's path. Example: - + let name = json[9,"list","person","name"] - + The same as: let name = json[9]["list"]["person"]["name"] - + - returns: Return a json found by the path or a null json with error */ public subscript(path: JSONSubscriptType...) -> JSON { @@ -534,43 +547,43 @@ extension JSON { // MARK: - LiteralConvertible extension JSON: Swift.StringLiteralConvertible { - + public init(stringLiteral value: StringLiteralType) { self.init(value) } - + public init(extendedGraphemeClusterLiteral value: StringLiteralType) { self.init(value) } - + public init(unicodeScalarLiteral value: StringLiteralType) { self.init(value) } } extension JSON: Swift.IntegerLiteralConvertible { - + public init(integerLiteral value: IntegerLiteralType) { self.init(value) } } extension JSON: Swift.BooleanLiteralConvertible { - + public init(booleanLiteral value: BooleanLiteralType) { self.init(value) } } extension JSON: Swift.FloatLiteralConvertible { - + public init(floatLiteral value: FloatLiteralType) { self.init(value) } } extension JSON: Swift.DictionaryLiteralConvertible { - + public init(dictionaryLiteral elements: (String, AnyObject)...) { self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in var d = dictionary @@ -581,14 +594,14 @@ extension JSON: Swift.DictionaryLiteralConvertible { } extension JSON: Swift.ArrayLiteralConvertible { - + public init(arrayLiteral elements: AnyObject...) { self.init(elements) } } extension JSON: Swift.NilLiteralConvertible { - + public init(nilLiteral: ()) { self.init(NSNull()) } @@ -597,7 +610,7 @@ extension JSON: Swift.NilLiteralConvertible { // MARK: - Raw extension JSON: Swift.RawRepresentable { - + public init?(rawValue: AnyObject) { if JSON(rawValue).type == .Unknown { return nil @@ -605,19 +618,19 @@ extension JSON: Swift.RawRepresentable { self.init(rawValue) } } - + public var rawValue: AnyObject { return self.object } - + public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(rawValue: 0)) throws -> NSData { guard NSJSONSerialization.isValidJSONObject(self.object) else { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "JSON is invalid"]) } - + return try NSJSONSerialization.dataWithJSONObject(self.object, options: opt) } - + public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted) -> String? { switch self.type { case .Array, .Dictionary: @@ -644,7 +657,7 @@ extension JSON: Swift.RawRepresentable { // MARK: - Printable, DebugPrintable extension JSON: Swift.Printable, Swift.DebugPrintable { - + public var description: String { if let string = self.rawString(options:.PrettyPrinted) { return string @@ -652,7 +665,7 @@ extension JSON: Swift.Printable, Swift.DebugPrintable { return "unknown" } } - + public var debugDescription: String { return description } @@ -661,7 +674,7 @@ extension JSON: Swift.Printable, Swift.DebugPrintable { // MARK: - Array extension JSON { - + //Optional [JSON] public var array: [JSON]? { get { @@ -672,14 +685,14 @@ extension JSON { } } } - + //Non-optional [JSON] public var arrayValue: [JSON] { get { return self.array ?? [] } } - + //Optional [AnyObject] public var arrayObject: [AnyObject]? { get { @@ -703,7 +716,7 @@ extension JSON { // MARK: - Dictionary extension JSON { - + //Optional [String : JSON] public var dictionary: [String : JSON]? { if self.type == .Dictionary { @@ -716,12 +729,12 @@ extension JSON { return nil } } - + //Non-optional [String : JSON] public var dictionaryValue: [String : JSON] { return self.dictionary ?? [:] } - + //Optional [String : AnyObject] public var dictionaryObject: [String : AnyObject]? { get { @@ -745,7 +758,7 @@ extension JSON { // MARK: - Bool extension JSON: Swift.BooleanType { - + //Optional bool public var bool: Bool? { get { @@ -764,7 +777,7 @@ extension JSON: Swift.BooleanType { } } } - + //Non-optional bool public var boolValue: Bool { get { @@ -784,7 +797,7 @@ extension JSON: Swift.BooleanType { // MARK: - String extension JSON { - + //Optional string public var string: String? { get { @@ -803,7 +816,7 @@ extension JSON { } } } - + //Non-optional string public var stringValue: String { get { @@ -826,7 +839,7 @@ extension JSON { // MARK: - Number extension JSON { - + //Optional number public var number: NSNumber? { get { @@ -841,7 +854,7 @@ extension JSON { self.object = newValue ?? NSNull() } } - + //Non-optional number public var numberValue: NSNumber { get { @@ -866,7 +879,7 @@ extension JSON { //MARK: - Null extension JSON { - + public var null: NSNull? { get { switch self.type { @@ -890,7 +903,7 @@ extension JSON { //MARK: - URL extension JSON { - + //Optional URL public var URL: NSURL? { get { @@ -914,7 +927,7 @@ extension JSON { // MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 extension JSON { - + public var double: Double? { get { return self.number?.doubleValue @@ -927,7 +940,7 @@ extension JSON { } } } - + public var doubleValue: Double { get { return self.numberValue.doubleValue @@ -936,7 +949,7 @@ extension JSON { self.object = NSNumber(double: newValue) } } - + public var float: Float? { get { return self.number?.floatValue @@ -949,7 +962,7 @@ extension JSON { } } } - + public var floatValue: Float { get { return self.numberValue.floatValue @@ -958,7 +971,7 @@ extension JSON { self.object = NSNumber(float: newValue) } } - + public var int: Int? { get { return self.number?.longValue @@ -971,7 +984,7 @@ extension JSON { } } } - + public var intValue: Int { get { return self.numberValue.integerValue @@ -980,7 +993,7 @@ extension JSON { self.object = NSNumber(integer: newValue) } } - + public var uInt: UInt? { get { return self.number?.unsignedLongValue @@ -993,7 +1006,7 @@ extension JSON { } } } - + public var uIntValue: UInt { get { return self.numberValue.unsignedLongValue @@ -1002,7 +1015,7 @@ extension JSON { self.object = NSNumber(unsignedLong: newValue) } } - + public var int8: Int8? { get { return self.number?.charValue @@ -1015,7 +1028,7 @@ extension JSON { } } } - + public var int8Value: Int8 { get { return self.numberValue.charValue @@ -1024,7 +1037,7 @@ extension JSON { self.object = NSNumber(char: newValue) } } - + public var uInt8: UInt8? { get { return self.number?.unsignedCharValue @@ -1037,7 +1050,7 @@ extension JSON { } } } - + public var uInt8Value: UInt8 { get { return self.numberValue.unsignedCharValue @@ -1046,7 +1059,7 @@ extension JSON { self.object = NSNumber(unsignedChar: newValue) } } - + public var int16: Int16? { get { return self.number?.shortValue @@ -1059,7 +1072,7 @@ extension JSON { } } } - + public var int16Value: Int16 { get { return self.numberValue.shortValue @@ -1068,7 +1081,7 @@ extension JSON { self.object = NSNumber(short: newValue) } } - + public var uInt16: UInt16? { get { return self.number?.unsignedShortValue @@ -1081,7 +1094,7 @@ extension JSON { } } } - + public var uInt16Value: UInt16 { get { return self.numberValue.unsignedShortValue @@ -1090,7 +1103,7 @@ extension JSON { self.object = NSNumber(unsignedShort: newValue) } } - + public var int32: Int32? { get { return self.number?.intValue @@ -1103,7 +1116,7 @@ extension JSON { } } } - + public var int32Value: Int32 { get { return self.numberValue.intValue @@ -1112,7 +1125,7 @@ extension JSON { self.object = NSNumber(int: newValue) } } - + public var uInt32: UInt32? { get { return self.number?.unsignedIntValue @@ -1125,7 +1138,7 @@ extension JSON { } } } - + public var uInt32Value: UInt32 { get { return self.numberValue.unsignedIntValue @@ -1134,7 +1147,7 @@ extension JSON { self.object = NSNumber(unsignedInt: newValue) } } - + public var int64: Int64? { get { return self.number?.longLongValue @@ -1147,7 +1160,7 @@ extension JSON { } } } - + public var int64Value: Int64 { get { return self.numberValue.longLongValue @@ -1156,7 +1169,7 @@ extension JSON { self.object = NSNumber(longLong: newValue) } } - + public var uInt64: UInt64? { get { return self.number?.unsignedLongLongValue @@ -1169,7 +1182,7 @@ extension JSON { } } } - + public var uInt64Value: UInt64 { get { return self.numberValue.unsignedLongLongValue @@ -1184,7 +1197,7 @@ extension JSON { extension JSON : Swift.Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.Number, .Number): return lhs.rawNumber == rhs.rawNumber @@ -1204,7 +1217,7 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { } public func <=(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.Number, .Number): return lhs.rawNumber <= rhs.rawNumber @@ -1224,7 +1237,7 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { } public func >=(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.Number, .Number): return lhs.rawNumber >= rhs.rawNumber @@ -1244,7 +1257,7 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { } public func >(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.Number, .Number): return lhs.rawNumber > rhs.rawNumber @@ -1256,7 +1269,7 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { } public func <(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.Number, .Number): return lhs.rawNumber < rhs.rawNumber @@ -1304,7 +1317,7 @@ public func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { } public func <(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1316,7 +1329,7 @@ public func <(lhs: NSNumber, rhs: NSNumber) -> Bool { } public func >(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1328,7 +1341,7 @@ public func >(lhs: NSNumber, rhs: NSNumber) -> Bool { } public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1340,7 +1353,7 @@ public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { } public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false From fdd674e2c67f5189f4989bf29723c80a84227627 Mon Sep 17 00:00:00 2001 From: Josh Brown Date: Thu, 29 Oct 2015 21:28:29 -0400 Subject: [PATCH 183/470] Updated README with better JSON parsing in Swift 2 --- README.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 20058d1b..9668d3d9 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,9 @@ The code would look like this: ```swift -let JSONObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) - -if let statusesArray = JSONObject as? [AnyObject], - let status = statusesArray[0] as? [String: AnyObject], - let user = status["user"] as? [String: AnyObject], - let username = user["name"] as? String { +if let statusesArray = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as? [[String: AnyObject]], + let user = statusesArray[0]["user"] as? [String: AnyObject], + let username = user["name"] as? String { // Finally we got the username } @@ -43,10 +40,9 @@ Even if we use optional chaining, it would be messy: ```swift -let JSONObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) - -if let username = (((JSONObject as? [AnyObject])?[0] as? [String: AnyObject])?["user"] as? [String: AnyObject])?["name"] as? String { - // What a disaster +if let JSONObject = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as? [[String: AnyObject]], + let username = (JSONObject[0]["user"] as? [String: AnyObject])?["name"] as? String { + // There's our username } ``` From 21ba023f5afd146dbb46094aa1ca6ca316942261 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 02:15:08 +0800 Subject: [PATCH 184/470] Update Travis Config --- .travis.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ef88a869..f428ff96 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,6 @@ language: objective-c -script: "xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme \"SwiftyJSON iOS\" -destination \"platform=iOS Simulator,name=iPhone 5\"" + +osx_image: xcode7 +xcode_sdk: iphonesimulator9.0 + +script: 'xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS"' From e5a5efb01d0e878e566d65e4c3a9314cff6e4417 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 02:19:27 +0800 Subject: [PATCH 185/470] Add back device specs --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f428ff96..bc7eeb09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,4 @@ language: objective-c osx_image: xcode7 xcode_sdk: iphonesimulator9.0 -script: 'xcodebuild test -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS"' +script: 'xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" test' From ab0ddbaec8c025e1f8d52fb50904bb1fa912ad5b Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 02:26:10 +0800 Subject: [PATCH 186/470] Adding tvOS and OSX --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index bc7eeb09..194af0cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,6 @@ osx_image: xcode7 xcode_sdk: iphonesimulator9.0 script: 'xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" test' +script: 'xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" test' +script: 'xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" test' + From def6ca609057544933082979816b0e56fa684756 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 02:33:21 +0800 Subject: [PATCH 187/470] Removing tvOS tests for now --- .travis.yml | 4 +--- scripts/ci.sh | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100755 scripts/ci.sh diff --git a/.travis.yml b/.travis.yml index 194af0cf..4414cbfc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,5 @@ language: objective-c osx_image: xcode7 xcode_sdk: iphonesimulator9.0 -script: 'xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" test' -script: 'xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" test' -script: 'xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" test' +script: 'sh scripts/ci.sh' diff --git a/scripts/ci.sh b/scripts/ci.sh new file mode 100755 index 00000000..39e02ac0 --- /dev/null +++ b/scripts/ci.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +set -e +xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" test +xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" test + +# Not running tvOS since Travis CI doesn't yet support it. +# xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" test \ No newline at end of file From 37ffd5d7241f48684e924e8b18695b193e7ad6fd Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 08:55:22 +0800 Subject: [PATCH 188/470] Add tvOS --- .travis.yml | 2 +- scripts/ci.sh | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4414cbfc..24b06066 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: objective-c -osx_image: xcode7 +osx_image: xcode7.1 xcode_sdk: iphonesimulator9.0 script: 'sh scripts/ci.sh' diff --git a/scripts/ci.sh b/scripts/ci.sh index 39e02ac0..98277210 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -1,8 +1,9 @@ #!/usr/bin/env bash set -e + xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" test + xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" test -# Not running tvOS since Travis CI doesn't yet support it. -# xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" test \ No newline at end of file +xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" test \ No newline at end of file From 28fdb86271c904d933964a03c99cb0b71cf3d76d Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Sat, 31 Oct 2015 11:50:01 +0800 Subject: [PATCH 189/470] Add Travis CI Icon --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 539029dd..b6bb963c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ #SwiftyJSON [中文介绍](http://tangplin.github.io/swiftyjson/) +[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) + SwiftyJSON makes it easy to deal with JSON data in Swift. 1. [Why is the typical JSON handling in Swift NOT good](#why-is-the-typical-json-handling-in-swift-not-good) From 646f7e8813e6627bd9b09c77d5e775b67988de72 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Sat, 31 Oct 2015 11:55:32 +0800 Subject: [PATCH 190/470] Fix Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6bb963c..9fe68f1e 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The code would look like this: ```swift -if let statusesArray = try NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as? [[String: AnyObject]], +if let statusesArray = try? NSJSONSerialization.JSONObjectWithData(data, options: .AllowFragments) as? [[String: AnyObject]], let user = statusesArray[0]["user"] as? [String: AnyObject], let username = user["name"] as? String { // Finally we got the username From fd5fac549fd0976ba60938249b6ad07b764e16eb Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 11:59:33 +0800 Subject: [PATCH 191/470] Rename it to JSONKey --- Source/SwiftyJSON.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 289cbddc..f0397a45 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -406,24 +406,24 @@ public struct JSONGenerator : GeneratorType { /** * To mark both String and Int can be used in subscript. */ -public enum JSONSubscriptKey { +public enum JSONKey { case Index(Int) case Key(String) } public protocol JSONSubscriptType { - var jsonKey:JSONSubscriptKey { get } + var jsonKey:JSONKey { get } } extension Int: JSONSubscriptType { - public var jsonKey:JSONSubscriptKey { - return JSONSubscriptKey.Index(self) + public var jsonKey:JSONKey { + return JSONKey.Index(self) } } extension String: JSONSubscriptType { - public var jsonKey:JSONSubscriptKey { - return JSONSubscriptKey.Key(self) + public var jsonKey:JSONKey { + return JSONKey.Key(self) } } From df8ecbcdae0b81a78bf173890fd078adc0465d8f Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 21:36:17 -0500 Subject: [PATCH 192/470] Add Playground File --- Example/Example.xcodeproj/project.pbxproj | 47 +++++++++++++++++++ Example/Playground.playground/Contents.swift | 3 ++ .../contents.xcplayground | 4 ++ .../Playground.playground/timeline.xctimeline | 6 +++ 4 files changed, 60 insertions(+) create mode 100644 Example/Playground.playground/Contents.swift create mode 100644 Example/Playground.playground/contents.xcplayground create mode 100644 Example/Playground.playground/timeline.xctimeline diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 1095dcdb..cd37ea68 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -16,6 +16,27 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 04294C581BE5A9DE00D0397E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = E4D7CCE81B9465A700EE7221; + remoteInfo = "SwiftyJSON watchOS"; + }; + 04294C5A1BE5A9DE00D0397E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = 7236B4F61BAC14150020529B; + remoteInfo = "SwiftyJSON tvOS"; + }; + 04294C5C1BE5A9DE00D0397E /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; + proxyType = 2; + remoteGlobalIDString = A8580F741BCF5C5B00DA927B; + remoteInfo = "SwiftyJSON tvOS Tests"; + }; A8BF45AA1B871E100066C032 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; @@ -60,6 +81,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 04294C501BE5A9DE00D0397E /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = ""; }; A82A1C1919D926B8009A653D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; A82A1C1D19D926B8009A653D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A82A1C1E19D926B8009A653D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -85,6 +107,7 @@ A82A1C1019D926B8009A653D = { isa = PBXGroup; children = ( + 04294C501BE5A9DE00D0397E /* Playground.playground */, A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */, A82A1C1B19D926B8009A653D /* Example */, A82A1C1A19D926B8009A653D /* Products */, @@ -128,6 +151,9 @@ A8BF45AD1B871E100066C032 /* SwiftyJSON iOS Tests.xctest */, A8BF45AF1B871E100066C032 /* SwiftyJSON.framework */, A8BF45B11B871E100066C032 /* SwiftyJSON OSX Tests.xctest */, + 04294C591BE5A9DE00D0397E /* SwiftyJSON.framework */, + 04294C5B1BE5A9DE00D0397E /* SwiftyJSON.framework */, + 04294C5D1BE5A9DE00D0397E /* SwiftyJSON tvOS Tests.xctest */, ); name = Products; sourceTree = ""; @@ -193,6 +219,27 @@ /* End PBXProject section */ /* Begin PBXReferenceProxy section */ + 04294C591BE5A9DE00D0397E /* SwiftyJSON.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftyJSON.framework; + remoteRef = 04294C581BE5A9DE00D0397E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 04294C5B1BE5A9DE00D0397E /* SwiftyJSON.framework */ = { + isa = PBXReferenceProxy; + fileType = wrapper.framework; + path = SwiftyJSON.framework; + remoteRef = 04294C5A1BE5A9DE00D0397E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; + 04294C5D1BE5A9DE00D0397E /* SwiftyJSON tvOS Tests.xctest */ = { + isa = PBXReferenceProxy; + fileType = wrapper.cfbundle; + path = "SwiftyJSON tvOS Tests.xctest"; + remoteRef = 04294C5C1BE5A9DE00D0397E /* PBXContainerItemProxy */; + sourceTree = BUILT_PRODUCTS_DIR; + }; A8BF45AB1B871E100066C032 /* SwiftyJSON.framework */ = { isa = PBXReferenceProxy; fileType = wrapper.framework; diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift new file mode 100644 index 00000000..33ae9484 --- /dev/null +++ b/Example/Playground.playground/Contents.swift @@ -0,0 +1,3 @@ +//: Playground - noun: a place where people can play + +import SwiftyJSON diff --git a/Example/Playground.playground/contents.xcplayground b/Example/Playground.playground/contents.xcplayground new file mode 100644 index 00000000..5da2641c --- /dev/null +++ b/Example/Playground.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Example/Playground.playground/timeline.xctimeline b/Example/Playground.playground/timeline.xctimeline new file mode 100644 index 00000000..bf468afe --- /dev/null +++ b/Example/Playground.playground/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + + From 07afaaa9ad69bba83d502e2be85c6ff590584730 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sat, 31 Oct 2015 22:01:18 -0500 Subject: [PATCH 193/470] Fix Example Target Build --- Example/Example/ViewController.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index ea5e720f..a0e13463 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -52,7 +52,7 @@ class ViewController: UITableViewController { cell.textLabel?.text = "\(row)" cell.detailTextLabel?.text = self.json.arrayValue.description case .Dictionary: - let key: AnyObject = self.json.dictionaryValue.keys.array[row] + let key: AnyObject = Array(self.json.dictionaryValue.keys)[row] let value = self.json[key as! String] cell.textLabel?.text = "\(key)" cell.detailTextLabel?.text = value.description @@ -83,7 +83,7 @@ class ViewController: UITableViewController { case .Array: nextJson = self.json[row] case .Dictionary where row < self.json.dictionaryValue.count: - let key = self.json.dictionaryValue.keys.array[row] + let key = Array(self.json.dictionaryValue.keys)[row] if let value = self.json.dictionary?[key] { nextJson = value } From 4c45c92a04785be3191ae2572b07599c16b23723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=B8vring?= Date: Tue, 10 Nov 2015 18:35:50 +0100 Subject: [PATCH 194/470] Sets UIRequiredDeviceCapabilities for tvOS target --- Source/Info-tvOS.plist | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Info-tvOS.plist b/Source/Info-tvOS.plist index 78122054..8d348099 100644 --- a/Source/Info-tvOS.plist +++ b/Source/Info-tvOS.plist @@ -22,5 +22,9 @@ ${CURRENT_PROJECT_VERSION} NSPrincipalClass + UIRequiredDeviceCapabilities + + arm64 + From d92b1bde563cfe707296b2b7b70a00ef69acf04a Mon Sep 17 00:00:00 2001 From: Erez Rabih Date: Wed, 11 Nov 2015 16:37:57 +0200 Subject: [PATCH 195/470] fixed Alamofire & SwiftJSON integration example --- README.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9fe68f1e..a897202e 100644 --- a/README.md +++ b/README.md @@ -362,16 +362,13 @@ json[path] = "that" SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: ```swift -Alamofire.request(.GET, url, parameters: parameters) - .responseJSON { (req, res, json, error) in - if(error != nil) { - NSLog("Error: \(error)") - print(req) - print(res) +Alamofire.request(.GET, url).validate().responseJSON { response in + switch response.result { + case .Success: + let json = JSON(response.result.value!) + print("JSON: \(json)") + case .Failure(let error): + print(error) } - else { - NSLog("Success: \(url)") - var json = JSON(json!) - } - } +} ``` From bc6223c815ee2b764020b4d7d5cd5c22678cc761 Mon Sep 17 00:00:00 2001 From: Erez Rabih Date: Thu, 12 Nov 2015 14:43:20 +0200 Subject: [PATCH 196/470] use safe unwrapping for result value --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a897202e..c0846f90 100644 --- a/README.md +++ b/README.md @@ -365,8 +365,10 @@ SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: Alamofire.request(.GET, url).validate().responseJSON { response in switch response.result { case .Success: - let json = JSON(response.result.value!) - print("JSON: \(json)") + if let value = response.result.value { + let json = JSON(value) + print("JSON: \(json)") + } case .Failure(let error): print(error) } From 88e5723b7b5fbe2f2fa98bf597ecae81afd38ee0 Mon Sep 17 00:00:00 2001 From: Christian Steffens Date: Wed, 18 Nov 2015 10:33:32 +0100 Subject: [PATCH 197/470] Deleted Framework search paths for target OSX Test --- SwiftyJSON.xcodeproj/project.pbxproj | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 3d4dad70..ad5f064a 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -888,10 +888,7 @@ buildSettings = { CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = ""; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -911,10 +908,7 @@ CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - FRAMEWORK_SEARCH_PATHS = ( - "$(DEVELOPER_FRAMEWORKS_DIR)", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = ""; INFOPLIST_FILE = "Tests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; From 48939eefea178480e42acb514c17b895f3666b35 Mon Sep 17 00:00:00 2001 From: Yozone Wang Date: Fri, 20 Nov 2015 15:31:01 +0800 Subject: [PATCH 198/470] Correct JSON's type specification URL Wrong JSON's type specification URL, it should be http://www.json.org. --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f0397a45..6e21c451 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -39,7 +39,7 @@ public let ErrorInvalidJSON: Int! = 490 /** JSON's type definitions. -See http://tools.ietf.org/html/rfc7231#section-4.3 +See http://www.json.org */ public enum Type :Int{ From bfbc948c6ec4f04556e32ab8265a784ca0bd0e17 Mon Sep 17 00:00:00 2001 From: Brian Capps Date: Tue, 24 Nov 2015 12:09:28 -0500 Subject: [PATCH 199/470] Remove force-unwrapped indicator from constants --- Source/SwiftyJSON.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f0397a45..097ba698 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -25,14 +25,14 @@ import Foundation // MARK: - Error ///Error domain -public let ErrorDomain: String! = "SwiftyJSONErrorDomain" +public let ErrorDomain: String = "SwiftyJSONErrorDomain" ///Error code -public let ErrorUnsupportedType: Int! = 999 -public let ErrorIndexOutOfBounds: Int! = 900 -public let ErrorWrongType: Int! = 901 -public let ErrorNotExist: Int! = 500 -public let ErrorInvalidJSON: Int! = 490 +public let ErrorUnsupportedType: Int = 999 +public let ErrorIndexOutOfBounds: Int = 900 +public let ErrorWrongType: Int = 901 +public let ErrorNotExist: Int = 500 +public let ErrorInvalidJSON: Int = 490 // MARK: - JSON Type From 0f88e655bbf622de2d1359cf92f708c33e0f4ca8 Mon Sep 17 00:00:00 2001 From: Brian Capps Date: Tue, 24 Nov 2015 12:13:10 -0500 Subject: [PATCH 200/470] Uses optional binding to remove force unwrapping --- Source/SwiftyJSON.swift | 56 ++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 097ba698..28ca430c 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -770,8 +770,8 @@ extension JSON: Swift.BooleanType { } } set { - if newValue != nil { - self.object = NSNumber(bool: newValue!) + if let newValue = newValue { + self.object = NSNumber(bool: newValue) } else { self.object = NSNull() } @@ -809,8 +809,8 @@ extension JSON { } } set { - if newValue != nil { - self.object = NSString(string:newValue!) + if let newValue = newValue { + self.object = NSString(string:newValue) } else { self.object = NSNull() } @@ -933,8 +933,8 @@ extension JSON { return self.number?.doubleValue } set { - if newValue != nil { - self.object = NSNumber(double: newValue!) + if let newValue = newValue { + self.object = NSNumber(double: newValue) } else { self.object = NSNull() } @@ -955,8 +955,8 @@ extension JSON { return self.number?.floatValue } set { - if newValue != nil { - self.object = NSNumber(float: newValue!) + if let newValue = newValue { + self.object = NSNumber(float: newValue) } else { self.object = NSNull() } @@ -977,8 +977,8 @@ extension JSON { return self.number?.longValue } set { - if newValue != nil { - self.object = NSNumber(integer: newValue!) + if let newValue = newValue { + self.object = NSNumber(integer: newValue) } else { self.object = NSNull() } @@ -999,8 +999,8 @@ extension JSON { return self.number?.unsignedLongValue } set { - if newValue != nil { - self.object = NSNumber(unsignedLong: newValue!) + if let newValue = newValue { + self.object = NSNumber(unsignedLong: newValue) } else { self.object = NSNull() } @@ -1021,8 +1021,8 @@ extension JSON { return self.number?.charValue } set { - if newValue != nil { - self.object = NSNumber(char: newValue!) + if let newValue = newValue { + self.object = NSNumber(char: newValue) } else { self.object = NSNull() } @@ -1043,8 +1043,8 @@ extension JSON { return self.number?.unsignedCharValue } set { - if newValue != nil { - self.object = NSNumber(unsignedChar: newValue!) + if let newValue = newValue { + self.object = NSNumber(unsignedChar: newValue) } else { self.object = NSNull() } @@ -1065,8 +1065,8 @@ extension JSON { return self.number?.shortValue } set { - if newValue != nil { - self.object = NSNumber(short: newValue!) + if let newValue = newValue { + self.object = NSNumber(short: newValue) } else { self.object = NSNull() } @@ -1087,8 +1087,8 @@ extension JSON { return self.number?.unsignedShortValue } set { - if newValue != nil { - self.object = NSNumber(unsignedShort: newValue!) + if let newValue = newValue { + self.object = NSNumber(unsignedShort: newValue) } else { self.object = NSNull() } @@ -1109,8 +1109,8 @@ extension JSON { return self.number?.intValue } set { - if newValue != nil { - self.object = NSNumber(int: newValue!) + if let newValue = newValue { + self.object = NSNumber(int: newValue) } else { self.object = NSNull() } @@ -1131,8 +1131,8 @@ extension JSON { return self.number?.unsignedIntValue } set { - if newValue != nil { - self.object = NSNumber(unsignedInt: newValue!) + if let newValue = newValue { + self.object = NSNumber(unsignedInt: newValue) } else { self.object = NSNull() } @@ -1153,8 +1153,8 @@ extension JSON { return self.number?.longLongValue } set { - if newValue != nil { - self.object = NSNumber(longLong: newValue!) + if let newValue = newValue { + self.object = NSNumber(longLong: newValue) } else { self.object = NSNull() } @@ -1175,8 +1175,8 @@ extension JSON { return self.number?.unsignedLongLongValue } set { - if newValue != nil { - self.object = NSNumber(unsignedLongLong: newValue!) + if let newValue = newValue { + self.object = NSNumber(unsignedLongLong: newValue) } else { self.object = NSNull() } From d4bf9f1d9a34d0e1db8c0f734638bafe503192d0 Mon Sep 17 00:00:00 2001 From: Brian Capps Date: Tue, 24 Nov 2015 12:16:40 -0500 Subject: [PATCH 201/470] Utilizes existing optional binding to stop force unwrapping --- Source/SwiftyJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 28ca430c..0c420aed 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -384,13 +384,13 @@ public struct JSONGenerator : GeneratorType { public mutating func next() -> JSONGenerator.Element? { switch self.type { case .Array: - if let o = self.arrayGenerate!.next() { + if let o = self.arrayGenerate?.next() { return (String(self.arrayIndex++), JSON(o)) } else { return nil } case .Dictionary: - if let (k, v): (String, AnyObject) = self.dictionayGenerate!.next() { + if let (k, v): (String, AnyObject) = self.dictionayGenerate?.next() { return (k, JSON(v)) } else { return nil From ea2696e459093c31e12ee13f81b20b10068004a2 Mon Sep 17 00:00:00 2001 From: Brian Capps Date: Tue, 24 Nov 2015 12:19:52 -0500 Subject: [PATCH 202/470] Nil coalesce instead of force unwrap --- Source/SwiftyJSON.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 0c420aed..9fd3496d 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -822,11 +822,11 @@ extension JSON { get { switch self.type { case .String: - return self.object as! String + return self.object as? String ?? "" case .Number: return self.object.stringValue case .Bool: - return (self.object as! Bool).description + return String(self.object as? Bool) default: return "" } @@ -866,7 +866,7 @@ extension JSON { } return decimal case .Number, .Bool: - return self.object as! NSNumber + return self.object as? NSNumber ?? NSNumber(int: 0) default: return NSNumber(double: 0.0) } From 9181c7c6d3da87890f23e1a7b01f5fed175241b8 Mon Sep 17 00:00:00 2001 From: Brian Capps Date: Tue, 24 Nov 2015 12:29:10 -0500 Subject: [PATCH 203/470] fixes Bool case to return expected value --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 9fd3496d..290388ba 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -826,7 +826,7 @@ extension JSON { case .Number: return self.object.stringValue case .Bool: - return String(self.object as? Bool) + return (self.object as? Bool).map { String($0) } ?? "" default: return "" } From b3257946ce59e18b52b4fd02a72af1624e0b0e34 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Tue, 24 Nov 2015 15:37:41 -0600 Subject: [PATCH 204/470] Keep NSNumber Operator Internal --- Source/SwiftyJSON.swift | 12 ++++++------ Tests/BaseTests.swift | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index c5ead0e9..b05a5aec 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1301,7 +1301,7 @@ extension NSNumber { } } -public func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { +func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1312,11 +1312,11 @@ public func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -public func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { +func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { return !(lhs == rhs) } -public func <(lhs: NSNumber, rhs: NSNumber) -> Bool { +func <(lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): @@ -1328,7 +1328,7 @@ public func <(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -public func >(lhs: NSNumber, rhs: NSNumber) -> Bool { +func >(lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): @@ -1340,7 +1340,7 @@ public func >(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { +func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): @@ -1352,7 +1352,7 @@ public func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -public func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { +func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 1ce3d28d..7b5b5dcd 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -21,7 +21,7 @@ // THE SOFTWARE. import XCTest -import SwiftyJSON +@testable import SwiftyJSON class BaseTests: XCTestCase { From ae73ec1373e2bab8904c77205f12e44afabf2cfc Mon Sep 17 00:00:00 2001 From: Diogo Guimaraes Date: Wed, 25 Nov 2015 15:13:49 +0000 Subject: [PATCH 205/470] Update codesign identity --- SwiftyJSON.xcodeproj/project.pbxproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index ad5f064a..8e95c29c 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -727,7 +727,8 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -747,7 +748,8 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - CODE_SIGN_IDENTITY = "iPhone Developer"; + CODE_SIGN_IDENTITY = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; From 298feb497e47422b6843f2308f370c5d83110963 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 26 Nov 2015 05:37:35 -0600 Subject: [PATCH 206/470] Add Parse as JSON.parse --- Source/SwiftyJSON.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index b05a5aec..fa8635eb 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -77,6 +77,17 @@ public struct JSON { } } + /** + Create a JSON from JSON string + - parameter string: Normal json string like '{"a":"b"}' + + - returns: The created JSON + */ + public static func parse(string:String) -> JSON { + return string.dataUsingEncoding(NSUTF8StringEncoding) + .flatMap({JSON(data: $0)}) ?? JSON(NSNull()) + } + /** Creates a JSON using the object. From 4d05047af9d80284bcff31883e4d33f32e2f1c03 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 3 Dec 2015 08:58:31 +0800 Subject: [PATCH 207/470] update pod specs --- SwiftyJSON.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 6a357e2b..ee48960c 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.3.1" + s.version = "2.3.2" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -11,6 +11,6 @@ Pod::Spec.new do |s| s.ios.deployment_target = "8.0" s.watchos.deployment_target = "2.0" s.tvos.deployment_target = "9.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.1"} + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.2"} s.source_files = "Source/*.swift" end From a1356035d2de68c155d05521292f0609ef7e69bb Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Fri, 4 Dec 2015 21:33:51 +0800 Subject: [PATCH 208/470] add Package.swift --- Package.swift | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..e69de29b From 8e618c8baf6323a5079c6549bb38d48357b31630 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Fri, 4 Dec 2015 21:55:50 +0800 Subject: [PATCH 209/470] Update README.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index c0846f90..ec3af393 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,22 @@ You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJ github "SwiftyJSON/SwiftyJSON" ``` +####Swift Package Manager +You can use [The Swift Package Manager](https://swift.org/package-manager) to install `SwiftyJSON` by adding the proper description to your `Package.swift` file: +```swift +import PackageDescription + +let package = Package( + name: "YOUR_PROJECT_NAME", + targets: [], + dependencies: [ + .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", versions: "2.3.3" ..< Version.max) + ] +) +``` + +Note that the [Swift Package Manager](https://swift.org/package-manager) is still in early design and development, for more infomation checkout it's [GitHub Page](https://github.com/apple/swift-package-manager) + ####Manually (iOS 7+, OS X 10.9+) To use this library in your project manually you may: From 1ddae138ebf0b9bacb2550bd8c14c13b03f96ea3 Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Tue, 8 Dec 2015 18:02:52 -0800 Subject: [PATCH 210/470] Use minimumCapacity parameter to optimize dictionary creations --- Source/SwiftyJSON.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fa8635eb..472eb1f0 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -118,7 +118,7 @@ public struct JSON { - returns: The created JSON */ public init(_ jsonDictionary:[String: JSON]) { - var dictionary = [String: AnyObject]() + var dictionary = [String: AnyObject](minimumCapacity: jsonDictionary.count) for (key, json) in jsonDictionary { dictionary[key] = json.object } @@ -596,7 +596,7 @@ extension JSON: Swift.FloatLiteralConvertible { extension JSON: Swift.DictionaryLiteralConvertible { public init(dictionaryLiteral elements: (String, AnyObject)...) { - self.init(elements.reduce([String : AnyObject]()){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in + self.init(elements.reduce([String : AnyObject](minimumCapacity: elements.count)){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in var d = dictionary d[element.0] = element.1 return d @@ -731,7 +731,7 @@ extension JSON { //Optional [String : JSON] public var dictionary: [String : JSON]? { if self.type == .Dictionary { - return self.rawDictionary.reduce([String : JSON]()) { (dictionary: [String : JSON], element: (String, AnyObject)) -> [String : JSON] in + return self.rawDictionary.reduce([String : JSON](minimumCapacity: count)) { (dictionary: [String : JSON], element: (String, AnyObject)) -> [String : JSON] in var d = dictionary d[element.0] = JSON(element.1) return d From 60034664e8ca3d9174efda1aa93a2c07ae45292a Mon Sep 17 00:00:00 2001 From: Alexander Ney Date: Wed, 9 Dec 2015 14:42:27 +0000 Subject: [PATCH 211/470] set the watch os deployment target to watchOs 2.0 - otherwise it would have used always the most current one with the result that the lib is not usable with apps deploying on watchOS 2.0 --- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 8e95c29c..442f9818 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -970,6 +970,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 2.0; }; name = Debug; }; @@ -992,6 +993,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; TARGETED_DEVICE_FAMILY = 4; + WATCHOS_DEPLOYMENT_TARGET = 2.0; }; name = Release; }; From 7620d5bc0fb4ad21c7dccbe6661b61a5f27b0545 Mon Sep 17 00:00:00 2001 From: Fernando Paredes Date: Mon, 21 Dec 2015 08:48:44 -0800 Subject: [PATCH 212/470] Programmatically set current tag --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index ee48960c..1a9d29dd 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -11,6 +11,6 @@ Pod::Spec.new do |s| s.ios.deployment_target = "8.0" s.watchos.deployment_target = "2.0" s.tvos.deployment_target = "9.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "2.3.2"} + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => s.version } s.source_files = "Source/*.swift" end From 5f59648a6e9356b26c5cb698ab924fa7d750b6c9 Mon Sep 17 00:00:00 2001 From: Pinglin Tang Date: Tue, 29 Dec 2015 18:22:53 +0800 Subject: [PATCH 213/470] Update optimization level to "-Ofast" --- SwiftyJSON.xcodeproj/project.pbxproj | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 8e95c29c..12728383 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -658,7 +658,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; - GCC_OPTIMIZATION_LEVEL = 0; + GCC_OPTIMIZATION_LEVEL = fast; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -675,7 +675,7 @@ METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; - SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -705,6 +705,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_OPTIMIZATION_LEVEL = fast; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -715,6 +716,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; From baf8c18655317439bf8d5e63d439c8fe40644112 Mon Sep 17 00:00:00 2001 From: Saagar Jha Date: Tue, 5 Jan 2016 17:06:56 -0800 Subject: [PATCH 214/470] Changed "Mac OS X" to "OS X" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OS X versions after OS X 10.8 Mountain dropped the “Mac” part of their name. Now matches rest of README as well. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ec3af393..2d854b92 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { ## Requirements -- iOS 7.0+ / Mac OS X 10.9+ +- iOS 7.0+ / OS X 10.9+ - Xcode 7 ##Integration From cbeddbc246ea18cb3e893452cd03085f830d4658 Mon Sep 17 00:00:00 2001 From: Danut Pralea Date: Tue, 12 Jan 2016 23:32:18 +0200 Subject: [PATCH 215/470] Update README.md typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d854b92..75d51850 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,7 @@ let package = Package( ) ``` -Note that the [Swift Package Manager](https://swift.org/package-manager) is still in early design and development, for more infomation checkout it's [GitHub Page](https://github.com/apple/swift-package-manager) +Note that the [Swift Package Manager](https://swift.org/package-manager) is still in early design and development, for more infomation checkout its [GitHub Page](https://github.com/apple/swift-package-manager) ####Manually (iOS 7+, OS X 10.9+) From 64b832c7f5f59a2ad132f738c332dbe53f766c69 Mon Sep 17 00:00:00 2001 From: Vijaya Prakash Kandel Date: Thu, 28 Jan 2016 16:45:37 +0100 Subject: [PATCH 216/470] Changed from .empty to .isEmpty The comment had array.empty which but it was implemented by array.isEmpty and similar for dictionary. Although the intent is clear, the comment suggested it was the code portion and it was mismatching. Thus, i think its necessary. --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fa8635eb..21b39d67 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -235,7 +235,7 @@ extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { } } - /// If `type` is `.Array` or `.Dictionary`, return `array.empty` or `dictonary.empty` otherwise return `true`. + /// If `type` is `.Array` or `.Dictionary`, return `array.isEmpty` or `dictonary.isEmpty` otherwise return `true`. public var isEmpty: Bool { get { switch self.type { From 49f588e634c934bad0439aa5a0a13eaea8e931fc Mon Sep 17 00:00:00 2001 From: Vijaya Prakash Kandel Date: Sun, 31 Jan 2016 13:33:57 +0100 Subject: [PATCH 217/470] Which's -> whose and typo fix in comments - `which's` doesnot seem to make lot of sense so i think its better off by using `whose` - there was no space between `structuresby` which is changed to `structures by` --- Source/SwiftyJSON.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fa8635eb..126563d9 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -440,7 +440,7 @@ extension String: JSONSubscriptType { extension JSON { - /// If `type` is `.Array`, return json which's object is `array[index]`, otherwise return null json with error. + /// If `type` is `.Array`, return json whose object is `array[index]`, otherwise return null json with error. private subscript(index index: Int) -> JSON { get { if self.type != .Array { @@ -464,7 +464,7 @@ extension JSON { } } - /// If `type` is `.Dictionary`, return json which's object is `dictionary[key]` , otherwise return null json with error. + /// If `type` is `.Dictionary`, return json whose object is `dictionary[key]` , otherwise return null json with error. private subscript(key key: String) -> JSON { get { var r = JSON.null @@ -535,7 +535,7 @@ extension JSON { } /** - Find a json in the complex data structuresby using the Int/String's array. + Find a json in the complex data structures by using the Int/String's array. - parameter path: The target json's path. Example: From 9966411ad58c17aac831b2af9ea9035b461e1743 Mon Sep 17 00:00:00 2001 From: ReadmeCritic Date: Fri, 12 Feb 2016 19:33:44 -0800 Subject: [PATCH 218/470] Correct the spelling of CocoaPods in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d51850..e616d7b0 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { ##Integration ####CocoaPods (iOS 8+, OS X 10.9+) -You can use [Cocoapods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: +You can use [CocoaPods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: ```ruby platform :ios, '8.0' use_frameworks! From 5fc4545c7a5d1fd4a2b3d04964f1bc593c356676 Mon Sep 17 00:00:00 2001 From: Craig Siemens Date: Wed, 17 Feb 2016 09:48:30 -0700 Subject: [PATCH 219/470] Rename isExists to exists. Fixes #448 --- Source/SwiftyJSON.swift | 2 +- Tests/BaseTests.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fa8635eb..15a1c3f8 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -904,7 +904,7 @@ extension JSON { self.object = NSNull() } } - public func isExists() -> Bool{ + public func exists() -> Bool{ if let errorValue = error where errorValue.code == ErrorNotExist{ return false } diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 7b5b5dcd..a5d52f42 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -229,8 +229,8 @@ class BaseTests: XCTestCase { func testExistance() { let dictionary = ["number":1111] let json = JSON(dictionary) - XCTAssertFalse(json["unspecifiedValue"].isExists()) - XCTAssertTrue(json["number"].isExists()) + XCTAssertFalse(json["unspecifiedValue"].exists()) + XCTAssertTrue(json["number"].exists()) } func testErrorHandle() { From f0bbe53d891cfcb781d4e73f87b35a4b9c045b53 Mon Sep 17 00:00:00 2001 From: Frank Date: Thu, 18 Feb 2016 17:45:34 -0500 Subject: [PATCH 220/470] README typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d51850..e62bd678 100644 --- a/README.md +++ b/README.md @@ -315,7 +315,7 @@ if let string = json.rawString() { //Do something you want } ``` -####Existance +####Existence ```swift //shows you whether value specified in JSON or not if json["name"].isExists() From 52cfeb54e05233e7f2b697a17a9b27e2fde524ff Mon Sep 17 00:00:00 2001 From: Victor Sigler Date: Mon, 29 Feb 2016 19:31:27 -0500 Subject: [PATCH 221/470] Update Alamofire code Update the Alamofire interaction with the new code for Alamofire 3, that in the `.Success` is returned its associated value as with the `error` in the case of `.Failure`. --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 75d51850..39e2c80a 100644 --- a/README.md +++ b/README.md @@ -380,11 +380,10 @@ SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: ```swift Alamofire.request(.GET, url).validate().responseJSON { response in switch response.result { - case .Success: - if let value = response.result.value { - let json = JSON(value) - print("JSON: \(json)") - } + case .Success(let value): + let json = JSON(value) + print("JSON: \(json)") + case .Failure(let error): print(error) } From d0ea821595e20874dcda32300155c3ec251cee59 Mon Sep 17 00:00:00 2001 From: Victor Sigler Date: Mon, 29 Feb 2016 19:32:39 -0500 Subject: [PATCH 222/470] Remove blank space --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 39e2c80a..113a65b2 100644 --- a/README.md +++ b/README.md @@ -383,7 +383,6 @@ Alamofire.request(.GET, url).validate().responseJSON { response in case .Success(let value): let json = JSON(value) print("JSON: \(json)") - case .Failure(let error): print(error) } From 20ee3ed7bd9e49c250d91f402f01fe87caeacf2a Mon Sep 17 00:00:00 2001 From: "Glenn R. Fisher" Date: Tue, 1 Mar 2016 11:23:14 -0600 Subject: [PATCH 223/470] Replace ++ with += The increment (++) and decrement (--) operators will be deprecated with Swift 3. For more information, see proposal SE-0004: https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md --- Source/SwiftyJSON.swift | 4 +++- Tests/SequenceTypeTests.swift | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fa8635eb..418531f1 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -396,7 +396,9 @@ public struct JSONGenerator : GeneratorType { switch self.type { case .Array: if let o = self.arrayGenerate?.next() { - return (String(self.arrayIndex++), JSON(o)) + let i = self.arrayIndex + self.arrayIndex += 1 + return (String(i), JSON(o)) } else { return nil } diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index 6711a221..b3ea4b77 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -56,7 +56,7 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(sub, json[index]) XCTAssertEqual(i, "\(index)") array.append(sub.number!) - index++ + index += 1 } XCTAssertEqual(index, 5) XCTAssertEqual(array, [1,2.0,3.3,123456789,987654321.123456789]) @@ -72,7 +72,7 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(sub, json[index]) XCTAssertEqual(i, "\(index)") array.append(sub.bool!) - index++ + index += 1 } XCTAssertEqual(index, 5) XCTAssertEqual(array, [true, false, false, true, true]) @@ -88,7 +88,7 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(sub, json[index]) XCTAssertEqual(i, "\(index)") array.append(sub.string!) - index++ + index += 1 } XCTAssertEqual(index, 3) XCTAssertEqual(array, ["aoo","bpp","zoo"]) @@ -104,7 +104,7 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(sub, json[index]) XCTAssertEqual(i, "\(index)") array.append(sub.object) - index++ + index += 1 } XCTAssertEqual(index, 4) XCTAssertEqual(array[0] as? String, "aoo") @@ -121,7 +121,7 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(sub, json[index]) XCTAssertEqual(i, "\(index)") array.append(sub.object) - index++ + index += 1 } XCTAssertEqual(index, 3) XCTAssertEqual((array[0] as! [String : Int])["1"]!, 1) @@ -140,7 +140,7 @@ class SequenceTypeTests: XCTestCase { for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.number! - index++ + index += 1 } XCTAssertEqual(index, 2) @@ -157,7 +157,7 @@ class SequenceTypeTests: XCTestCase { for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.bool! - index++ + index += 1 } XCTAssertEqual(index, 5) @@ -174,7 +174,7 @@ class SequenceTypeTests: XCTestCase { for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.string! - index++ + index += 1 } XCTAssertEqual(index, 3) @@ -191,7 +191,7 @@ class SequenceTypeTests: XCTestCase { for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.object - index++ + index += 1 } XCTAssertEqual(index, 4) @@ -210,7 +210,7 @@ class SequenceTypeTests: XCTestCase { for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.object - index++ + index += 1 } XCTAssertEqual(index, 3) From b3972382d06459a5ae1dea5e6672a7bdb96094f6 Mon Sep 17 00:00:00 2001 From: Karthik Gollapudi Date: Sun, 20 Mar 2016 17:49:53 -0700 Subject: [PATCH 224/470] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d51850..e62bd678 100644 --- a/README.md +++ b/README.md @@ -315,7 +315,7 @@ if let string = json.rawString() { //Do something you want } ``` -####Existance +####Existence ```swift //shows you whether value specified in JSON or not if json["name"].isExists() From 71a006fef39b5a42ab8658542ccf0d0752f734b6 Mon Sep 17 00:00:00 2001 From: Shantanu Desai Date: Sun, 27 Mar 2016 13:58:35 +0530 Subject: [PATCH 225/470] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d51850..ec44965d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #SwiftyJSON [中文介绍](http://tangplin.github.io/swiftyjson/) -[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) +[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) SwiftyJSON makes it easy to deal with JSON data in Swift. From a121ac6ef15336a71b792f0998d275be32e18c2e Mon Sep 17 00:00:00 2001 From: Grant Kemp Date: Sat, 16 Apr 2016 19:53:41 +0100 Subject: [PATCH 226/470] errorFix: incorrect method specified in Readme. Fixed to ensure new users are not confused. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d51850..ed0513fa 100644 --- a/README.md +++ b/README.md @@ -318,7 +318,7 @@ if let string = json.rawString() { ####Existance ```swift //shows you whether value specified in JSON or not -if json["name"].isExists() +if json["name"].exists() ``` ####Literal convertibles From a57e05c465cf9bb52316bfbdb4c6490847aaee2b Mon Sep 17 00:00:00 2001 From: Grant Kemp Date: Sat, 16 Apr 2016 19:54:08 +0100 Subject: [PATCH 227/470] admin : fixed some typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ed0513fa..63566e97 100644 --- a/README.md +++ b/README.md @@ -275,7 +275,7 @@ let id: Int = json["id"].intValue let name: String = json["name"].stringValue ``` ```swift -//If not a Array or nil, return [] +//If not an Array or nil, return [] let list: Array = json["list"].arrayValue ``` ```swift @@ -315,7 +315,7 @@ if let string = json.rawString() { //Do something you want } ``` -####Existance +####Existence ```swift //shows you whether value specified in JSON or not if json["name"].exists() From 6882c23c19d8c36811e9424daf458877032f4b81 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Tue, 14 Jun 2016 16:12:31 -0700 Subject: [PATCH 228/470] Beta support for swift3. --- Source/SwiftyJSON.swift | 556 +++++++----------- SwiftyJSON.xcodeproj/project.pbxproj | 14 +- .../xcschemes/SwiftyJSON OSX.xcscheme | 10 +- .../xcschemes/SwiftyJSON iOS.xcscheme | 10 +- .../xcschemes/SwiftyJSON tvOS.xcscheme | 4 +- .../xcschemes/SwiftyJSON watchOS.xcscheme | 2 +- Tests/BaseTests.swift | 70 +-- Tests/ComparableTests.swift | 24 +- Tests/NumberTests.swift | 208 +++---- Tests/PerformanceTests.swift | 16 +- Tests/PrintableTests.swift | 20 +- Tests/RawRepresentableTests.swift | 6 +- Tests/RawTests.swift | 12 +- Tests/SequenceTypeTests.swift | 6 +- Tests/StringTests.swift | 6 +- Tests/SubscriptTests.swift | 4 +- 16 files changed, 411 insertions(+), 557 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 8a5b5d67..b639ac00 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -43,13 +43,13 @@ See http://www.json.org */ public enum Type :Int{ - case Number - case String - case Bool - case Array - case Dictionary - case Null - case Unknown + case number + case string + case bool + case array + case dictionary + case null + case unknown } // MARK: - JSON Base @@ -65,13 +65,13 @@ public struct JSON { - returns: The created JSON */ - public init(data:NSData, options opt: NSJSONReadingOptions = .AllowFragments, error: NSErrorPointer = nil) { + public init(data:Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer? = nil) { do { - let object: AnyObject = try NSJSONSerialization.JSONObjectWithData(data, options: opt) + let object: AnyObject = try JSONSerialization.jsonObject(with: data, options: opt) self.init(object) } catch let aError as NSError { if error != nil { - error.memory = aError + error??.pointee = aError } self.init(NSNull()) } @@ -83,8 +83,8 @@ public struct JSON { - returns: The created JSON */ - public static func parse(string:String) -> JSON { - return string.dataUsingEncoding(NSUTF8StringEncoding) + public static func parse(_ string:String) -> JSON { + return string.data(using: String.Encoding.utf8) .flatMap({JSON(data: $0)}) ?? JSON(NSNull()) } @@ -132,7 +132,7 @@ public struct JSON { private var rawNumber: NSNumber = 0 private var rawNull: NSNull = NSNull() /// Private type - private var _type: Type = .Null + private var _type: Type = .null /// prviate error private var _error: NSError? = nil @@ -140,15 +140,15 @@ public struct JSON { public var object: AnyObject { get { switch self.type { - case .Array: + case .array: return self.rawArray - case .Dictionary: + case .dictionary: return self.rawDictionary - case .String: + case .string: return self.rawString - case .Number: + case .number: return self.rawNumber - case .Bool: + case .bool: return self.rawNumber default: return self.rawNull @@ -159,24 +159,24 @@ public struct JSON { switch newValue { case let number as NSNumber: if number.isBool { - _type = .Bool + _type = .bool } else { - _type = .Number + _type = .number } self.rawNumber = number case let string as String: - _type = .String + _type = .string self.rawString = string case _ as NSNull: - _type = .Null + _type = .null case let array as [AnyObject]: - _type = .Array + _type = .array self.rawArray = array case let dictionary as [String : AnyObject]: - _type = .Dictionary + _type = .dictionary self.rawDictionary = dictionary default: - _type = .Unknown + _type = .unknown _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) } } @@ -189,229 +189,90 @@ public struct JSON { public var error: NSError? { get { return self._error } } /// The static null json - @available(*, unavailable, renamed="null") + @available(*, unavailable, renamed:"null") public static var nullJSON: JSON { get { return null } } public static var null: JSON { get { return JSON(NSNull()) } } } -// MARK: - CollectionType, SequenceType, Indexable -extension JSON : Swift.CollectionType, Swift.SequenceType, Swift.Indexable { - - public typealias Generator = JSONGenerator - - public typealias Index = JSONIndex - - public var startIndex: JSON.Index { - switch self.type { - case .Array: - return JSONIndex(arrayIndex: self.rawArray.startIndex) - case .Dictionary: - return JSONIndex(dictionaryIndex: self.rawDictionary.startIndex) - default: - return JSONIndex() - } - } - - public var endIndex: JSON.Index { - switch self.type { - case .Array: - return JSONIndex(arrayIndex: self.rawArray.endIndex) - case .Dictionary: - return JSONIndex(dictionaryIndex: self.rawDictionary.endIndex) - default: - return JSONIndex() - } - } - - public subscript (position: JSON.Index) -> JSON.Generator.Element { - switch self.type { - case .Array: - return (String(position.arrayIndex), JSON(self.rawArray[position.arrayIndex!])) - case .Dictionary: - let (key, value) = self.rawDictionary[position.dictionaryIndex!] - return (key, JSON(value)) - default: - return ("", JSON.null) - } - } - - /// If `type` is `.Array` or `.Dictionary`, return `array.isEmpty` or `dictonary.isEmpty` otherwise return `true`. - public var isEmpty: Bool { - get { - switch self.type { - case .Array: - return self.rawArray.isEmpty - case .Dictionary: - return self.rawDictionary.isEmpty - default: - return true - } - } - } - - /// If `type` is `.Array` or `.Dictionary`, return `array.count` or `dictonary.count` otherwise return `0`. - public var count: Int { - switch self.type { - case .Array: - return self.rawArray.count - case .Dictionary: - return self.rawDictionary.count - default: - return 0 - } - } - - public func underestimateCount() -> Int { - switch self.type { - case .Array: - return self.rawArray.underestimateCount() - case .Dictionary: - return self.rawDictionary.underestimateCount() - default: - return 0 - } - } - - /** - If `type` is `.Array` or `.Dictionary`, return a generator over the elements like `Array` or `Dictionary`, otherwise return a generator over empty. - - - returns: Return a *generator* over the elements of JSON. - */ - public func generate() -> JSON.Generator { - return JSON.Generator(self) - } -} - -public struct JSONIndex: ForwardIndexType, _Incrementable, Equatable, Comparable { - - let arrayIndex: Int? - let dictionaryIndex: DictionaryIndex? - - let type: Type - - init(){ - self.arrayIndex = nil - self.dictionaryIndex = nil - self.type = .Unknown - } - - init(arrayIndex: Int) { - self.arrayIndex = arrayIndex - self.dictionaryIndex = nil - self.type = .Array - } - - init(dictionaryIndex: DictionaryIndex) { - self.arrayIndex = nil - self.dictionaryIndex = dictionaryIndex - self.type = .Dictionary - } - - public func successor() -> JSONIndex { - switch self.type { - case .Array: - return JSONIndex(arrayIndex: self.arrayIndex!.successor()) - case .Dictionary: - return JSONIndex(dictionaryIndex: self.dictionaryIndex!.successor()) - default: - return JSONIndex() - } - } +public enum JSONIndex:Comparable { + case Array(Int) + case Dictionary(DictionaryIndex) + case Null } public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - switch (lhs.type, rhs.type) { - case (.Array, .Array): - return lhs.arrayIndex == rhs.arrayIndex - case (.Dictionary, .Dictionary): - return lhs.dictionaryIndex == rhs.dictionaryIndex + switch (lhs, rhs) { + case (.Array(let left), .Array(let right)): + return left == right + case (.Dictionary(let left), .Dictionary(let right)): + return left == right default: return false } } public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - switch (lhs.type, rhs.type) { - case (.Array, .Array): - return lhs.arrayIndex < rhs.arrayIndex - case (.Dictionary, .Dictionary): - return lhs.dictionaryIndex < rhs.dictionaryIndex + switch (lhs, rhs) { + case (.Array(let left), .Array(let right)): + return left < right + case (.Dictionary(let left), .Dictionary(let right)): + return left < right default: return false } } -public func <=(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - switch (lhs.type, rhs.type) { - case (.Array, .Array): - return lhs.arrayIndex <= rhs.arrayIndex - case (.Dictionary, .Dictionary): - return lhs.dictionaryIndex <= rhs.dictionaryIndex - default: - return false - } -} - -public func >=(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - switch (lhs.type, rhs.type) { - case (.Array, .Array): - return lhs.arrayIndex >= rhs.arrayIndex - case (.Dictionary, .Dictionary): - return lhs.dictionaryIndex >= rhs.dictionaryIndex - default: - return false - } -} -public func >(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - switch (lhs.type, rhs.type) { - case (.Array, .Array): - return lhs.arrayIndex > rhs.arrayIndex - case (.Dictionary, .Dictionary): - return lhs.dictionaryIndex > rhs.dictionaryIndex - default: - return false - } -} +extension JSON: Collection{ -public struct JSONGenerator : GeneratorType { + public typealias Index = JSONIndex - public typealias Element = (String, JSON) + public var startIndex: Index{ + switch type { + case .array: + return .Array(rawArray.startIndex) + case .dictionary: + return .Dictionary(dictionaryValue.startIndex) + default: + return .Null + } + } - private let type: Type - private var dictionayGenerate: DictionaryGenerator? - private var arrayGenerate: IndexingGenerator<[AnyObject]>? - private var arrayIndex: Int = 0 + public var endIndex: Index{ + switch type { + case .array: + return .Array(rawArray.endIndex) + case .dictionary: + return .Dictionary(dictionaryValue.endIndex) + default: + return .Null + } + } - init(_ json: JSON) { - self.type = json.type - if type == .Array { - self.arrayGenerate = json.rawArray.generate() - }else { - self.dictionayGenerate = json.rawDictionary.generate() + public func index(after i: Index) -> Index { + switch i { + case .Array(let idx): + return .Array(rawArray.index(after: idx)) + case .Dictionary(let idx): + return .Dictionary(dictionaryValue.index(after: idx)) + default: + return .Null } + } - public mutating func next() -> JSONGenerator.Element? { - switch self.type { - case .Array: - if let o = self.arrayGenerate?.next() { - let i = self.arrayIndex - self.arrayIndex += 1 - return (String(i), JSON(o)) - } else { - return nil - } - case .Dictionary: - if let (k, v): (String, AnyObject) = self.dictionayGenerate?.next() { - return (k, JSON(v)) - } else { - return nil - } + public subscript (position: Index) -> (String, JSON) { + switch position { + case .Array(let idx): + return (String(idx), JSON(self.rawArray[idx])) + case .Dictionary(let idx): + return dictionaryValue[idx] default: - return nil + return ("", JSON.null) } } + + } // MARK: - Subscript @@ -420,8 +281,8 @@ public struct JSONGenerator : GeneratorType { * To mark both String and Int can be used in subscript. */ public enum JSONKey { - case Index(Int) - case Key(String) + case index(Int) + case key(String) } public protocol JSONSubscriptType { @@ -430,13 +291,13 @@ public protocol JSONSubscriptType { extension Int: JSONSubscriptType { public var jsonKey:JSONKey { - return JSONKey.Index(self) + return JSONKey.index(self) } } extension String: JSONSubscriptType { public var jsonKey:JSONKey { - return JSONKey.Key(self) + return JSONKey.key(self) } } @@ -445,7 +306,7 @@ extension JSON { /// If `type` is `.Array`, return json whose object is `array[index]`, otherwise return null json with error. private subscript(index index: Int) -> JSON { get { - if self.type != .Array { + if self.type != .array { var r = JSON.null r._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) return r @@ -458,7 +319,7 @@ extension JSON { } } set { - if self.type == .Array { + if self.type == .array { if self.rawArray.count > index && newValue.error == nil { self.rawArray[index] = newValue.object } @@ -470,7 +331,7 @@ extension JSON { private subscript(key key: String) -> JSON { get { var r = JSON.null - if self.type == .Dictionary { + if self.type == .dictionary { if let o = self.rawDictionary[key] { r = JSON(o) } else { @@ -482,7 +343,7 @@ extension JSON { return r } set { - if self.type == .Dictionary && newValue.error == nil { + if self.type == .dictionary && newValue.error == nil { self.rawDictionary[key] = newValue.object } } @@ -492,14 +353,14 @@ extension JSON { private subscript(sub sub: JSONSubscriptType) -> JSON { get { switch sub.jsonKey { - case .Index(let index): return self[index: index] - case .Key(let key): return self[key: key] + case .index(let index): return self[index: index] + case .key(let key): return self[key: key] } } set { switch sub.jsonKey { - case .Index(let index): self[index: index] = newValue - case .Key(let key): self[key: key] = newValue + case .index(let index): self[index: index] = newValue + case .key(let key): self[key: key] = newValue } } } @@ -528,7 +389,7 @@ extension JSON { case 1: self[sub:path[0]].object = newValue.object default: - var aPath = path; aPath.removeAtIndex(0) + var aPath = path; aPath.remove(at: 0) var nextJSON = self[sub: path[0]] nextJSON[aPath] = newValue self[sub: path[0]] = nextJSON @@ -625,7 +486,7 @@ extension JSON: Swift.NilLiteralConvertible { extension JSON: Swift.RawRepresentable { public init?(rawValue: AnyObject) { - if JSON(rawValue).type == .Unknown { + if JSON(rawValue).type == .unknown { return nil } else { self.init(rawValue) @@ -636,30 +497,30 @@ extension JSON: Swift.RawRepresentable { return self.object } - public func rawData(options opt: NSJSONWritingOptions = NSJSONWritingOptions(rawValue: 0)) throws -> NSData { - guard NSJSONSerialization.isValidJSONObject(self.object) else { + public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data { + guard JSONSerialization.isValidJSONObject(self.object) else { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "JSON is invalid"]) } - return try NSJSONSerialization.dataWithJSONObject(self.object, options: opt) + return try JSONSerialization.data(withJSONObject: self.object, options: opt) } - public func rawString(encoding: UInt = NSUTF8StringEncoding, options opt: NSJSONWritingOptions = .PrettyPrinted) -> String? { + public func rawString(_ encoding: String.Encoding = String.Encoding.utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? { switch self.type { - case .Array, .Dictionary: + case .array, .dictionary: do { let data = try self.rawData(options: opt) - return NSString(data: data, encoding: encoding) as? String + return String(data: data, encoding: encoding) } catch _ { return nil } - case .String: + case .string: return self.rawString - case .Number: + case .number: return self.rawNumber.stringValue - case .Bool: + case .bool: return self.rawNumber.boolValue.description - case .Null: + case .null: return "null" default: return nil @@ -669,10 +530,10 @@ extension JSON: Swift.RawRepresentable { // MARK: - Printable, DebugPrintable -extension JSON: Swift.Printable, Swift.DebugPrintable { +extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertible { public var description: String { - if let string = self.rawString(options:.PrettyPrinted) { + if let string = self.rawString(options:.prettyPrinted) { return string } else { return "unknown" @@ -691,7 +552,7 @@ extension JSON { //Optional [JSON] public var array: [JSON]? { get { - if self.type == .Array { + if self.type == .array { return self.rawArray.map{ JSON($0) } } else { return nil @@ -710,7 +571,7 @@ extension JSON { public var arrayObject: [AnyObject]? { get { switch self.type { - case .Array: + case .array: return self.rawArray default: return nil @@ -732,8 +593,9 @@ extension JSON { //Optional [String : JSON] public var dictionary: [String : JSON]? { - if self.type == .Dictionary { - return self.rawDictionary.reduce([String : JSON](minimumCapacity: count)) { (dictionary: [String : JSON], element: (String, AnyObject)) -> [String : JSON] in + if self.type == .dictionary { + + return self.rawDictionary.reduce([String : JSON]()) { (dictionary: [String : JSON], element: (String, AnyObject)) -> [String : JSON] in var d = dictionary d[element.0] = JSON(element.1) return d @@ -752,7 +614,7 @@ extension JSON { public var dictionaryObject: [String : AnyObject]? { get { switch self.type { - case .Dictionary: + case .dictionary: return self.rawDictionary default: return nil @@ -770,13 +632,13 @@ extension JSON { // MARK: - Bool -extension JSON: Swift.BooleanType { +extension JSON: Swift.Boolean { //Optional bool public var bool: Bool? { get { switch self.type { - case .Bool: + case .bool: return self.rawNumber.boolValue default: return nil @@ -784,7 +646,7 @@ extension JSON: Swift.BooleanType { } set { if let newValue = newValue { - self.object = NSNumber(bool: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -795,14 +657,14 @@ extension JSON: Swift.BooleanType { public var boolValue: Bool { get { switch self.type { - case .Bool, .Number, .String: + case .bool, .number, .string: return self.object.boolValue default: return false } } set { - self.object = NSNumber(bool: newValue) + self.object = NSNumber(value: newValue) } } } @@ -815,7 +677,7 @@ extension JSON { public var string: String? { get { switch self.type { - case .String: + case .string: return self.object as? String default: return nil @@ -834,11 +696,11 @@ extension JSON { public var stringValue: String { get { switch self.type { - case .String: + case .string: return self.object as? String ?? "" - case .Number: + case .number: return self.object.stringValue - case .Bool: + case .bool: return (self.object as? Bool).map { String($0) } ?? "" default: return "" @@ -857,7 +719,7 @@ extension JSON { public var number: NSNumber? { get { switch self.type { - case .Number, .Bool: + case .number, .bool: return self.rawNumber default: return nil @@ -872,16 +734,16 @@ extension JSON { public var numberValue: NSNumber { get { switch self.type { - case .String: + case .string: let decimal = NSDecimalNumber(string: self.object as? String) if decimal == NSDecimalNumber.notANumber() { // indicates parse error return NSDecimalNumber.zero() } return decimal - case .Number, .Bool: - return self.object as? NSNumber ?? NSNumber(int: 0) + case .number, .bool: + return self.object as? NSNumber ?? NSNumber(value: 0) default: - return NSNumber(double: 0.0) + return NSNumber(value: 0.0) } } set { @@ -896,7 +758,7 @@ extension JSON { public var null: NSNull? { get { switch self.type { - case .Null: + case .null: return self.rawNull default: return nil @@ -918,12 +780,12 @@ extension JSON { extension JSON { //Optional URL - public var URL: NSURL? { + public var URL: Foundation.URL? { get { switch self.type { - case .String: - if let encodedString_ = self.rawString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) { - return NSURL(string: encodedString_) + case .string: + if let encodedString_ = self.rawString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { + return Foundation.URL(string: encodedString_) } else { return nil } @@ -947,7 +809,7 @@ extension JSON { } set { if let newValue = newValue { - self.object = NSNumber(double: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -959,7 +821,7 @@ extension JSON { return self.numberValue.doubleValue } set { - self.object = NSNumber(double: newValue) + self.object = NSNumber(value: newValue) } } @@ -969,7 +831,7 @@ extension JSON { } set { if let newValue = newValue { - self.object = NSNumber(float: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -981,17 +843,17 @@ extension JSON { return self.numberValue.floatValue } set { - self.object = NSNumber(float: newValue) + self.object = NSNumber(value: newValue) } } public var int: Int? { get { - return self.number?.longValue + return self.number?.intValue } set { if let newValue = newValue { - self.object = NSNumber(integer: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1000,20 +862,20 @@ extension JSON { public var intValue: Int { get { - return self.numberValue.integerValue + return self.numberValue.intValue } set { - self.object = NSNumber(integer: newValue) + self.object = NSNumber(value: newValue) } } public var uInt: UInt? { get { - return self.number?.unsignedLongValue + return self.number?.uintValue } set { if let newValue = newValue { - self.object = NSNumber(unsignedLong: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1022,20 +884,20 @@ extension JSON { public var uIntValue: UInt { get { - return self.numberValue.unsignedLongValue + return self.numberValue.uintValue } set { - self.object = NSNumber(unsignedLong: newValue) + self.object = NSNumber(value: newValue) } } public var int8: Int8? { get { - return self.number?.charValue + return self.number?.int8Value } set { if let newValue = newValue { - self.object = NSNumber(char: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1044,20 +906,20 @@ extension JSON { public var int8Value: Int8 { get { - return self.numberValue.charValue + return self.numberValue.int8Value } set { - self.object = NSNumber(char: newValue) + self.object = NSNumber(value: newValue) } } public var uInt8: UInt8? { get { - return self.number?.unsignedCharValue + return self.number?.uint8Value } set { if let newValue = newValue { - self.object = NSNumber(unsignedChar: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1066,20 +928,20 @@ extension JSON { public var uInt8Value: UInt8 { get { - return self.numberValue.unsignedCharValue + return self.numberValue.uint8Value } set { - self.object = NSNumber(unsignedChar: newValue) + self.object = NSNumber(value: newValue) } } public var int16: Int16? { get { - return self.number?.shortValue + return self.number?.int16Value } set { if let newValue = newValue { - self.object = NSNumber(short: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1088,20 +950,20 @@ extension JSON { public var int16Value: Int16 { get { - return self.numberValue.shortValue + return self.numberValue.int16Value } set { - self.object = NSNumber(short: newValue) + self.object = NSNumber(value: newValue) } } public var uInt16: UInt16? { get { - return self.number?.unsignedShortValue + return self.number?.uint16Value } set { if let newValue = newValue { - self.object = NSNumber(unsignedShort: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1110,20 +972,20 @@ extension JSON { public var uInt16Value: UInt16 { get { - return self.numberValue.unsignedShortValue + return self.numberValue.uint16Value } set { - self.object = NSNumber(unsignedShort: newValue) + self.object = NSNumber(value: newValue) } } public var int32: Int32? { get { - return self.number?.intValue + return self.number?.int32Value } set { if let newValue = newValue { - self.object = NSNumber(int: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1132,20 +994,20 @@ extension JSON { public var int32Value: Int32 { get { - return self.numberValue.intValue + return self.numberValue.int32Value } set { - self.object = NSNumber(int: newValue) + self.object = NSNumber(value: newValue) } } public var uInt32: UInt32? { get { - return self.number?.unsignedIntValue + return self.number?.uint32Value } set { if let newValue = newValue { - self.object = NSNumber(unsignedInt: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1154,20 +1016,20 @@ extension JSON { public var uInt32Value: UInt32 { get { - return self.numberValue.unsignedIntValue + return self.numberValue.uint32Value } set { - self.object = NSNumber(unsignedInt: newValue) + self.object = NSNumber(value: newValue) } } public var int64: Int64? { get { - return self.number?.longLongValue + return self.number?.int64Value } set { if let newValue = newValue { - self.object = NSNumber(longLong: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1176,20 +1038,20 @@ extension JSON { public var int64Value: Int64 { get { - return self.numberValue.longLongValue + return self.numberValue.int64Value } set { - self.object = NSNumber(longLong: newValue) + self.object = NSNumber(value: newValue) } } public var uInt64: UInt64? { get { - return self.number?.unsignedLongLongValue + return self.number?.uint64Value } set { if let newValue = newValue { - self.object = NSNumber(unsignedLongLong: newValue) + self.object = NSNumber(value: newValue) } else { self.object = NSNull() } @@ -1198,10 +1060,10 @@ extension JSON { public var uInt64Value: UInt64 { get { - return self.numberValue.unsignedLongLongValue + return self.numberValue.uint64Value } set { - self.object = NSNumber(unsignedLongLong: newValue) + self.object = NSNumber(value: newValue) } } } @@ -1212,17 +1074,17 @@ extension JSON : Swift.Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.Number, .Number): + case (.number, .number): return lhs.rawNumber == rhs.rawNumber - case (.String, .String): + case (.string, .string): return lhs.rawString == rhs.rawString - case (.Bool, .Bool): + case (.bool, .bool): return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue - case (.Array, .Array): + case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray - case (.Dictionary, .Dictionary): + case (.dictionary, .dictionary): return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary - case (.Null, .Null): + case (.null, .null): return true default: return false @@ -1232,17 +1094,17 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { public func <=(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.Number, .Number): + case (.number, .number): return lhs.rawNumber <= rhs.rawNumber - case (.String, .String): + case (.string, .string): return lhs.rawString <= rhs.rawString - case (.Bool, .Bool): + case (.bool, .bool): return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue - case (.Array, .Array): + case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray - case (.Dictionary, .Dictionary): + case (.dictionary, .dictionary): return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary - case (.Null, .Null): + case (.null, .null): return true default: return false @@ -1252,17 +1114,17 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { public func >=(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.Number, .Number): + case (.number, .number): return lhs.rawNumber >= rhs.rawNumber - case (.String, .String): + case (.string, .string): return lhs.rawString >= rhs.rawString - case (.Bool, .Bool): + case (.bool, .bool): return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue - case (.Array, .Array): + case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray - case (.Dictionary, .Dictionary): + case (.dictionary, .dictionary): return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary - case (.Null, .Null): + case (.null, .null): return true default: return false @@ -1272,9 +1134,9 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { public func >(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.Number, .Number): + case (.number, .number): return lhs.rawNumber > rhs.rawNumber - case (.String, .String): + case (.string, .string): return lhs.rawString > rhs.rawString default: return false @@ -1284,28 +1146,28 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { public func <(lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.Number, .Number): + case (.number, .number): return lhs.rawNumber < rhs.rawNumber - case (.String, .String): + case (.string, .string): return lhs.rawString < rhs.rawString default: return false } } -private let trueNumber = NSNumber(bool: true) -private let falseNumber = NSNumber(bool: false) -private let trueObjCType = String.fromCString(trueNumber.objCType) -private let falseObjCType = String.fromCString(falseNumber.objCType) +private let trueNumber = NSNumber(value: true) +private let falseNumber = NSNumber(value: false) +private let trueObjCType = String(cString: trueNumber.objCType) +private let falseObjCType = String(cString: falseNumber.objCType) // MARK: - NSNumber: Comparable extension NSNumber { var isBool:Bool { get { - let objCType = String.fromCString(self.objCType) - if (self.compare(trueNumber) == NSComparisonResult.OrderedSame && objCType == trueObjCType) - || (self.compare(falseNumber) == NSComparisonResult.OrderedSame && objCType == falseObjCType){ + let objCType = String(cString: self.objCType) + if (self.compare(trueNumber) == ComparisonResult.orderedSame && objCType == trueObjCType) + || (self.compare(falseNumber) == ComparisonResult.orderedSame && objCType == falseObjCType){ return true } else { return false @@ -1321,7 +1183,7 @@ func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { case (true, false): return false default: - return lhs.compare(rhs) == NSComparisonResult.OrderedSame + return lhs.compare(rhs) == ComparisonResult.orderedSame } } @@ -1337,7 +1199,7 @@ func <(lhs: NSNumber, rhs: NSNumber) -> Bool { case (true, false): return false default: - return lhs.compare(rhs) == NSComparisonResult.OrderedAscending + return lhs.compare(rhs) == ComparisonResult.orderedAscending } } @@ -1349,7 +1211,7 @@ func >(lhs: NSNumber, rhs: NSNumber) -> Bool { case (true, false): return false default: - return lhs.compare(rhs) == NSComparisonResult.OrderedDescending + return lhs.compare(rhs) == ComparisonResult.orderedDescending } } @@ -1361,7 +1223,7 @@ func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { case (true, false): return false default: - return lhs.compare(rhs) != NSComparisonResult.OrderedDescending + return lhs.compare(rhs) != ComparisonResult.orderedDescending } } @@ -1373,6 +1235,6 @@ func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { case (true, false): return false default: - return lhs.compare(rhs) != NSComparisonResult.OrderedAscending + return lhs.compare(rhs) != ComparisonResult.orderedAscending } } diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index f3628d27..10897c87 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -422,13 +422,15 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; TargetAttributes = { 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; }; 2E4FEFE519575BE100351305 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; TestTargetID = 2E4FEFDA19575BE100351305; }; 9C7DFC5A1A9102BD005AA3F7 = { @@ -658,6 +660,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = fast; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -670,7 +673,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -705,6 +708,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = fast; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; @@ -712,7 +716,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -742,6 +746,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -763,6 +768,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -779,6 +785,7 @@ METAL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -791,6 +798,7 @@ METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme index 1441778e..6d7a6f62 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,11 +66,11 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -66,11 +66,11 @@ diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme index 7dacc905..d760fb2b 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme @@ -1,6 +1,6 @@ = -988343) - let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(value:87621.12345678)) XCTAssertGreaterThanOrEqual(jsonL3, jsonR3) XCTAssertTrue(jsonR3 >= 0.3232) } @@ -88,8 +88,8 @@ class ComparableTests: XCTestCase { XCTAssertLessThanOrEqual(jsonR2, jsonL2) XCTAssertFalse(9348343 <= jsonR2) - let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(double:87621.12345678)) + let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(value:87621.12345678)) XCTAssertLessThanOrEqual(jsonR3, jsonL3) XCTAssertTrue(87621.12345678 <= jsonR3) } @@ -105,8 +105,8 @@ class ComparableTests: XCTestCase { XCTAssertGreaterThan(jsonL2, jsonR2) XCTAssertFalse(jsonR2 > 877434) - let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) + let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(value:87621.1234567)) XCTAssertGreaterThan(jsonL3, jsonR3) XCTAssertFalse(-7799 > jsonR3) } @@ -122,8 +122,8 @@ class ComparableTests: XCTestCase { XCTAssertLessThan(jsonR2, jsonL2) XCTAssertTrue(jsonR2 < 877434) - let jsonL3:JSON = JSON(NSNumber(double:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(double:87621.1234567)) + let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3:JSON = JSON(NSNumber(value:87621.1234567)) XCTAssertLessThan(jsonR3, jsonL3) XCTAssertTrue(-7799 < jsonR3) } diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 6b7b954d..8e19517b 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -26,7 +26,7 @@ class NumberTests: XCTestCase { func testNumber() { //getter - var json = JSON(NSNumber(double: 9876543210.123456789)) + var json = JSON(NSNumber(value: 9876543210.123456789)) XCTAssertEqual(json.number!, 9876543210.123456789) XCTAssertEqual(json.numberValue, 9876543210.123456789) XCTAssertEqual(json.stringValue, "9876543210.123457") @@ -39,7 +39,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue.description, "1000000000000000000000000000") //setter - json.number = NSNumber(double: 123456789.0987654321) + json.number = NSNumber(value: 123456789.0987654321) XCTAssertEqual(json.number!, 123456789.0987654321) XCTAssertEqual(json.numberValue, 123456789.0987654321) @@ -106,22 +106,22 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, 54321.12345) XCTAssertEqual(json.stringValue, "54321.12345") - json.float = 23231.65 + json.double = 23231.65 XCTAssertTrue(json.float! == 23231.65) XCTAssertTrue(json.floatValue == 23231.65) - XCTAssertEqual(json.numberValue, NSNumber(float:23231.65)) + XCTAssertEqual(json.numberValue, NSNumber(value:23231.65)) - json.floatValue = -98766.23 + json.double = -98766.23 XCTAssertEqual(json.float!, -98766.23) XCTAssertEqual(json.floatValue, -98766.23) - XCTAssertEqual(json.numberValue, NSNumber(float:-98766.23)) + XCTAssertEqual(json.numberValue, NSNumber(value:-98766.23)) } func testInt() { var json = JSON(123456789) XCTAssertEqual(json.int!, 123456789) XCTAssertEqual(json.intValue, 123456789) - XCTAssertEqual(json.numberValue, NSNumber(integer: 123456789)) + XCTAssertEqual(json.numberValue, NSNumber(value: 123456789)) XCTAssertEqual(json.stringValue, "123456789") json.int = nil @@ -134,19 +134,19 @@ class NumberTests: XCTestCase { json.intValue = 76543 XCTAssertEqual(json.int!, 76543) XCTAssertEqual(json.intValue, 76543) - XCTAssertEqual(json.numberValue, NSNumber(integer: 76543)) + XCTAssertEqual(json.numberValue, NSNumber(value: 76543)) json.intValue = 98765421 XCTAssertEqual(json.int!, 98765421) XCTAssertEqual(json.intValue, 98765421) - XCTAssertEqual(json.numberValue, NSNumber(integer: 98765421)) + XCTAssertEqual(json.numberValue, NSNumber(value: 98765421)) } func testUInt() { var json = JSON(123456789) XCTAssertTrue(json.uInt! == 123456789) XCTAssertTrue(json.uIntValue == 123456789) - XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 123456789)) + XCTAssertEqual(json.numberValue, NSNumber(value: 123456789)) XCTAssertEqual(json.stringValue, "123456789") json.uInt = nil @@ -159,35 +159,35 @@ class NumberTests: XCTestCase { json.uIntValue = 76543 XCTAssertTrue(json.uInt! == 76543) XCTAssertTrue(json.uIntValue == 76543) - XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 76543)) + XCTAssertEqual(json.numberValue, NSNumber(value: 76543)) json.uIntValue = 98765421 XCTAssertTrue(json.uInt! == 98765421) XCTAssertTrue(json.uIntValue == 98765421) - XCTAssertEqual(json.numberValue, NSNumber(unsignedInteger: 98765421)) + XCTAssertEqual(json.numberValue, NSNumber(value: 98765421)) } func testInt8() { - let n127 = NSNumber(char: 127) + let n127 = NSNumber(value: 127) var json = JSON(n127) - XCTAssertTrue(json.int8! == n127.charValue) - XCTAssertTrue(json.int8Value == n127.charValue) + XCTAssertTrue(json.int8! == n127.int8Value) + XCTAssertTrue(json.int8Value == n127.int8Value) XCTAssertTrue(json.number! == n127) XCTAssertEqual(json.numberValue, n127) XCTAssertEqual(json.stringValue, "127") - let nm128 = NSNumber(char: -128) - json.int8Value = nm128.charValue - XCTAssertTrue(json.int8! == nm128.charValue) - XCTAssertTrue(json.int8Value == nm128.charValue) + let nm128 = NSNumber(value: -128) + json.int8Value = nm128.int8Value + XCTAssertTrue(json.int8! == nm128.int8Value) + XCTAssertTrue(json.int8Value == nm128.int8Value) XCTAssertTrue(json.number! == nm128) XCTAssertEqual(json.numberValue, nm128) XCTAssertEqual(json.stringValue, "-128") - let n0 = NSNumber(char: 0 as Int8) - json.int8Value = n0.charValue - XCTAssertTrue(json.int8! == n0.charValue) - XCTAssertTrue(json.int8Value == n0.charValue) + let n0 = NSNumber(value: 0 as Int8) + json.int8Value = n0.int8Value + XCTAssertTrue(json.int8! == n0.int8Value) + XCTAssertTrue(json.int8Value == n0.int8Value) print(json.number) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) @@ -198,10 +198,10 @@ class NumberTests: XCTestCase { #endif - let n1 = NSNumber(char: 1 as Int8) - json.int8Value = n1.charValue - XCTAssertTrue(json.int8! == n1.charValue) - XCTAssertTrue(json.int8Value == n1.charValue) + let n1 = NSNumber(value: 1 as Int8) + json.int8Value = n1.int8Value + XCTAssertTrue(json.int8! == n1.int8Value) + XCTAssertTrue(json.int8Value == n1.int8Value) XCTAssertTrue(json.number! == n1) XCTAssertEqual(json.numberValue, n1) #if (arch(x86_64) || arch(arm64)) @@ -212,34 +212,34 @@ class NumberTests: XCTestCase { } func testUInt8() { - let n255 = NSNumber(unsignedChar: 255) + let n255 = NSNumber(value: 255) var json = JSON(n255) - XCTAssertTrue(json.uInt8! == n255.unsignedCharValue) - XCTAssertTrue(json.uInt8Value == n255.unsignedCharValue) + XCTAssertTrue(json.uInt8! == n255.uint8Value) + XCTAssertTrue(json.uInt8Value == n255.uint8Value) XCTAssertTrue(json.number! == n255) XCTAssertEqual(json.numberValue, n255) XCTAssertEqual(json.stringValue, "255") - let nm2 = NSNumber(unsignedChar: 2) - json.uInt8Value = nm2.unsignedCharValue - XCTAssertTrue(json.uInt8! == nm2.unsignedCharValue) - XCTAssertTrue(json.uInt8Value == nm2.unsignedCharValue) + let nm2 = NSNumber(value: 2) + json.uInt8Value = nm2.uint8Value + XCTAssertTrue(json.uInt8! == nm2.uint8Value) + XCTAssertTrue(json.uInt8Value == nm2.uint8Value) XCTAssertTrue(json.number! == nm2) XCTAssertEqual(json.numberValue, nm2) XCTAssertEqual(json.stringValue, "2") - let nm0 = NSNumber(unsignedChar: 0) - json.uInt8Value = nm0.unsignedCharValue - XCTAssertTrue(json.uInt8! == nm0.unsignedCharValue) - XCTAssertTrue(json.uInt8Value == nm0.unsignedCharValue) + let nm0 = NSNumber(value: 0) + json.uInt8Value = nm0.uint8Value + XCTAssertTrue(json.uInt8! == nm0.uint8Value) + XCTAssertTrue(json.uInt8Value == nm0.uint8Value) XCTAssertTrue(json.number! == nm0) XCTAssertEqual(json.numberValue, nm0) XCTAssertEqual(json.stringValue, "0") - let nm1 = NSNumber(unsignedChar: 1) - json.uInt8 = nm1.unsignedCharValue - XCTAssertTrue(json.uInt8! == nm1.unsignedCharValue) - XCTAssertTrue(json.uInt8Value == nm1.unsignedCharValue) + let nm1 = NSNumber(value: 1) + json.uInt8 = nm1.uint8Value + XCTAssertTrue(json.uInt8! == nm1.uint8Value) + XCTAssertTrue(json.uInt8Value == nm1.uint8Value) XCTAssertTrue(json.number! == nm1) XCTAssertEqual(json.numberValue, nm1) XCTAssertEqual(json.stringValue, "1") @@ -247,35 +247,35 @@ class NumberTests: XCTestCase { func testInt16() { - let n32767 = NSNumber(short: 32767) + let n32767 = NSNumber(value: 32767) var json = JSON(n32767) - XCTAssertTrue(json.int16! == n32767.shortValue) - XCTAssertTrue(json.int16Value == n32767.shortValue) + XCTAssertTrue(json.int16! == n32767.int16Value) + XCTAssertTrue(json.int16Value == n32767.int16Value) XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - let nm32768 = NSNumber(short: -32768) - json.int16Value = nm32768.shortValue - XCTAssertTrue(json.int16! == nm32768.shortValue) - XCTAssertTrue(json.int16Value == nm32768.shortValue) + let nm32768 = NSNumber(value: -32768) + json.int16Value = nm32768.int16Value + XCTAssertTrue(json.int16! == nm32768.int16Value) + XCTAssertTrue(json.int16Value == nm32768.int16Value) XCTAssertTrue(json.number! == nm32768) XCTAssertEqual(json.numberValue, nm32768) XCTAssertEqual(json.stringValue, "-32768") - let n0 = NSNumber(short: 0) - json.int16Value = n0.shortValue - XCTAssertTrue(json.int16! == n0.shortValue) - XCTAssertTrue(json.int16Value == n0.shortValue) + let n0 = NSNumber(value: 0) + json.int16Value = n0.int16Value + XCTAssertTrue(json.int16! == n0.int16Value) + XCTAssertTrue(json.int16Value == n0.int16Value) print(json.number) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) XCTAssertEqual(json.stringValue, "0") - let n1 = NSNumber(short: 1) - json.int16 = n1.shortValue - XCTAssertTrue(json.int16! == n1.shortValue) - XCTAssertTrue(json.int16Value == n1.shortValue) + let n1 = NSNumber(value: 1) + json.int16 = n1.int16Value + XCTAssertTrue(json.int16! == n1.int16Value) + XCTAssertTrue(json.int16Value == n1.int16Value) XCTAssertTrue(json.number! == n1) XCTAssertEqual(json.numberValue, n1) XCTAssertEqual(json.stringValue, "1") @@ -283,114 +283,114 @@ class NumberTests: XCTestCase { func testUInt16() { - let n65535 = NSNumber(unsignedInteger: 65535) + let n65535 = NSNumber(value: 65535) var json = JSON(n65535) - XCTAssertTrue(json.uInt16! == n65535.unsignedShortValue) - XCTAssertTrue(json.uInt16Value == n65535.unsignedShortValue) + XCTAssertTrue(json.uInt16! == n65535.uint16Value) + XCTAssertTrue(json.uInt16Value == n65535.uint16Value) XCTAssertTrue(json.number! == n65535) XCTAssertEqual(json.numberValue, n65535) XCTAssertEqual(json.stringValue, "65535") - let n32767 = NSNumber(unsignedInteger: 32767) - json.uInt16 = n32767.unsignedShortValue - XCTAssertTrue(json.uInt16! == n32767.unsignedShortValue) - XCTAssertTrue(json.uInt16Value == n32767.unsignedShortValue) + let n32767 = NSNumber(value: 32767) + json.uInt16 = n32767.uint16Value + XCTAssertTrue(json.uInt16! == n32767.uint16Value) + XCTAssertTrue(json.uInt16Value == n32767.uint16Value) XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") } func testInt32() { - let n2147483647 = NSNumber(int: 2147483647) + let n2147483647 = NSNumber(value: 2147483647) var json = JSON(n2147483647) - XCTAssertTrue(json.int32! == n2147483647.intValue) - XCTAssertTrue(json.int32Value == n2147483647.intValue) + XCTAssertTrue(json.int32! == n2147483647.int32Value) + XCTAssertTrue(json.int32Value == n2147483647.int32Value) XCTAssertTrue(json.number! == n2147483647) XCTAssertEqual(json.numberValue, n2147483647) XCTAssertEqual(json.stringValue, "2147483647") - let n32767 = NSNumber(int: 32767) - json.int32 = n32767.intValue - XCTAssertTrue(json.int32! == n32767.intValue) - XCTAssertTrue(json.int32Value == n32767.intValue) + let n32767 = NSNumber(value: 32767) + json.int32 = n32767.int32Value + XCTAssertTrue(json.int32! == n32767.int32Value) + XCTAssertTrue(json.int32Value == n32767.int32Value) XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - let nm2147483648 = NSNumber(int: -2147483648) - json.int32Value = nm2147483648.intValue - XCTAssertTrue(json.int32! == nm2147483648.intValue) - XCTAssertTrue(json.int32Value == nm2147483648.intValue) + let nm2147483648 = NSNumber(value: -2147483648) + json.int32Value = nm2147483648.int32Value + XCTAssertTrue(json.int32! == nm2147483648.int32Value) + XCTAssertTrue(json.int32Value == nm2147483648.int32Value) XCTAssertTrue(json.number! == nm2147483648) XCTAssertEqual(json.numberValue, nm2147483648) XCTAssertEqual(json.stringValue, "-2147483648") } func testUInt32() { - let n2147483648 = NSNumber(unsignedInt: 2147483648) + let n2147483648 = NSNumber(value: 2147483648) var json = JSON(n2147483648) - XCTAssertTrue(json.uInt32! == n2147483648.unsignedIntValue) - XCTAssertTrue(json.uInt32Value == n2147483648.unsignedIntValue) + XCTAssertTrue(json.uInt32! == n2147483648.uint32Value) + XCTAssertTrue(json.uInt32Value == n2147483648.uint32Value) XCTAssertTrue(json.number! == n2147483648) XCTAssertEqual(json.numberValue, n2147483648) XCTAssertEqual(json.stringValue, "2147483648") - let n32767 = NSNumber(unsignedInt: 32767) - json.uInt32 = n32767.unsignedIntValue - XCTAssertTrue(json.uInt32! == n32767.unsignedIntValue) - XCTAssertTrue(json.uInt32Value == n32767.unsignedIntValue) + let n32767 = NSNumber(value: 32767) + json.uInt32 = n32767.uint32Value + XCTAssertTrue(json.uInt32! == n32767.uint32Value) + XCTAssertTrue(json.uInt32Value == n32767.uint32Value) XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - let n0 = NSNumber(unsignedInt: 0) - json.uInt32Value = n0.unsignedIntValue - XCTAssertTrue(json.uInt32! == n0.unsignedIntValue) - XCTAssertTrue(json.uInt32Value == n0.unsignedIntValue) + let n0 = NSNumber(value: 0) + json.uInt32Value = n0.uint32Value + XCTAssertTrue(json.uInt32! == n0.uint32Value) + XCTAssertTrue(json.uInt32Value == n0.uint32Value) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) XCTAssertEqual(json.stringValue, "0") } func testInt64() { - let int64Max = NSNumber(longLong: INT64_MAX) + let int64Max = NSNumber(value: INT64_MAX) var json = JSON(int64Max) - XCTAssertTrue(json.int64! == int64Max.longLongValue) - XCTAssertTrue(json.int64Value == int64Max.longLongValue) + XCTAssertTrue(json.int64! == int64Max.int64Value) + XCTAssertTrue(json.int64Value == int64Max.int64Value) XCTAssertTrue(json.number! == int64Max) XCTAssertEqual(json.numberValue, int64Max) XCTAssertEqual(json.stringValue, int64Max.stringValue) - let n32767 = NSNumber(longLong: 32767) - json.int64 = n32767.longLongValue - XCTAssertTrue(json.int64! == n32767.longLongValue) - XCTAssertTrue(json.int64Value == n32767.longLongValue) + let n32767 = NSNumber(value: 32767) + json.int64 = n32767.int64Value + XCTAssertTrue(json.int64! == n32767.int64Value) + XCTAssertTrue(json.int64Value == n32767.int64Value) XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - let int64Min = NSNumber(longLong: (INT64_MAX-1) * -1) - json.int64Value = int64Min.longLongValue - XCTAssertTrue(json.int64! == int64Min.longLongValue) - XCTAssertTrue(json.int64Value == int64Min.longLongValue) + let int64Min = NSNumber(value: (INT64_MAX-1) * -1) + json.int64Value = int64Min.int64Value + XCTAssertTrue(json.int64! == int64Min.int64Value) + XCTAssertTrue(json.int64Value == int64Min.int64Value) XCTAssertTrue(json.number! == int64Min) XCTAssertEqual(json.numberValue, int64Min) XCTAssertEqual(json.stringValue, int64Min.stringValue) } func testUInt64() { - let uInt64Max = NSNumber(unsignedLongLong: UINT64_MAX) + let uInt64Max = NSNumber(value: UINT64_MAX) var json = JSON(uInt64Max) - XCTAssertTrue(json.uInt64! == uInt64Max.unsignedLongLongValue) - XCTAssertTrue(json.uInt64Value == uInt64Max.unsignedLongLongValue) + XCTAssertTrue(json.uInt64! == uInt64Max.uint64Value) + XCTAssertTrue(json.uInt64Value == uInt64Max.uint64Value) XCTAssertTrue(json.number! == uInt64Max) XCTAssertEqual(json.numberValue, uInt64Max) XCTAssertEqual(json.stringValue, uInt64Max.stringValue) - let n32767 = NSNumber(longLong: 32767) - json.int64 = n32767.longLongValue - XCTAssertTrue(json.int64! == n32767.longLongValue) - XCTAssertTrue(json.int64Value == n32767.longLongValue) + let n32767 = NSNumber(value: 32767) + json.int64 = n32767.int64Value + XCTAssertTrue(json.int64! == n32767.int64Value) + XCTAssertTrue(json.int64Value == n32767.int64Value) XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index c7cd7450..18a10ea1 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -25,13 +25,13 @@ import SwiftyJSON class PerformanceTests: XCTestCase { - var testData: NSData! + var testData: Data! override func setUp() { super.setUp() - if let file = NSBundle(forClass:PerformanceTests.self).pathForResource("Tests", ofType: "json") { - self.testData = NSData(contentsOfFile: file) + if let file = Bundle(for:PerformanceTests.self).pathForResource("Tests", ofType: "json") { + self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { XCTFail("Can't find the test JSON file") } @@ -43,7 +43,7 @@ class PerformanceTests: XCTestCase { } func testInitPerformance() { - self.measureBlock() { + self.measure() { for _ in 1...100 { let json = JSON(data:self.testData) XCTAssertTrue(json != JSON.null) @@ -53,7 +53,7 @@ class PerformanceTests: XCTestCase { func testObjectMethodPerformance() { var json = JSON(data:self.testData) - self.measureBlock() { + self.measure() { for _ in 1...100 { let object:AnyObject? = json.object XCTAssertTrue(object != nil) @@ -63,7 +63,7 @@ class PerformanceTests: XCTestCase { func testArrayMethodPerformance() { let json = JSON(data:self.testData) - self.measureBlock() { + self.measure() { for _ in 1...100 { autoreleasepool{ let array = json.array @@ -75,7 +75,7 @@ class PerformanceTests: XCTestCase { func testDictionaryMethodPerformance() { let json = JSON(data:testData)[0] - self.measureBlock() { + self.measure() { for _ in 1...100 { autoreleasepool{ let dictionary = json.dictionary @@ -87,7 +87,7 @@ class PerformanceTests: XCTestCase { func testRawStringMethodPerformance() { let json = JSON(data:testData) - self.measureBlock() { + self.measure() { for _ in 1...100 { autoreleasepool{ let string = json.rawString() diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index 2a4203d7..72448288 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -56,20 +56,20 @@ class PrintableTests: XCTestCase { func testArray() { let json:JSON = [1,2,"4",5,"6"] - var description = json.description.stringByReplacingOccurrencesOfString("\n", withString: "") - description = description.stringByReplacingOccurrencesOfString(" ", withString: "") + var description = json.description.replacingOccurrences(of: "\n", with: "") + description = description.replacingOccurrences(of: " ", with: "") XCTAssertEqual(description, "[1,2,\"4\",5,\"6\"]") - XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) - XCTAssertTrue(json.debugDescription.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) + XCTAssertTrue(json.debugDescription.lengthOfBytes(using: String.Encoding.utf8) > 0) } func testDictionary() { let json:JSON = ["1":2,"2":"two", "3":3] - var debugDescription = json.debugDescription.stringByReplacingOccurrencesOfString("\n", withString: "") - debugDescription = debugDescription.stringByReplacingOccurrencesOfString(" ", withString: "") - XCTAssertTrue(json.description.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) - XCTAssertTrue(debugDescription.rangeOfString("\"1\":2", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) - XCTAssertTrue(debugDescription.rangeOfString("\"2\":\"two\"", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) - XCTAssertTrue(debugDescription.rangeOfString("\"3\":3", options: NSStringCompareOptions.CaseInsensitiveSearch) != nil) + var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") + debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") + XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) + XCTAssertTrue(debugDescription.range(of: "\"1\":2", options: NSString.CompareOptions.caseInsensitiveSearch) != nil) + XCTAssertTrue(debugDescription.range(of: "\"2\":\"two\"", options: NSString.CompareOptions.caseInsensitiveSearch) != nil) + XCTAssertTrue(debugDescription.range(of: "\"3\":3", options: NSString.CompareOptions.caseInsensitiveSearch) != nil) } } diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index 149246db..e9412481 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -54,13 +54,13 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(objectTrue as? Int, 1) XCTAssertEqual(objectTrue as? Double, 1.0) XCTAssertEqual(objectTrue as? Bool, true) - XCTAssertEqual(objectTrue as? NSNumber, NSNumber(bool: true)) + XCTAssertEqual(objectTrue as? NSNumber, NSNumber(value: true)) let objectFalse: AnyObject = jsonFalse.rawValue XCTAssertEqual(objectFalse as? Int, 0) XCTAssertEqual(objectFalse as? Double, 0.0) XCTAssertEqual(objectFalse as? Bool, false) - XCTAssertEqual(objectFalse as? NSNumber, NSNumber(bool: false)) + XCTAssertEqual(objectFalse as? NSNumber, NSNumber(value: false)) } func testString() { @@ -72,7 +72,7 @@ class RawRepresentableTests: XCTestCase { XCTAssertTrue(json.dictionary == nil) XCTAssertTrue(json.null == nil) XCTAssertTrue(json.error == nil) - XCTAssertTrue(json.type == .String) + XCTAssertTrue(json.type == .string) XCTAssertEqual(json.object as? String, string) } else { XCTFail("Should not run into here") diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index 86669a66..0799be36 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -27,9 +27,9 @@ class RawTests: XCTestCase { func testRawData() { let json: JSON = ["somekey" : "some string value"] - let expectedRawData = "{\"somekey\":\"some string value\"}".dataUsingEncoding(NSUTF8StringEncoding) + let expectedRawData = "{\"somekey\":\"some string value\"}".data(using: String.Encoding.utf8) do { - let data: NSData = try json.rawData() + let data: Data = try json.rawData() XCTAssertEqual(expectedRawData, data) } catch _ { XCTFail() @@ -47,7 +47,7 @@ class RawTests: XCTestCase { func testArray() { let json:JSON = [1, "2", 3.12, NSNull(), true, ["name": "Jack"]] - let data: NSData? + let data: Data? do { data = try json.rawData() } catch _ { @@ -55,13 +55,13 @@ class RawTests: XCTestCase { } let string = json.rawString() XCTAssertTrue (data != nil) - XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + XCTAssertTrue (string!.lengthOfBytes(using: String.Encoding.utf8) > 0) print(string!) } func testDictionary() { let json:JSON = ["number":111111.23456789, "name":"Jack", "list":[1,2,3,4], "bool":false, "null":NSNull()] - let data: NSData? + let data: Data? do { data = try json.rawData() } catch _ { @@ -69,7 +69,7 @@ class RawTests: XCTestCase { } let string = json.rawString() XCTAssertTrue (data != nil) - XCTAssertTrue (string!.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 0) + XCTAssertTrue (string!.lengthOfBytes(using: String.Encoding.utf8) > 0) print(string!) } diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index b3ea4b77..467231f6 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -27,8 +27,8 @@ import SwiftyJSON class SequenceTypeTests: XCTestCase { func testJSONFile() { - if let file = NSBundle(forClass:BaseTests.self).pathForResource("Tests", ofType: "json") { - let testData = NSData(contentsOfFile: file) + if let file = Bundle(for:BaseTests.self).pathForResource("Tests", ofType: "json") { + let testData = try? Data(contentsOf: URL(fileURLWithPath: file)) let json = JSON(data:testData!) for (index, sub) in json { switch (index as NSString).integerValue { @@ -201,7 +201,7 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryAllArray() { - var json:JSON = JSON (["Number":[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], "String":["aa","bbb","cccc"], "Mix":[true, "766", NSNull(), 655231.9823]]) + var json:JSON = JSON (["Number":[NSNumber(value:1),NSNumber(value:2.123456),NSNumber(value:123456789)], "String":["aa","bbb","cccc"], "Mix":[true, "766", NSNull(), 655231.9823]]) XCTAssertEqual(json.count, 3) diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index 229349a9..8e720be4 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -38,14 +38,14 @@ class StringTests: XCTestCase { func testURL() { let json = JSON("http://github.com") - XCTAssertEqual(json.URL!, NSURL(string:"http://github.com")!) + XCTAssertEqual(json.URL!, URL(string:"http://github.com")!) } func testURLPercentEscapes() { let emDash = "\\u2014" let urlString = "http://examble.com/unencoded" + emDash + "string" - let encodedURLString = urlString.stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet()) + let encodedURLString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) let json = JSON(urlString) - XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!)!, "Wrong unpacked ") + XCTAssertEqual(json.URL!, URL(string: encodedURLString!)!, "Wrong unpacked ") } } diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index c5803664..bdbd821a 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -161,7 +161,7 @@ class SubscriptTests: XCTestCase { func testDictionaryAllArray() { //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) - let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let json:JSON = JSON ([[NSNumber(value:1),NSNumber(value:2.123456),NSNumber(value:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertTrue(json[0] == [1,2.123456,123456789]) XCTAssertEqual(json[0][1].double!, 2.123456) XCTAssertTrue(json[0][2] == 123456789) @@ -178,7 +178,7 @@ class SubscriptTests: XCTestCase { } func testOutOfBounds() { - let json:JSON = JSON ([[NSNumber(integer:1),NSNumber(double:2.123456),NSNumber(int:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let json:JSON = JSON ([[NSNumber(value:1),NSNumber(value:2.123456),NSNumber(value:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertEqual(json[9], JSON.null) XCTAssertEqual(json[-2].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) From f2c0c962cdf353a4831c8ce457aed8343ed898e4 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Tue, 14 Jun 2016 16:14:59 -0700 Subject: [PATCH 229/470] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 75d51850..cd6fc8e6 100644 --- a/README.md +++ b/README.md @@ -89,11 +89,12 @@ platform :ios, '8.0' use_frameworks! target 'MyApp' do - pod 'SwiftyJSON', :git => 'https://github.com/SwiftyJSON/SwiftyJSON.git' + pod 'SwiftyJSON' end ``` Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 8.0: + ####Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` From 2d4f4d0226257a0d78e3ffaf66186143db35b301 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Tue, 14 Jun 2016 16:21:04 -0700 Subject: [PATCH 230/470] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index cd6fc8e6..112cf609 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -#SwiftyJSON [中文介绍](http://tangplin.github.io/swiftyjson/) - +#SwiftyJSON + [![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) SwiftyJSON makes it easy to deal with JSON data in Swift. @@ -17,6 +17,9 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Setter](#setter) - [Raw object](#raw-object) - [Literal convertibles](#literal-convertibles) +> For Swift3 support, take a look at the [swift3 beta branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift3) +> [中文介绍](http://tangplin.github.io/swiftyjson/) + 1. [Work with Alamofire](#work-with-alamofire) ##Why is the typical JSON handling in Swift NOT good? From 4421d00c351215f14111f06f52fd97c740796ec0 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Tue, 14 Jun 2016 16:21:32 -0700 Subject: [PATCH 231/470] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 112cf609..7a30af7f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Setter](#setter) - [Raw object](#raw-object) - [Literal convertibles](#literal-convertibles) + > For Swift3 support, take a look at the [swift3 beta branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift3) > [中文介绍](http://tangplin.github.io/swiftyjson/) From 29e8cf380dd9ff40970243b49312e2ad1cf33b02 Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Tue, 14 Jun 2016 16:22:21 -0700 Subject: [PATCH 232/470] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7a30af7f..e281dc5c 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Literal convertibles](#literal-convertibles) > For Swift3 support, take a look at the [swift3 beta branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift3) + > [中文介绍](http://tangplin.github.io/swiftyjson/) 1. [Work with Alamofire](#work-with-alamofire) From 73670b94292b8d8496c398a973f56ac67789ba9f Mon Sep 17 00:00:00 2001 From: Ruoyu Fu Date: Tue, 14 Jun 2016 16:23:25 -0700 Subject: [PATCH 233/470] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e281dc5c..5c983cc5 100644 --- a/README.md +++ b/README.md @@ -17,12 +17,12 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Setter](#setter) - [Raw object](#raw-object) - [Literal convertibles](#literal-convertibles) +1. [Work with Alamofire](#work-with-alamofire) > For Swift3 support, take a look at the [swift3 beta branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift3) > [中文介绍](http://tangplin.github.io/swiftyjson/) -1. [Work with Alamofire](#work-with-alamofire) ##Why is the typical JSON handling in Swift NOT good? Swift is very strict about types. But although explicit typing is good for saving us from mistakes, it becomes painful when dealing with JSON and other areas that are, by nature, implicit about types. From cecab2b06d65f8e10e31858e3e17f972bb6d2e4e Mon Sep 17 00:00:00 2001 From: Jan Date: Fri, 17 Jun 2016 16:42:11 +0200 Subject: [PATCH 234/470] updated "Swift Package Manager" installation manual seems to be, that the Swift Package Manager has updated the kind of defining Versions. But on "swift build -v" we have still a issue: /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/bin/swiftc --driver-mode=swift -I /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib/swift/pm -L /Library/Developer/Toolchains/swift-latest.xctoolchain/usr/lib/swift/pm -lPackageDescription -target x86_64-apple-macosx10.10 /Users/jan/Development/iOS/Global\ Nights/Package.swift -fileno 4 /Users/jan/Development/iOS/Global Nights/Package.swift:15:17: error: incorrect argument labels in call (have 'url:tag:versions:', expected 'url:majorVersion:minor:') .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", tag: "2.3.3", versions: Version(1,0,0).. Date: Thu, 23 Jun 2016 12:01:51 +0400 Subject: [PATCH 235/470] Updated Year in License File --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index a7af1968..916a0acd 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Ruoyu Fu +Copyright (c) 2016 Ruoyu Fu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 700c8d2c9476588fc61db7d68924a24604cf7e32 Mon Sep 17 00:00:00 2001 From: Lucas Derraugh Date: Sat, 25 Jun 2016 05:39:01 -0400 Subject: [PATCH 236/470] Valid Swift 3.0 code Update Travis for Xcode 8 --- .travis.yml | 5 ++--- Source/SwiftyJSON.swift | 40 +++++++++++++++++------------------ Tests/RawTests.swift | 2 +- Tests/SequenceTypeTests.swift | 3 ++- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index 24b06066..9d896ba4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: objective-c -osx_image: xcode7.1 -xcode_sdk: iphonesimulator9.0 +osx_image: xcode8 +xcode_sdk: iphonesimulator10.0 script: 'sh scripts/ci.sh' - diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index b639ac00..ad3d9564 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -195,16 +195,16 @@ public struct JSON { } public enum JSONIndex:Comparable { - case Array(Int) - case Dictionary(DictionaryIndex) - case Null + case array(Int) + case dictionary(DictionaryIndex) + case null } public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { switch (lhs, rhs) { - case (.Array(let left), .Array(let right)): + case (.array(let left), .array(let right)): return left == right - case (.Dictionary(let left), .Dictionary(let right)): + case (.dictionary(let left), .dictionary(let right)): return left == right default: return false @@ -213,9 +213,9 @@ public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool { switch (lhs, rhs) { - case (.Array(let left), .Array(let right)): + case (.array(let left), .array(let right)): return left < right - case (.Dictionary(let left), .Dictionary(let right)): + case (.dictionary(let left), .dictionary(let right)): return left < right default: return false @@ -230,42 +230,42 @@ extension JSON: Collection{ public var startIndex: Index{ switch type { case .array: - return .Array(rawArray.startIndex) + return .array(rawArray.startIndex) case .dictionary: - return .Dictionary(dictionaryValue.startIndex) + return .dictionary(dictionaryValue.startIndex) default: - return .Null + return .null } } public var endIndex: Index{ switch type { case .array: - return .Array(rawArray.endIndex) + return .array(rawArray.endIndex) case .dictionary: - return .Dictionary(dictionaryValue.endIndex) + return .dictionary(dictionaryValue.endIndex) default: - return .Null + return .null } } public func index(after i: Index) -> Index { switch i { - case .Array(let idx): - return .Array(rawArray.index(after: idx)) - case .Dictionary(let idx): - return .Dictionary(dictionaryValue.index(after: idx)) + case .array(let idx): + return .array(rawArray.index(after: idx)) + case .dictionary(let idx): + return .dictionary(dictionaryValue.index(after: idx)) default: - return .Null + return .null } } public subscript (position: Index) -> (String, JSON) { switch position { - case .Array(let idx): + case .array(let idx): return (String(idx), JSON(self.rawArray[idx])) - case .Dictionary(let idx): + case .dictionary(let idx): return dictionaryValue[idx] default: return ("", JSON.null) diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index 0799be36..7ba7a334 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -39,7 +39,7 @@ class RawTests: XCTestCase { func testInvalidJSONForRawData() { let json: JSON = "...xyz" do { - try json.rawData() + _ = try json.rawData() } catch let error as NSError { XCTAssertEqual(error.code, ErrorInvalidJSON) } diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index 467231f6..904b90b3 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -38,7 +38,8 @@ class SequenceTypeTests: XCTestCase { XCTAssertTrue(sub["id_str"] == "240556426106372096") case 2: XCTAssertTrue(sub["id_str"] == "240539141056638977") - default:0 + default: + continue } } } else { From 976ba4c487a0b29cb46f56109baf06fd29f9b51a Mon Sep 17 00:00:00 2001 From: Lucas Derraugh Date: Sat, 25 Jun 2016 06:31:43 -0400 Subject: [PATCH 237/470] Use Swift 3.0 for whole project --- SwiftyJSON.xcodeproj/project.pbxproj | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 10897c87..37c8464c 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -679,6 +679,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -721,6 +722,7 @@ METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -746,7 +748,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -768,7 +769,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; }; name = Release; }; @@ -785,7 +785,6 @@ METAL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -798,7 +797,6 @@ METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Release; }; From 580dc33a003b7800a604fb636019ebb347b687fd Mon Sep 17 00:00:00 2001 From: EyeOfTheStorm Date: Wed, 6 Jul 2016 14:29:13 +0200 Subject: [PATCH 238/470] filled Manifest Manifest file should not be empty in Swift 3.0 --- Package.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Package.swift b/Package.swift index e69de29b..801f1d5d 100644 --- a/Package.swift +++ b/Package.swift @@ -0,0 +1,4 @@ +import PackageDescription + +let package = Package( + name: "SwiftyJSON") From 536f3766b8ea2abdffe1ebb05b0a3f31af573f22 Mon Sep 17 00:00:00 2001 From: Mariam Date: Sat, 30 Jul 2016 12:19:12 +0300 Subject: [PATCH 239/470] Add Getting an array of string from a JSON Array --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 5c983cc5..dc0bd8c3 100644 --- a/README.md +++ b/README.md @@ -152,6 +152,12 @@ if let dataFromString = jsonString.dataUsingEncoding(NSUTF8StringEncoding, allow //Getting a double from a JSON Array let name = json[0].double ``` + +```swift +//Getting an array of string from a JSON Array +let arrayNames = json["users"].arrayValue.map({$0["name"].stringValue}) +``` + ```swift //Getting a string from a JSON Dictionary let name = json["name"].stringValue From 8e488dec25f3d1c83f74a51d880ab6fd376cb9a8 Mon Sep 17 00:00:00 2001 From: Evgeny Yurtaev Date: Wed, 17 Aug 2016 00:28:39 +0100 Subject: [PATCH 240/470] Small Readme fix "dictionary" is get-only property, should be dictionaryObject. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c983cc5..dcd8834f 100644 --- a/README.md +++ b/README.md @@ -299,7 +299,7 @@ json["id"].int = 1234567890 json["coordinate"].double = 8766.766 json["name"].string = "Jack" json.arrayObject = [1,2,3,4] -json.dictionary = ["name":"Jack", "age":25] +json.dictionaryObject = ["name":"Jack", "age":25] ``` ####Raw object From fea362172a2a36c6491cd70021e508d8c2a5aaa9 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Tue, 23 Aug 2016 17:13:21 -0400 Subject: [PATCH 241/470] Spelling fix: existence, not existance --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c983cc5..9ca4c59c 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,7 @@ if let string = json.rawString() { //Do something you want } ``` -####Existance +####Existence ```swift //shows you whether value specified in JSON or not if json["name"].isExists() From d2367f7df4608649c718b41dc8eab50db98327ee Mon Sep 17 00:00:00 2001 From: Jeff Kang Date: Thu, 1 Sep 2016 23:01:15 +0900 Subject: [PATCH 242/470] Basic playground set. --- Example/Playground.playground/Contents.swift | 11 + .../Resources/SwiftyJSONTests.json | 345 ++++++++++++++++++ 2 files changed, 356 insertions(+) create mode 100644 Example/Playground.playground/Resources/SwiftyJSONTests.json diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index 33ae9484..1ed77302 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -1,3 +1,14 @@ //: Playground - noun: a place where people can play import SwiftyJSON + +var testData: NSData? + +if let file = NSBundle.mainBundle().pathForResource("SwiftyJSONTests", ofType: "json") { + testData = NSData(contentsOfFile: file) +} else { + print("Fail") +} + +let json = JSON(data: testData!) +print(json[0]["text"]) \ No newline at end of file diff --git a/Example/Playground.playground/Resources/SwiftyJSONTests.json b/Example/Playground.playground/Resources/SwiftyJSONTests.json new file mode 100644 index 00000000..05190a8a --- /dev/null +++ b/Example/Playground.playground/Resources/SwiftyJSONTests.json @@ -0,0 +1,345 @@ +[ + { + "coordinates":null, + "truncated":false, + "created_at":"Tue Aug 28 21:16:23 +0000 2012", + "favorited":false, + "id_str":"240558470661799936", + "in_reply_to_user_id_str":null, + "entities":{ + "urls":[ + + ], + "hashtags":[ + + ], + "user_mentions":[ + + ] + }, + "text":"just another test", + "contributors":null, + "id":240558470661799936, + "retweet_count":0, + "in_reply_to_status_id_str":null, + "geo":null, + "retweeted":false, + "in_reply_to_user_id":null, + "place":null, + "source":"<a href=\"//realitytechnicians.com\" rel=\"\"nofollow\"\">OAuth Dancer Reborn</a>", + "user":{ + "name":"OAuth Dancer", + "profile_sidebar_fill_color":"DDEEF6", + "profile_background_tile":true, + "profile_sidebar_border_color":"C0DEED", + "profile_image_url":"http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", + "created_at":"Wed Mar 03 19:37:35 +0000 2010", + "location":"San Francisco, CA", + "follow_request_sent":false, + "id_str":"119476949", + "is_translator":false, + "profile_link_color":"0084B4", + "entities":{ + "url":{ + "urls":[ + { + "expanded_url":null, + "url":"http://bit.ly/oauth-dancer", + "indices":[ + 0, + 26 + ], + "display_url":null + } + ] + }, + "description":null + }, + "default_profile":false, + "url":"http://bit.ly/oauth-dancer", + "contributors_enabled":false, + "favourites_count":7, + "utc_offset":null, + "profile_image_url_https":"https://si0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg", + "id":119476949, + "listed_count":1, + "profile_use_background_image":true, + "profile_text_color":"333333", + "followers_count":28, + "lang":"en", + "protected":false, + "geo_enabled":true, + "notifications":false, + "description":"", + "profile_background_color":"C0DEED", + "verified":false, + "time_zone":null, + "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/80151733/oauth-dance.png", + "statuses_count":166, + "profile_background_image_url":"http://a0.twimg.com/profile_background_images/80151733/oauth-dance.png", + "default_profile_image":false, + "friends_count":14, + "following":false, + "show_all_inline_media":false, + "screen_name":"oauth_dancer" + }, + "in_reply_to_screen_name":null, + "in_reply_to_status_id":null + }, + { + "coordinates":{ + "coordinates":[ + -122.25831, + 37.871609 + ], + "type":"Point" + }, + "truncated":false, + "created_at":"Tue Aug 28 21:08:15 +0000 2012", + "favorited":false, + "id_str":"240556426106372096", + "in_reply_to_user_id_str":null, + "entities":{ + "urls":[ + { + "expanded_url":"http://blogs.ischool.berkeley.edu/i290-abdt-s12/", + "url":"http://t.co/bfj7zkDJ", + "indices":[ + 79, + 99 + ], + "display_url":"blogs.ischool.berkeley.edu/i290-abdt-s12/" + } + ], + "hashtags":[ + + ], + "user_mentions":[ + { + "name":"Cal", + "id_str":"17445752", + "id":17445752, + "indices":[ + 60, + 64 + ], + "screen_name":"Cal" + }, + { + "name":"Othman Laraki", + "id_str":"20495814", + "id":20495814, + "indices":[ + 70, + 77 + ], + "screen_name":"othman" + } + ] + }, + "text":"lecturing at the \"analyzing big data with twitter\" class at @cal with @othman http://t.co/bfj7zkDJ", + "contributors":null, + "id":240556426106372096, + "retweet_count":3, + "in_reply_to_status_id_str":null, + "geo":{ + "coordinates":[ + 37.871609, + -122.25831 + ], + "type":"Point" + }, + "retweeted":false, + "possibly_sensitive":false, + "in_reply_to_user_id":null, + "place":{ + "name":"Berkeley", + "country_code":"US", + "country":"United States", + "attributes":{ + + }, + "url":"http://api.twitter.com/1/geo/id/5ef5b7f391e30aff.json", + "id":"5ef5b7f391e30aff", + "bounding_box":{ + "coordinates":[ + [ + [ + -122.367781, + 37.835727 + ], + [ + -122.234185, + 37.835727 + ], + [ + -122.234185, + 37.905824 + ], + [ + -122.367781, + 37.905824 + ] + ] + ], + "type":"Polygon" + }, + "full_name":"Berkeley, CA", + "place_type":"city" + }, + "source":"<a href=\"//www.apple.com\"\" rel=\"\"nofollow\"\">Safari on iOS</a>", + "user":{ + "name":"Raffi Krikorian", + "profile_sidebar_fill_color":"DDEEF6", + "profile_background_tile":false, + "profile_sidebar_border_color":"C0DEED", + "profile_image_url":"http://a0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", + "created_at":"Sun Aug 19 14:24:06 +0000 2007", + "location":"San Francisco, California", + "follow_request_sent":false, + "id_str":"8285392", + "is_translator":false, + "profile_link_color":"0084B4", + "entities":{ + "url":{ + "urls":[ + { + "expanded_url":"http://about.me/raffi.krikorian", + "url":"http://t.co/eNmnM6q", + "indices":[ + 0, + 19 + ], + "display_url":"about.me/raffi.krikorian" + } + ] + }, + "description":{ + "urls":[ + + ] + } + }, + "default_profile":true, + "url":"http://t.co/eNmnM6q", + "contributors_enabled":false, + "favourites_count":724, + "utc_offset":-28800, + "profile_image_url_https":"https://si0.twimg.com/profile_images/1270234259/raffi-headshot-casual_normal.png", + "id":8285392, + "listed_count":619, + "profile_use_background_image":true, + "profile_text_color":"333333", + "followers_count":18752, + "lang":"en", + "protected":false, + "geo_enabled":true, + "notifications":false, + "description":"Director of @twittereng's Platform Services. I break things.", + "profile_background_color":"C0DEED", + "verified":false, + "time_zone":"Pacific Time (US & Canada)", + "profile_background_image_url_https":"https://si0.twimg.com/images/themes/theme1/bg.png", + "statuses_count":5007, + "profile_background_image_url":"http://a0.twimg.com/images/themes/theme1/bg.png", + "default_profile_image":false, + "friends_count":701, + "following":true, + "show_all_inline_media":true, + "screen_name":"raffi" + }, + "in_reply_to_screen_name":null, + "in_reply_to_status_id":null + }, + { + "coordinates":null, + "truncated":false, + "created_at":"Tue Aug 28 19:59:34 +0000 2012", + "favorited":false, + "id_str":"240539141056638977", + "in_reply_to_user_id_str":null, + "entities":{ + "urls":[ + + ], + "hashtags":[ + + ], + "user_mentions":[ + + ] + }, + "text":"You'd be right more often if you thought you were wrong.", + "contributors":null, + "id":240539141056638977, + "retweet_count":1, + "in_reply_to_status_id_str":null, + "geo":null, + "retweeted":false, + "in_reply_to_user_id":null, + "place":null, + "source":"web", + "user":{ + "name":"Taylor Singletary", + "profile_sidebar_fill_color":"FBFBFB", + "profile_background_tile":true, + "profile_sidebar_border_color":"000000", + "profile_image_url":"http://a0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", + "created_at":"Wed Mar 07 22:23:19 +0000 2007", + "location":"San Francisco, CA", + "follow_request_sent":false, + "id_str":"819797", + "is_translator":false, + "profile_link_color":"c71818", + "entities":{ + "url":{ + "urls":[ + { + "expanded_url":"http://www.rebelmouse.com/episod/", + "url":"http://t.co/Lxw7upbN", + "indices":[ + 0, + 20 + ], + "display_url":"rebelmouse.com/episod/" + } + ] + }, + "description":{ + "urls":[ + + ] + } + }, + "default_profile":false, + "url":"http://t.co/Lxw7upbN", + "contributors_enabled":false, + "favourites_count":15990, + "utc_offset":-28800, + "profile_image_url_https":"https://si0.twimg.com/profile_images/2546730059/f6a8zq58mg1hn0ha8vie_normal.jpeg", + "id":819797, + "listed_count":340, + "profile_use_background_image":true, + "profile_text_color":"D20909", + "followers_count":7126, + "lang":"en", + "protected":false, + "geo_enabled":true, + "notifications":false, + "description":"Reality Technician, Twitter API team, synthesizer enthusiast; a most excellent adventure in timelines. I know it's hard to believe in something you can't see.", + "profile_background_color":"000000", + "verified":false, + "time_zone":"Pacific Time (US & Canada)", + "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", + "statuses_count":18076, + "profile_background_image_url":"http://a0.twimg.com/profile_background_images/643655842/hzfv12wini4q60zzrthg.png", + "default_profile_image":false, + "friends_count":5444, + "following":true, + "show_all_inline_media":true, + "screen_name":"episod" + }, + "in_reply_to_screen_name":null, + "in_reply_to_status_id":null + } + ] \ No newline at end of file From cf657820fad3656df022d8ebf32f9cdd99e1247a Mon Sep 17 00:00:00 2001 From: Jason Neumeier Date: Sun, 18 Sep 2016 09:25:08 -0400 Subject: [PATCH 243/470] Updated main source and tests to spec for Swift 3.0 as released in Xcode 8/0 GM. --- Example/Example.xcodeproj/project.pbxproj | 15 +- Example/Example/AppDelegate.swift | 14 +- Example/Example/Base.lproj/LaunchScreen.xib | 12 +- Example/Example/Base.lproj/Main.storyboard | 29 +- .../AppIcon.appiconset/Contents.json | 25 + Example/Example/ViewController.swift | 36 +- Source/SwiftyJSON.swift | 430 +++++++++--------- Tests/BaseTests.swift | 8 +- Tests/DictionaryTests.swift | 2 +- Tests/LiteralConvertibleTests.swift | 2 +- Tests/NumberTests.swift | 7 +- Tests/PerformanceTests.swift | 16 +- Tests/PrintableTests.swift | 6 +- Tests/RawRepresentableTests.swift | 18 +- Tests/SequenceTypeTests.swift | 10 +- Tests/StringTests.swift | 4 +- 16 files changed, 342 insertions(+), 292 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index cd37ea68..44393c89 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -186,11 +186,13 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = swiftyjson; TargetAttributes = { A82A1C1819D926B8009A653D = { CreatedOnToolsVersion = 6.0.1; + LastSwiftMigration = 0800; + ProvisioningStyle = Manual; }; }; }; @@ -329,8 +331,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; @@ -340,6 +344,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -374,8 +379,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; @@ -384,6 +391,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -393,6 +401,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -403,10 +412,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -416,10 +427,12 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; CODE_SIGN_IDENTITY = "iPhone Distribution"; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = Example/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 77c528ff..31b98b35 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -28,15 +28,19 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { let navigationController = self.window?.rootViewController as! UINavigationController let viewController = navigationController.topViewController as! ViewController - if let file = NSBundle(forClass:AppDelegate.self).pathForResource("SwiftyJSONTests", ofType: "json") { - let data = NSData(contentsOfFile: file)! - let json = JSON(data:data) - viewController.json = json + if let file = Bundle.main.path(forResource: "SwiftyJSONTests", ofType: "json") { + do { + let data = try Data(contentsOf: URL(fileURLWithPath: file)) + let json = JSON(data: data) + viewController.json = json + } catch { + viewController.json = JSON.null + } } else { viewController.json = JSON.null } diff --git a/Example/Example/Base.lproj/LaunchScreen.xib b/Example/Example/Base.lproj/LaunchScreen.xib index 0985c07c..b999ccb2 100644 --- a/Example/Example/Base.lproj/LaunchScreen.xib +++ b/Example/Example/Base.lproj/LaunchScreen.xib @@ -1,8 +1,10 @@ - - + + - + + + @@ -12,19 +14,17 @@ - + diff --git a/Example/Example/Base.lproj/Main.storyboard b/Example/Example/Base.lproj/Main.storyboard index 68803970..be1a65dc 100644 --- a/Example/Example/Base.lproj/Main.storyboard +++ b/Example/Example/Base.lproj/Main.storyboard @@ -1,13 +1,14 @@ - - + + - + + - + HelveticaNeue - + @@ -24,36 +25,36 @@ - + - + - + - + - + @@ -75,7 +76,7 @@ - + diff --git a/Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json b/Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json index 36d2c80d..1d060ed2 100644 --- a/Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Example/Example/Images.xcassets/AppIcon.appiconset/Contents.json @@ -1,5 +1,15 @@ { "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, { "idiom" : "iphone", "size" : "29x29", @@ -30,6 +40,16 @@ "size" : "60x60", "scale" : "3x" }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "1x" + }, + { + "idiom" : "ipad", + "size" : "20x20", + "scale" : "2x" + }, { "idiom" : "ipad", "size" : "29x29", @@ -59,6 +79,11 @@ "idiom" : "ipad", "size" : "76x76", "scale" : "2x" + }, + { + "idiom" : "ipad", + "size" : "83.5x83.5", + "scale" : "2x" } ], "info" : { diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index a0e13463..373be9bb 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -29,30 +29,30 @@ class ViewController: UITableViewController { // MARK: - Table view data source - override func numberOfSectionsInTableView(tableView: UITableView) -> Int { + override func numberOfSections(in tableView: UITableView) -> Int { return 1 } - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch self.json.type { - case Type.Array, Type.Dictionary: + case Type.array, Type.dictionary: return self.json.count default: return 1 } } - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier("JSONCell", forIndexPath: indexPath) as UITableViewCell + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "JSONCell", for: indexPath) as UITableViewCell - let row = indexPath.row + let row = (indexPath as NSIndexPath).row switch self.json.type { - case .Array: + case .array: cell.textLabel?.text = "\(row)" cell.detailTextLabel?.text = self.json.arrayValue.description - case .Dictionary: - let key: AnyObject = Array(self.json.dictionaryValue.keys)[row] + case .dictionary: + let key: Any = Array(self.json.dictionaryValue.keys)[row] let value = self.json[key as! String] cell.textLabel?.text = "\(key)" cell.detailTextLabel?.text = value.description @@ -66,23 +66,23 @@ class ViewController: UITableViewController { // MARK: - Navigation - override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { + override func prepare(for segue: UIStoryboardSegue, sender: Any!) { var nextController: UIViewController? - switch UIDevice.currentDevice().systemVersion.compare("8.0.0", options: NSStringCompareOptions.NumericSearch) { - case .OrderedSame, .OrderedDescending: - nextController = (segue.destinationViewController as! UINavigationController).topViewController - case .OrderedAscending: - nextController = segue.destinationViewController + switch UIDevice.current.systemVersion.compare("8.0.0", options: NSString.CompareOptions.numeric) { + case .orderedSame, .orderedDescending: + nextController = (segue.destination as! UINavigationController).topViewController + case .orderedAscending: + nextController = segue.destination } if let indexPath = self.tableView.indexPathForSelectedRow { - let row = indexPath.row + let row = (indexPath as NSIndexPath).row var nextJson: JSON = JSON.null switch self.json.type { - case .Array: + case .array: nextJson = self.json[row] - case .Dictionary where row < self.json.dictionaryValue.count: + case .dictionary where row < self.json.dictionaryValue.count: let key = Array(self.json.dictionaryValue.keys)[row] if let value = self.json.dictionary?[key] { nextJson = value diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index ad3d9564..26180fec 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -37,12 +37,12 @@ public let ErrorInvalidJSON: Int = 490 // MARK: - JSON Type /** -JSON's type definitions. - -See http://www.json.org -*/ + JSON's type definitions. + + See http://www.json.org + */ public enum Type :Int{ - + case number case string case bool @@ -55,19 +55,19 @@ public enum Type :Int{ // MARK: - JSON Base public struct JSON { - + /** - Creates a JSON using the data. - - - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - - parameter opt: The JSON serialization reading options. `.AllowFragments` by default. - - parameter error: error The NSErrorPointer used to return the error. `nil` by default. - - - returns: The created JSON - */ + Creates a JSON using the data. + + - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary + - parameter opt: The JSON serialization reading options. `.AllowFragments` by default. + - parameter error: error The NSErrorPointer used to return the error. `nil` by default. + + - returns: The created JSON + */ public init(data:Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer? = nil) { do { - let object: AnyObject = try JSONSerialization.jsonObject(with: data, options: opt) + let object: Any = try JSONSerialization.jsonObject(with: data, options: opt) self.init(object) } catch let aError as NSError { if error != nil { @@ -76,68 +76,69 @@ public struct JSON { self.init(NSNull()) } } - + /** Create a JSON from JSON string - - parameter string: Normal json string like '{"a":"b"}' - - - returns: The created JSON - */ + - parameter string: Normal json string like '{"a":"b"}' + + - returns: The created JSON + */ public static func parse(_ string:String) -> JSON { return string.data(using: String.Encoding.utf8) .flatMap({JSON(data: $0)}) ?? JSON(NSNull()) } - + /** - Creates a JSON using the object. - - - parameter object: The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. - - - returns: The created JSON - */ - public init(_ object: AnyObject) { + Creates a JSON using the object. + + - parameter object: The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. + + - returns: The created JSON + */ + public init(_ object: Any) { self.object = object } - + /** - Creates a JSON from a [JSON] - - - parameter jsonArray: A Swift array of JSON objects - - - returns: The created JSON - */ + Creates a JSON from a [JSON] + + - parameter jsonArray: A Swift array of JSON objects + + - returns: The created JSON + */ public init(_ jsonArray:[JSON]) { self.init(jsonArray.map { $0.object }) } - + /** - Creates a JSON from a [String: JSON] - - - parameter jsonDictionary: A Swift dictionary of JSON objects - - - returns: The created JSON - */ + Creates a JSON from a [String: JSON] + + - parameter jsonDictionary: A Swift dictionary of JSON objects + + - returns: The created JSON + */ public init(_ jsonDictionary:[String: JSON]) { - var dictionary = [String: AnyObject](minimumCapacity: jsonDictionary.count) + var dictionary = [String: Any](minimumCapacity: jsonDictionary.count) for (key, json) in jsonDictionary { dictionary[key] = json.object } self.init(dictionary) } - + /// Private object - private var rawArray: [AnyObject] = [] - private var rawDictionary: [String : AnyObject] = [:] - private var rawString: String = "" - private var rawNumber: NSNumber = 0 - private var rawNull: NSNull = NSNull() + fileprivate var rawArray: [Any] = [] + fileprivate var rawDictionary: [String : Any] = [:] + fileprivate var rawString: String = "" + fileprivate var rawNumber: NSNumber = 0 + fileprivate var rawNull: NSNull = NSNull() + fileprivate var rawBool: Bool = false /// Private type - private var _type: Type = .null + fileprivate var _type: Type = .null /// prviate error - private var _error: NSError? = nil - + fileprivate var _error: NSError? = nil + /// Object in JSON - public var object: AnyObject { + public var object: Any { get { switch self.type { case .array: @@ -149,7 +150,7 @@ public struct JSON { case .number: return self.rawNumber case .bool: - return self.rawNumber + return self.rawBool default: return self.rawNull } @@ -160,19 +161,20 @@ public struct JSON { case let number as NSNumber: if number.isBool { _type = .bool + self.rawBool = number.boolValue } else { _type = .number + self.rawNumber = number } - self.rawNumber = number case let string as String: _type = .string self.rawString = string case _ as NSNull: _type = .null - case let array as [AnyObject]: + case let array as [Any]: _type = .array self.rawArray = array - case let dictionary as [String : AnyObject]: + case let dictionary as [String : Any]: _type = .dictionary self.rawDictionary = dictionary default: @@ -181,13 +183,13 @@ public struct JSON { } } } - + /// json type public var type: Type { get { return _type } } - + /// Error in JSON public var error: NSError? { get { return self._error } } - + /// The static null json @available(*, unavailable, renamed:"null") public static var nullJSON: JSON { get { return null } } @@ -224,9 +226,9 @@ public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool { extension JSON: Collection{ - + public typealias Index = JSONIndex - + public var startIndex: Index{ switch type { case .array: @@ -237,7 +239,7 @@ extension JSON: Collection{ return .null } } - + public var endIndex: Index{ switch type { case .array: @@ -248,7 +250,7 @@ extension JSON: Collection{ return .null } } - + public func index(after i: Index) -> Index { switch i { case .array(let idx): @@ -258,9 +260,9 @@ extension JSON: Collection{ default: return .null } - + } - + public subscript (position: Index) -> (String, JSON) { switch position { case .array(let idx): @@ -271,15 +273,15 @@ extension JSON: Collection{ return ("", JSON.null) } } - - + + } // MARK: - Subscript /** -* To mark both String and Int can be used in subscript. -*/ + * To mark both String and Int can be used in subscript. + */ public enum JSONKey { case index(Int) case key(String) @@ -302,9 +304,9 @@ extension String: JSONSubscriptType { } extension JSON { - + /// If `type` is `.Array`, return json whose object is `array[index]`, otherwise return null json with error. - private subscript(index index: Int) -> JSON { + fileprivate subscript(index index: Int) -> JSON { get { if self.type != .array { var r = JSON.null @@ -326,9 +328,9 @@ extension JSON { } } } - + /// If `type` is `.Dictionary`, return json whose object is `dictionary[key]` , otherwise return null json with error. - private subscript(key key: String) -> JSON { + fileprivate subscript(key key: String) -> JSON { get { var r = JSON.null if self.type == .dictionary { @@ -348,9 +350,9 @@ extension JSON { } } } - + /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. - private subscript(sub sub: JSONSubscriptType) -> JSON { + fileprivate subscript(sub sub: JSONSubscriptType) -> JSON { get { switch sub.jsonKey { case .index(let index): return self[index: index] @@ -364,20 +366,20 @@ extension JSON { } } } - + /** - Find a json in the complex data structuresby using the Int/String's array. - - - parameter path: The target json's path. Example: - - let json = JSON[data] - let path = [9,"list","person","name"] - let name = json[path] - - The same as: let name = json[9]["list"]["person"]["name"] - - - returns: Return a json found by the path or a null json with error - */ + Find a json in the complex data structuresby using the Int/String's array. + + - parameter path: The target json's path. Example: + + let json = JSON[data] + let path = [9,"list","person","name"] + let name = json[path] + + The same as: let name = json[9]["list"]["person"]["name"] + + - returns: Return a json found by the path or a null json with error + */ public subscript(path: [JSONSubscriptType]) -> JSON { get { return path.reduce(self) { $0[sub: $1] } @@ -396,18 +398,18 @@ extension JSON { } } } - + /** - Find a json in the complex data structures by using the Int/String's array. - - - parameter path: The target json's path. Example: - - let name = json[9,"list","person","name"] - - The same as: let name = json[9]["list"]["person"]["name"] - - - returns: Return a json found by the path or a null json with error - */ + Find a json in the complex data structures by using the Int/String's array. + + - parameter path: The target json's path. Example: + + let name = json[9,"list","person","name"] + + The same as: let name = json[9]["list"]["person"]["name"] + + - returns: Return a json found by the path or a null json with error + */ public subscript(path: JSONSubscriptType...) -> JSON { get { return self[path] @@ -420,91 +422,91 @@ extension JSON { // MARK: - LiteralConvertible -extension JSON: Swift.StringLiteralConvertible { - +extension JSON: Swift.ExpressibleByStringLiteral { + public init(stringLiteral value: StringLiteralType) { - self.init(value) + self.init(value as Any) } - + public init(extendedGraphemeClusterLiteral value: StringLiteralType) { - self.init(value) + self.init(value as Any) } - + public init(unicodeScalarLiteral value: StringLiteralType) { - self.init(value) + self.init(value as Any) } } -extension JSON: Swift.IntegerLiteralConvertible { - +extension JSON: Swift.ExpressibleByIntegerLiteral { + public init(integerLiteral value: IntegerLiteralType) { - self.init(value) + self.init(value as Any) } } -extension JSON: Swift.BooleanLiteralConvertible { - +extension JSON: Swift.ExpressibleByBooleanLiteral { + public init(booleanLiteral value: BooleanLiteralType) { - self.init(value) + self.init(value as Any) } } -extension JSON: Swift.FloatLiteralConvertible { - +extension JSON: Swift.ExpressibleByFloatLiteral { + public init(floatLiteral value: FloatLiteralType) { - self.init(value) + self.init(value as Any) } } -extension JSON: Swift.DictionaryLiteralConvertible { - - public init(dictionaryLiteral elements: (String, AnyObject)...) { - self.init(elements.reduce([String : AnyObject](minimumCapacity: elements.count)){(dictionary: [String : AnyObject], element:(String, AnyObject)) -> [String : AnyObject] in +extension JSON: Swift.ExpressibleByDictionaryLiteral { + + public init(dictionaryLiteral elements: (String, Any)...) { + self.init(elements.reduce([String : Any](minimumCapacity: elements.count)){(dictionary: [String : Any], element:(String, Any)) -> [String : Any] in var d = dictionary d[element.0] = element.1 return d - }) + } as Any) } } -extension JSON: Swift.ArrayLiteralConvertible { - - public init(arrayLiteral elements: AnyObject...) { - self.init(elements) +extension JSON: Swift.ExpressibleByArrayLiteral { + + public init(arrayLiteral elements: Any...) { + self.init(elements as Any) } } -extension JSON: Swift.NilLiteralConvertible { - +extension JSON: Swift.ExpressibleByNilLiteral { + public init(nilLiteral: ()) { - self.init(NSNull()) + self.init(NSNull() as Any) } } // MARK: - Raw extension JSON: Swift.RawRepresentable { - - public init?(rawValue: AnyObject) { + + public init?(rawValue: Any) { if JSON(rawValue).type == .unknown { return nil } else { self.init(rawValue) } } - - public var rawValue: AnyObject { + + public var rawValue: Any { return self.object } - + public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data { guard JSONSerialization.isValidJSONObject(self.object) else { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "JSON is invalid"]) } - + return try JSONSerialization.data(withJSONObject: self.object, options: opt) } - + public func rawString(_ encoding: String.Encoding = String.Encoding.utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? { switch self.type { case .array, .dictionary: @@ -519,7 +521,7 @@ extension JSON: Swift.RawRepresentable { case .number: return self.rawNumber.stringValue case .bool: - return self.rawNumber.boolValue.description + return self.rawBool.description case .null: return "null" default: @@ -531,7 +533,7 @@ extension JSON: Swift.RawRepresentable { // MARK: - Printable, DebugPrintable extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertible { - + public var description: String { if let string = self.rawString(options:.prettyPrinted) { return string @@ -539,7 +541,7 @@ extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertibl return "unknown" } } - + public var debugDescription: String { return description } @@ -548,7 +550,7 @@ extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertibl // MARK: - Array extension JSON { - + //Optional [JSON] public var array: [JSON]? { get { @@ -559,16 +561,16 @@ extension JSON { } } } - + //Non-optional [JSON] public var arrayValue: [JSON] { get { return self.array ?? [] } } - + //Optional [AnyObject] - public var arrayObject: [AnyObject]? { + public var arrayObject: [Any]? { get { switch self.type { case .array: @@ -579,7 +581,7 @@ extension JSON { } set { if let array = newValue { - self.object = array + self.object = array as Any } else { self.object = NSNull() } @@ -590,12 +592,12 @@ extension JSON { // MARK: - Dictionary extension JSON { - + //Optional [String : JSON] public var dictionary: [String : JSON]? { if self.type == .dictionary { - - return self.rawDictionary.reduce([String : JSON]()) { (dictionary: [String : JSON], element: (String, AnyObject)) -> [String : JSON] in + + return self.rawDictionary.reduce([String : JSON]()) { (dictionary: [String : JSON], element: (String, Any)) -> [String : JSON] in var d = dictionary d[element.0] = JSON(element.1) return d @@ -604,14 +606,14 @@ extension JSON { return nil } } - + //Non-optional [String : JSON] public var dictionaryValue: [String : JSON] { return self.dictionary ?? [:] } - + //Optional [String : AnyObject] - public var dictionaryObject: [String : AnyObject]? { + public var dictionaryObject: [String : Any]? { get { switch self.type { case .dictionary: @@ -622,7 +624,7 @@ extension JSON { } set { if let v = newValue { - self.object = v + self.object = v as Any } else { self.object = NSNull() } @@ -632,39 +634,43 @@ extension JSON { // MARK: - Bool -extension JSON: Swift.Boolean { - +extension JSON { // : Swift.Bool + //Optional bool public var bool: Bool? { get { switch self.type { case .bool: - return self.rawNumber.boolValue + return self.rawBool default: return nil } } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + self.object = newValue as Bool } else { self.object = NSNull() } } } - + //Non-optional bool public var boolValue: Bool { get { switch self.type { - case .bool, .number, .string: - return self.object.boolValue + case .bool: + return self.rawBool + case .number: + return self.rawNumber.boolValue + case .string: + return self.rawString.caseInsensitiveCompare("true") == .orderedSame default: return false } } set { - self.object = NSNumber(value: newValue) + self.object = newValue } } } @@ -672,7 +678,7 @@ extension JSON: Swift.Boolean { // MARK: - String extension JSON { - + //Optional string public var string: String? { get { @@ -691,7 +697,7 @@ extension JSON { } } } - + //Non-optional string public var stringValue: String { get { @@ -699,7 +705,7 @@ extension JSON { case .string: return self.object as? String ?? "" case .number: - return self.object.stringValue + return self.rawNumber.stringValue case .bool: return (self.object as? Bool).map { String($0) } ?? "" default: @@ -714,13 +720,15 @@ extension JSON { // MARK: - Number extension JSON { - + //Optional number public var number: NSNumber? { get { switch self.type { - case .number, .bool: + case .number: return self.rawNumber + case .bool: + return NSNumber(value: self.rawBool ? 1 : 0) default: return nil } @@ -729,19 +737,21 @@ extension JSON { self.object = newValue ?? NSNull() } } - + //Non-optional number public var numberValue: NSNumber { get { switch self.type { case .string: let decimal = NSDecimalNumber(string: self.object as? String) - if decimal == NSDecimalNumber.notANumber() { // indicates parse error - return NSDecimalNumber.zero() + if decimal == NSDecimalNumber.notANumber { // indicates parse error + return NSDecimalNumber.zero } return decimal - case .number, .bool: + case .number: return self.object as? NSNumber ?? NSNumber(value: 0) + case .bool: + return NSNumber(value: self.rawBool ? 1 : 0) default: return NSNumber(value: 0.0) } @@ -754,7 +764,7 @@ extension JSON { //MARK: - Null extension JSON { - + public var null: NSNull? { get { switch self.type { @@ -769,7 +779,7 @@ extension JSON { } } public func exists() -> Bool{ - if let errorValue = error where errorValue.code == ErrorNotExist{ + if let errorValue = error , errorValue.code == ErrorNotExist{ return false } return true @@ -778,14 +788,14 @@ extension JSON { //MARK: - URL extension JSON { - + //Optional URL - public var URL: Foundation.URL? { + public var URL: NSURL? { get { switch self.type { case .string: if let encodedString_ = self.rawString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { - return Foundation.URL(string: encodedString_) + return NSURL(string: encodedString_) } else { return nil } @@ -794,7 +804,7 @@ extension JSON { } } set { - self.object = newValue?.absoluteString ?? NSNull() + self.object = newValue?.absoluteString } } } @@ -802,7 +812,7 @@ extension JSON { // MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 extension JSON { - + public var double: Double? { get { return self.number?.doubleValue @@ -815,7 +825,7 @@ extension JSON { } } } - + public var doubleValue: Double { get { return self.numberValue.doubleValue @@ -824,7 +834,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var float: Float? { get { return self.number?.floatValue @@ -837,7 +847,7 @@ extension JSON { } } } - + public var floatValue: Float { get { return self.numberValue.floatValue @@ -846,7 +856,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int: Int? { get { return self.number?.intValue @@ -859,7 +869,7 @@ extension JSON { } } } - + public var intValue: Int { get { return self.numberValue.intValue @@ -868,7 +878,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt: UInt? { get { return self.number?.uintValue @@ -881,7 +891,7 @@ extension JSON { } } } - + public var uIntValue: UInt { get { return self.numberValue.uintValue @@ -890,7 +900,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int8: Int8? { get { return self.number?.int8Value @@ -903,7 +913,7 @@ extension JSON { } } } - + public var int8Value: Int8 { get { return self.numberValue.int8Value @@ -912,7 +922,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt8: UInt8? { get { return self.number?.uint8Value @@ -925,7 +935,7 @@ extension JSON { } } } - + public var uInt8Value: UInt8 { get { return self.numberValue.uint8Value @@ -934,7 +944,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int16: Int16? { get { return self.number?.int16Value @@ -947,7 +957,7 @@ extension JSON { } } } - + public var int16Value: Int16 { get { return self.numberValue.int16Value @@ -956,7 +966,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt16: UInt16? { get { return self.number?.uint16Value @@ -969,7 +979,7 @@ extension JSON { } } } - + public var uInt16Value: UInt16 { get { return self.numberValue.uint16Value @@ -978,7 +988,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int32: Int32? { get { return self.number?.int32Value @@ -991,7 +1001,7 @@ extension JSON { } } } - + public var int32Value: Int32 { get { return self.numberValue.int32Value @@ -1000,7 +1010,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt32: UInt32? { get { return self.number?.uint32Value @@ -1013,7 +1023,7 @@ extension JSON { } } } - + public var uInt32Value: UInt32 { get { return self.numberValue.uint32Value @@ -1022,7 +1032,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int64: Int64? { get { return self.number?.int64Value @@ -1035,7 +1045,7 @@ extension JSON { } } } - + public var int64Value: Int64 { get { return self.numberValue.int64Value @@ -1044,7 +1054,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt64: UInt64? { get { return self.number?.uint64Value @@ -1057,7 +1067,7 @@ extension JSON { } } } - + public var uInt64Value: UInt64 { get { return self.numberValue.uint64Value @@ -1072,14 +1082,14 @@ extension JSON { extension JSON : Swift.Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber == rhs.rawNumber case (.string, .string): return lhs.rawString == rhs.rawString case (.bool, .bool): - return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue + return lhs.rawBool == rhs.rawBool case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray case (.dictionary, .dictionary): @@ -1092,14 +1102,14 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { } public func <=(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber <= rhs.rawNumber case (.string, .string): return lhs.rawString <= rhs.rawString case (.bool, .bool): - return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue + return lhs.rawBool == rhs.rawBool case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray case (.dictionary, .dictionary): @@ -1112,14 +1122,14 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { } public func >=(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber >= rhs.rawNumber case (.string, .string): return lhs.rawString >= rhs.rawString case (.bool, .bool): - return lhs.rawNumber.boolValue == rhs.rawNumber.boolValue + return lhs.rawBool == rhs.rawBool case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray case (.dictionary, .dictionary): @@ -1132,7 +1142,7 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { } public func >(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber > rhs.rawNumber @@ -1144,7 +1154,7 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { } public func <(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber < rhs.rawNumber @@ -1168,7 +1178,7 @@ extension NSNumber { let objCType = String(cString: self.objCType) if (self.compare(trueNumber) == ComparisonResult.orderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == ComparisonResult.orderedSame && objCType == falseObjCType){ - return true + return true } else { return false } @@ -1192,7 +1202,7 @@ func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { } func <(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1204,7 +1214,7 @@ func <(lhs: NSNumber, rhs: NSNumber) -> Bool { } func >(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1216,7 +1226,7 @@ func >(lhs: NSNumber, rhs: NSNumber) -> Bool { } func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1228,7 +1238,7 @@ func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { } func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index fd462c5e..12b03233 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -31,7 +31,7 @@ class BaseTests: XCTestCase { super.setUp() - if let file = Bundle(for:BaseTests.self).pathForResource("Tests", ofType: "json") { + if let file = Bundle(for:BaseTests.self).path(forResource: "Tests", ofType: "json") { self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { XCTFail("Can't find the test JSON file") @@ -52,7 +52,7 @@ class BaseTests: XCTestCase { dictionary.setObject(NSNull(), forKey: "null" as NSString) _ = JSON(dictionary) do { - let object: AnyObject = try JSONSerialization.jsonObject(with: self.testData, options: []) + let object: Any = try JSONSerialization.jsonObject(with: self.testData, options: []) let json2 = JSON(object) XCTAssertEqual(json0, json2) } catch _ { @@ -122,13 +122,13 @@ class BaseTests: XCTestCase { let user_name = user["name"].string let user_profile_image_url = user["profile_image_url"].URL XCTAssert(user_name == "OAuth Dancer") - XCTAssert(user_profile_image_url == URL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) + XCTAssert(user_profile_image_url == NSURL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) let user_dictionary = json[0]["user"].dictionary let user_dictionary_name = user_dictionary?["name"]?.string let user_dictionary_name_profile_image_url = user_dictionary?["profile_image_url"]?.URL XCTAssert(user_dictionary_name == "OAuth Dancer") - XCTAssert(user_dictionary_name_profile_image_url == URL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) + XCTAssert(user_dictionary_name_profile_image_url == NSURL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) } func testJSONNumberCompare() { diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index 84d110d3..12074ed3 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -26,7 +26,7 @@ import SwiftyJSON class DictionaryTests: XCTestCase { func testGetter() { - let dictionary = ["number":9823.212, "name":"NAME", "list":[1234, 4.212], "object":["sub_number":877.2323, "sub_name":"sub_name"], "bool":true] + let dictionary = ["number":9823.212, "name":"NAME", "list":[1234, 4.212], "object":["sub_number":877.2323, "sub_name":"sub_name"], "bool":true] as [String : Any] let json = JSON(dictionary) //dictionary XCTAssertEqual((json.dictionary!["number"]! as JSON).double!, 9823.212) diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift index ecbfb3fc..1f6cf031 100644 --- a/Tests/LiteralConvertibleTests.swift +++ b/Tests/LiteralConvertibleTests.swift @@ -53,7 +53,7 @@ class LiteralConvertibleTests: XCTestCase { func testNil() { let jsonNil_1:JSON = nil XCTAssert(jsonNil_1 == nil) - let jsonNil_2:JSON = JSON(NSNull) + let jsonNil_2:JSON = JSON(NSNull.self) XCTAssert(jsonNil_2 != nil) let jsonNil_3:JSON = JSON([1:2]) XCTAssert(jsonNil_3 != nil) diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index 8e19517b..e578bf83 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -22,6 +22,7 @@ import XCTest import SwiftyJSON + class NumberTests: XCTestCase { func testNumber() { @@ -327,7 +328,7 @@ class NumberTests: XCTestCase { } func testUInt32() { - let n2147483648 = NSNumber(value: 2147483648) + let n2147483648 = NSNumber(value: 2147483648 as UInt32) var json = JSON(n2147483648) XCTAssertTrue(json.uInt32! == n2147483648.uint32Value) XCTAssertTrue(json.uInt32Value == n2147483648.uint32Value) @@ -335,7 +336,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, n2147483648) XCTAssertEqual(json.stringValue, "2147483648") - let n32767 = NSNumber(value: 32767) + let n32767 = NSNumber(value: 32767 as UInt32) json.uInt32 = n32767.uint32Value XCTAssertTrue(json.uInt32! == n32767.uint32Value) XCTAssertTrue(json.uInt32Value == n32767.uint32Value) @@ -343,7 +344,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - let n0 = NSNumber(value: 0) + let n0 = NSNumber(value: 0 as UInt32) json.uInt32Value = n0.uint32Value XCTAssertTrue(json.uInt32! == n0.uint32Value) XCTAssertTrue(json.uInt32Value == n0.uint32Value) diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index 18a10ea1..21b9b31f 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -30,7 +30,7 @@ class PerformanceTests: XCTestCase { override func setUp() { super.setUp() - if let file = Bundle(for:PerformanceTests.self).pathForResource("Tests", ofType: "json") { + if let file = Bundle(for:PerformanceTests.self).path(forResource: "Tests", ofType: "json") { self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { XCTFail("Can't find the test JSON file") @@ -52,10 +52,10 @@ class PerformanceTests: XCTestCase { } func testObjectMethodPerformance() { - var json = JSON(data:self.testData) + let json = JSON(data:self.testData) self.measure() { for _ in 1...100 { - let object:AnyObject? = json.object + let object:Any? = json.object XCTAssertTrue(object != nil) } } @@ -66,8 +66,9 @@ class PerformanceTests: XCTestCase { self.measure() { for _ in 1...100 { autoreleasepool{ - let array = json.array - XCTAssertTrue(array?.count > 0) + if let array = json.array { + XCTAssertTrue(array.count > 0) + } } } } @@ -78,8 +79,9 @@ class PerformanceTests: XCTestCase { self.measure() { for _ in 1...100 { autoreleasepool{ - let dictionary = json.dictionary - XCTAssertTrue(dictionary?.count > 0) + if let dictionary = json.dictionary { + XCTAssertTrue(dictionary.count > 0) + } } } } diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index 72448288..e9d38811 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -68,8 +68,8 @@ class PrintableTests: XCTestCase { var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) - XCTAssertTrue(debugDescription.range(of: "\"1\":2", options: NSString.CompareOptions.caseInsensitiveSearch) != nil) - XCTAssertTrue(debugDescription.range(of: "\"2\":\"two\"", options: NSString.CompareOptions.caseInsensitiveSearch) != nil) - XCTAssertTrue(debugDescription.range(of: "\"3\":3", options: NSString.CompareOptions.caseInsensitiveSearch) != nil) + XCTAssertTrue(debugDescription.range(of: "\"1\":2", options: String.CompareOptions.caseInsensitive) != nil) + XCTAssertTrue(debugDescription.range(of: "\"2\":\"two\"", options: String.CompareOptions.caseInsensitive) != nil) + XCTAssertTrue(debugDescription.range(of: "\"3\":3", options: String.CompareOptions.caseInsensitive) != nil) } } diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index e9412481..c4e79258 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -34,7 +34,7 @@ class RawRepresentableTests: XCTestCase { XCTAssertTrue(json.float! == 948394394.347384) XCTAssertTrue(json.floatValue == 948394394.347384) - let object: AnyObject = json.rawValue + let object: Any = json.rawValue XCTAssertEqual(object as? Int, 948394394) XCTAssertEqual(object as? Double, 948394394.347384) XCTAssertTrue(object as! Float == 948394394.347384) @@ -50,17 +50,11 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(jsonFalse.bool!, false) XCTAssertEqual(jsonFalse.boolValue, false) - let objectTrue: AnyObject = jsonTrue.rawValue - XCTAssertEqual(objectTrue as? Int, 1) - XCTAssertEqual(objectTrue as? Double, 1.0) + let objectTrue = jsonTrue.rawValue XCTAssertEqual(objectTrue as? Bool, true) - XCTAssertEqual(objectTrue as? NSNumber, NSNumber(value: true)) - let objectFalse: AnyObject = jsonFalse.rawValue - XCTAssertEqual(objectFalse as? Int, 0) - XCTAssertEqual(objectFalse as? Double, 0.0) + let objectFalse = jsonFalse.rawValue XCTAssertEqual(objectFalse as? Bool, false) - XCTAssertEqual(objectFalse as? NSNumber, NSNumber(value: false)) } func testString() { @@ -78,7 +72,7 @@ class RawRepresentableTests: XCTestCase { XCTFail("Should not run into here") } - let object: AnyObject = JSON(rawValue: string)!.rawValue + let object: Any = JSON(rawValue: string)!.rawValue XCTAssertEqual(object as? String, string) } @@ -94,7 +88,7 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(json, JSON(array)) } - let object: AnyObject = JSON(rawValue: array)!.rawValue + let object: Any = JSON(rawValue: array)!.rawValue XCTAssertTrue(array == object as! NSArray) } @@ -104,7 +98,7 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(json, JSON(dictionary)) } - let object: AnyObject = JSON(rawValue: dictionary)!.rawValue + let object: Any = JSON(rawValue: dictionary)!.rawValue XCTAssertTrue(dictionary == object as! NSDictionary) } } diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index 904b90b3..3aae1c19 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -27,7 +27,7 @@ import SwiftyJSON class SequenceTypeTests: XCTestCase { func testJSONFile() { - if let file = Bundle(for:BaseTests.self).pathForResource("Tests", ofType: "json") { + if let file = Bundle(for:BaseTests.self).path(forResource: "Tests", ofType: "json") { let testData = try? Data(contentsOf: URL(fileURLWithPath: file)) let json = JSON(data:testData!) for (index, sub) in json { @@ -104,7 +104,7 @@ class SequenceTypeTests: XCTestCase { for (i, sub) in json { XCTAssertEqual(sub, json[index]) XCTAssertEqual(i, "\(index)") - array.append(sub.object) + array.append(sub.object as AnyObject) index += 1 } XCTAssertEqual(index, 4) @@ -121,7 +121,7 @@ class SequenceTypeTests: XCTestCase { for (i, sub) in json { XCTAssertEqual(sub, json[index]) XCTAssertEqual(i, "\(index)") - array.append(sub.object) + array.append(sub.object as AnyObject) index += 1 } XCTAssertEqual(index, 3) @@ -191,7 +191,7 @@ class SequenceTypeTests: XCTestCase { var dictionary = [String:AnyObject]() for (key, sub) in json { XCTAssertEqual(sub, json[key]) - dictionary[key] = sub.object + dictionary[key] = sub.object as AnyObject? index += 1 } @@ -210,7 +210,7 @@ class SequenceTypeTests: XCTestCase { var dictionary = [String:AnyObject]() for (key, sub) in json { XCTAssertEqual(sub, json[key]) - dictionary[key] = sub.object + dictionary[key] = sub.object as AnyObject? index += 1 } diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index 8e720be4..e79992cc 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -38,7 +38,7 @@ class StringTests: XCTestCase { func testURL() { let json = JSON("http://github.com") - XCTAssertEqual(json.URL!, URL(string:"http://github.com")!) + XCTAssertEqual(json.URL!, NSURL(string:"http://github.com")!) } func testURLPercentEscapes() { @@ -46,6 +46,6 @@ class StringTests: XCTestCase { let urlString = "http://examble.com/unencoded" + emDash + "string" let encodedURLString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) let json = JSON(urlString) - XCTAssertEqual(json.URL!, URL(string: encodedURLString!)!, "Wrong unpacked ") + XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!)!, "Wrong unpacked ") } } From e20cbab49fc0f67c6a8dcfbf4c370b905506bce5 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 21 Sep 2016 22:09:33 +0800 Subject: [PATCH 244/470] Update readme file for swift3 --- README.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5c983cc5..492f1e29 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ #SwiftyJSON - + [![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) SwiftyJSON makes it easy to deal with JSON data in Swift. 1. [Why is the typical JSON handling in Swift NOT good](#why-is-the-typical-json-handling-in-swift-not-good) -1. [Requirements](#requirements) -1. [Integration](#integration) -1. [Usage](#usage) - - [Initialization](#initialization) - - [Subscript](#subscript) - - [Loop](#loop) - - [Error](#error) - - [Optional getter](#optional-getter) - - [Non-optional getter](#non-optional-getter) - - [Setter](#setter) - - [Raw object](#raw-object) - - [Literal convertibles](#literal-convertibles) -1. [Work with Alamofire](#work-with-alamofire) - -> For Swift3 support, take a look at the [swift3 beta branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift3) +2. [Requirements](#requirements) +3. [Integration](#integration) +4. [Usage](#usage) + - [Initialization](#initialization) + - [Subscript](#subscript) + - [Loop](#loop) + - [Error](#error) + - [Optional getter](#optional-getter) + - [Non-optional getter](#non-optional-getter) + - [Setter](#setter) + - [Raw object](#raw-object) + - [Literal convertibles](#literal-convertibles) +5. [Work with Alamofire](#work-with-alamofire) + +> For Legacy Swift support, take a look at the [swift2 branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift2) > [中文介绍](http://tangplin.github.io/swiftyjson/) @@ -83,7 +83,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { ## Requirements - iOS 7.0+ / OS X 10.9+ -- Xcode 7 +- Xcode 8 ##Integration From f6d8c921034c58e19bc34b6aa5d0d3f9c345e3f1 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 21 Sep 2016 22:16:21 +0800 Subject: [PATCH 245/470] Update pod version --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 1a9d29dd..335ca965 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "2.3.2" + s.version = "3.0.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From c8a6bda9aa0e823b4c0ec1e74f19869d77c4bed4 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 21 Sep 2016 22:19:34 +0800 Subject: [PATCH 246/470] Add .swift-version --- .swift-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 00000000..9f55b2cc --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +3.0 From 87dae80939b9163cc2b2a5d90215a6e8e133bebe Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 21 Sep 2016 22:41:26 +0800 Subject: [PATCH 247/470] Set APPLICATION_EXTENSION_API_ONLY to yes for macOS target from https://github.com/SwiftyJSON/SwiftyJSON/pull/616 --- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 37c8464c..d8c3a749 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -847,6 +847,7 @@ 9C7DFC6F1A9102BD005AA3F7 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; @@ -873,6 +874,7 @@ 9C7DFC701A9102BD005AA3F7 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; From 497e8eb9f350c7af41f425274a1a3afef724d79a Mon Sep 17 00:00:00 2001 From: Lukas Zielinski Date: Wed, 21 Sep 2016 17:29:41 +0200 Subject: [PATCH 248/470] Update NSErrorPointer usage in initializer. --- Source/SwiftyJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 26180fec..12e796d9 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -65,13 +65,13 @@ public struct JSON { - returns: The created JSON */ - public init(data:Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer? = nil) { + public init(data:Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer = nil) { do { let object: Any = try JSONSerialization.jsonObject(with: data, options: opt) self.init(object) } catch let aError as NSError { if error != nil { - error??.pointee = aError + error?.pointee = aError } self.init(NSNull()) } From 1090ce6299d32479be7a5321926991277a923bb2 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 21 Sep 2016 23:58:52 +0800 Subject: [PATCH 249/470] Update code signing change to fix .travisCI --- SwiftyJSON.xcodeproj/project.pbxproj | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index d8c3a749..6f5c58f4 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -431,6 +431,7 @@ 2E4FEFE519575BE100351305 = { CreatedOnToolsVersion = 6.0; LastSwiftMigration = 0800; + ProvisioningStyle = Manual; TestTargetID = 2E4FEFDA19575BE100351305; }; 9C7DFC5A1A9102BD005AA3F7 = { @@ -735,8 +736,6 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -756,8 +755,6 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - CODE_SIGN_IDENTITY = ""; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -775,6 +772,8 @@ 2E4FEFF519575BE100351305 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = ""; + DEVELOPMENT_TEAM = ""; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -791,6 +790,8 @@ 2E4FEFF619575BE100351305 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = ""; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = "Tests/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -933,6 +934,7 @@ A8580F7D1BCF5C5B00DA927B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = ""; DEBUG_INFORMATION_FORMAT = dwarf; GCC_NO_COMMON_BLOCKS = YES; INFOPLIST_FILE = "Tests/Info-tvOS.plist"; @@ -948,6 +950,7 @@ A8580F7E1BCF5C5B00DA927B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_IDENTITY = ""; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_NO_COMMON_BLOCKS = YES; From e7729f35da2fad24f2ea9e036207aaf39e2ef2e3 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 22 Sep 2016 00:05:24 +0800 Subject: [PATCH 250/470] Fix example app in xcode 8 --- Example/Example.xcodeproj/project.pbxproj | 132 +--------------------- 1 file changed, 6 insertions(+), 126 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 44393c89..717e1606 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 04733F521D92E6ED002E3A99 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04733F511D92E6ED002E3A99 /* SwiftyJSON.framework */; }; + 04733F531D92E6ED002E3A99 /* SwiftyJSON.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 04733F511D92E6ED002E3A99 /* SwiftyJSON.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A82A1C1F19D926B8009A653D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C1E19D926B8009A653D /* AppDelegate.swift */; }; A82A1C2419D926B8009A653D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2219D926B8009A653D /* Main.storyboard */; }; A82A1C2619D926B8009A653D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A82A1C2519D926B8009A653D /* Images.xcassets */; }; @@ -15,58 +17,6 @@ A82A1C5619D95606009A653D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A82A1C5519D95606009A653D /* ViewController.swift */; }; /* End PBXBuildFile section */ -/* Begin PBXContainerItemProxy section */ - 04294C581BE5A9DE00D0397E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = E4D7CCE81B9465A700EE7221; - remoteInfo = "SwiftyJSON watchOS"; - }; - 04294C5A1BE5A9DE00D0397E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 7236B4F61BAC14150020529B; - remoteInfo = "SwiftyJSON tvOS"; - }; - 04294C5C1BE5A9DE00D0397E /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = A8580F741BCF5C5B00DA927B; - remoteInfo = "SwiftyJSON tvOS Tests"; - }; - A8BF45AA1B871E100066C032 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFDB19575BE100351305; - remoteInfo = "SwiftyJSON iOS"; - }; - A8BF45AC1B871E100066C032 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 2E4FEFE619575BE100351305; - remoteInfo = "SwiftyJSON iOS Tests"; - }; - A8BF45AE1B871E100066C032 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9C7DFC5B1A9102BD005AA3F7; - remoteInfo = "SwiftyJSON OSX"; - }; - A8BF45B01B871E100066C032 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - proxyType = 2; - remoteGlobalIDString = 9C7DFC651A9102BD005AA3F7; - remoteInfo = "SwiftyJSON OSX Tests"; - }; -/* End PBXContainerItemProxy section */ - /* Begin PBXCopyFilesBuildPhase section */ A82A1C5419D94E97009A653D /* Embed Frameworks */ = { isa = PBXCopyFilesBuildPhase; @@ -74,6 +24,7 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( + 04733F531D92E6ED002E3A99 /* SwiftyJSON.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -82,6 +33,7 @@ /* Begin PBXFileReference section */ 04294C501BE5A9DE00D0397E /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = ""; }; + 04733F511D92E6ED002E3A99 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A82A1C1919D926B8009A653D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; A82A1C1D19D926B8009A653D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A82A1C1E19D926B8009A653D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -89,7 +41,6 @@ A82A1C2519D926B8009A653D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; A82A1C2819D926B8009A653D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; A82A1C3F19D94AE5009A653D /* SwiftyJSONTests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = SwiftyJSONTests.json; sourceTree = ""; }; - A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = SwiftyJSON.xcodeproj; path = ../SwiftyJSON.xcodeproj; sourceTree = ""; }; A82A1C5519D95606009A653D /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ @@ -98,6 +49,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 04733F521D92E6ED002E3A99 /* SwiftyJSON.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -107,8 +59,8 @@ A82A1C1019D926B8009A653D = { isa = PBXGroup; children = ( + 04733F511D92E6ED002E3A99 /* SwiftyJSON.framework */, 04294C501BE5A9DE00D0397E /* Playground.playground */, - A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */, A82A1C1B19D926B8009A653D /* Example */, A82A1C1A19D926B8009A653D /* Products */, ); @@ -144,20 +96,6 @@ name = "Supporting Files"; sourceTree = ""; }; - A8BF45A41B871E0F0066C032 /* Products */ = { - isa = PBXGroup; - children = ( - A8BF45AB1B871E100066C032 /* SwiftyJSON.framework */, - A8BF45AD1B871E100066C032 /* SwiftyJSON iOS Tests.xctest */, - A8BF45AF1B871E100066C032 /* SwiftyJSON.framework */, - A8BF45B11B871E100066C032 /* SwiftyJSON OSX Tests.xctest */, - 04294C591BE5A9DE00D0397E /* SwiftyJSON.framework */, - 04294C5B1BE5A9DE00D0397E /* SwiftyJSON.framework */, - 04294C5D1BE5A9DE00D0397E /* SwiftyJSON tvOS Tests.xctest */, - ); - name = Products; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -207,12 +145,6 @@ mainGroup = A82A1C1019D926B8009A653D; productRefGroup = A82A1C1A19D926B8009A653D /* Products */; projectDirPath = ""; - projectReferences = ( - { - ProductGroup = A8BF45A41B871E0F0066C032 /* Products */; - ProjectRef = A82A1C4719D94E86009A653D /* SwiftyJSON.xcodeproj */; - }, - ); projectRoot = ""; targets = ( A82A1C1819D926B8009A653D /* Example */, @@ -220,58 +152,6 @@ }; /* End PBXProject section */ -/* Begin PBXReferenceProxy section */ - 04294C591BE5A9DE00D0397E /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = 04294C581BE5A9DE00D0397E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 04294C5B1BE5A9DE00D0397E /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = 04294C5A1BE5A9DE00D0397E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - 04294C5D1BE5A9DE00D0397E /* SwiftyJSON tvOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON tvOS Tests.xctest"; - remoteRef = 04294C5C1BE5A9DE00D0397E /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8BF45AB1B871E100066C032 /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = A8BF45AA1B871E100066C032 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8BF45AD1B871E100066C032 /* SwiftyJSON iOS Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON iOS Tests.xctest"; - remoteRef = A8BF45AC1B871E100066C032 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8BF45AF1B871E100066C032 /* SwiftyJSON.framework */ = { - isa = PBXReferenceProxy; - fileType = wrapper.framework; - path = SwiftyJSON.framework; - remoteRef = A8BF45AE1B871E100066C032 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; - A8BF45B11B871E100066C032 /* SwiftyJSON OSX Tests.xctest */ = { - isa = PBXReferenceProxy; - fileType = wrapper.cfbundle; - path = "SwiftyJSON OSX Tests.xctest"; - remoteRef = A8BF45B01B871E100066C032 /* PBXContainerItemProxy */; - sourceTree = BUILT_PRODUCTS_DIR; - }; -/* End PBXReferenceProxy section */ - /* Begin PBXResourcesBuildPhase section */ A82A1C1719D926B8009A653D /* Resources */ = { isa = PBXResourcesBuildPhase; From 78fb8311bab86bacbeb8a9d9f5afe75c15eaea54 Mon Sep 17 00:00:00 2001 From: James C Date: Thu, 12 May 2016 08:36:17 -0400 Subject: [PATCH 251/470] Add checks on exists method for errors - Check for out of bounds error on exists method - Check for wrong type error on exists method - Add tests for cases where out of bounds and wrong type errors occur --- Source/SwiftyJSON.swift | 6 ++++-- Tests/BaseTests.swift | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 12e796d9..2c7f718d 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -779,8 +779,10 @@ extension JSON { } } public func exists() -> Bool{ - if let errorValue = error , errorValue.code == ErrorNotExist{ - return false + if let errorValue = error, errorValue.code == ErrorNotExist || + errorValue.code == ErrorIndexOutOfBounds || + errorValue.code == ErrorWrongType { + return false } return true } diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 12b03233..2ce24a4b 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -214,7 +214,14 @@ class BaseTests: XCTestCase { let dictionary = ["number":1111] let json = JSON(dictionary) XCTAssertFalse(json["unspecifiedValue"].exists()) + XCTAssertFalse(json[0].exists()) XCTAssertTrue(json["number"].exists()) + + let array = [["number":1111]] + let jsonForArray = JSON(array) + XCTAssertTrue(jsonForArray[0].exists()) + XCTAssertFalse(jsonForArray[1].exists()) + XCTAssertFalse(jsonForArray["someValue"].exists()) } func testErrorHandle() { From 46e888a19fae39e2a23b780dec808e3e15bf76d0 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 22 Sep 2016 13:15:47 +0800 Subject: [PATCH 252/470] Fix travis CI --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9d896ba4..14a93dd0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,4 +3,6 @@ language: objective-c osx_image: xcode8 xcode_sdk: iphonesimulator10.0 -script: 'sh scripts/ci.sh' +script: + - rvm get head # https://github.com/travis-ci/travis-ci/issues/6307 + - 'sh scripts/ci.sh' From 5e29a8b86c5763d95fa0b207319d5c735d37df01 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 22 Sep 2016 13:31:20 +0800 Subject: [PATCH 253/470] Add cocoapods and platform badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e53998e..0b75b2da 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #SwiftyJSON -[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) +[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg)![Platform](https://img.shields.io/badge/platforms-iOS%20%7C%20OSX%20%7C%20tvOS%20%7C%20watchOS-333333.svg) SwiftyJSON makes it easy to deal with JSON data in Swift. From 995fe225e75febcb605412126a7203a7b38d2575 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 22 Sep 2016 13:37:23 +0800 Subject: [PATCH 254/470] Update min target for macOS to 10.10 Also update platform iOS and README --- README.md | 4 ++-- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b75b2da..085c4ee9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #SwiftyJSON -[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg)![Platform](https://img.shields.io/badge/platforms-iOS%20%7C%20OSX%20%7C%20tvOS%20%7C%20watchOS-333333.svg) +[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg)![Platform](https://img.shields.io/badge/platforms-iOS%208.0+%20%7C%20macOS%2010.10+%20%7C%20tvOS%209.0+%20%7C%20watchOS%202.0+-333333.svg) SwiftyJSON makes it easy to deal with JSON data in Swift. @@ -82,7 +82,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { ## Requirements -- iOS 7.0+ / OS X 10.9+ +- iOS 8.0+ | macOS 10.10+ | tvOS 9.0+ | watchOS 2.0+ - Xcode 8 ##Integration diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 6f5c58f4..4156ddf1 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -863,6 +863,7 @@ INFOPLIST_FILE = "Source/Info-OSX.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; PLIST_FILE_OUTPUT_FORMAT = binary; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; @@ -887,6 +888,7 @@ INFOPLIST_FILE = "Source/Info-OSX.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; PLIST_FILE_OUTPUT_FORMAT = binary; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; From 5c526116cf3945f3bc3679bd9ef94df71006b231 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 22 Sep 2016 13:41:24 +0800 Subject: [PATCH 255/470] Add spaces to badge icons --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 085c4ee9..891c0ead 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ #SwiftyJSON -[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg)![Platform](https://img.shields.io/badge/platforms-iOS%208.0+%20%7C%20macOS%2010.10+%20%7C%20tvOS%209.0+%20%7C%20watchOS%202.0+-333333.svg) +[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg) ![Platform](https://img.shields.io/badge/platforms-iOS%208.0+%20%7C%20macOS%2010.10+%20%7C%20tvOS%209.0+%20%7C%20watchOS%202.0+-333333.svg) SwiftyJSON makes it easy to deal with JSON data in Swift. From 0df304865c059bdf0b786eb01cfb1d1f8f16c729 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 22 Sep 2016 13:44:49 +0800 Subject: [PATCH 256/470] Fix test in macOS target --- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 4156ddf1..32ea7003 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -910,6 +910,7 @@ ); INFOPLIST_FILE = "Tests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -926,6 +927,7 @@ FRAMEWORK_SEARCH_PATHS = ""; INFOPLIST_FILE = "Tests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; From e953aa7d8796c0b114e07516f00698b8158247e0 Mon Sep 17 00:00:00 2001 From: Vijaya Prakash Kandel Date: Fri, 23 Sep 2016 07:43:08 +0200 Subject: [PATCH 257/470] Typos in Comments correction Added little more descriptive comment. --- Source/SwiftyJSON.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 12e796d9..bd33db6b 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -61,7 +61,7 @@ public struct JSON { - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - parameter opt: The JSON serialization reading options. `.AllowFragments` by default. - - parameter error: error The NSErrorPointer used to return the error. `nil` by default. + - parameter error: The NSErrorPointer used to return the error. `nil` by default. - returns: The created JSON */ @@ -78,14 +78,14 @@ public struct JSON { } /** - Create a JSON from JSON string + Creates a JSON from JSON string - parameter string: Normal json string like '{"a":"b"}' - returns: The created JSON */ public static func parse(_ string:String) -> JSON { return string.data(using: String.Encoding.utf8) - .flatMap({JSON(data: $0)}) ?? JSON(NSNull()) + .flatMap{ JSON(data: $0) } ?? JSON(NSNull()) } /** @@ -184,13 +184,13 @@ public struct JSON { } } - /// json type + /// JSON type public var type: Type { get { return _type } } /// Error in JSON public var error: NSError? { get { return self._error } } - /// The static null json + /// The static null JSON @available(*, unavailable, renamed:"null") public static var nullJSON: JSON { get { return null } } public static var null: JSON { get { return JSON(NSNull()) } } @@ -368,7 +368,7 @@ extension JSON { } /** - Find a json in the complex data structuresby using the Int/String's array. + Find a json in the complex data structures by using array of Int and/or String as path. - parameter path: The target json's path. Example: @@ -400,7 +400,7 @@ extension JSON { } /** - Find a json in the complex data structures by using the Int/String's array. + Find a json in the complex data structures by using array of Int and/or String as path. - parameter path: The target json's path. Example: From 21507827a7d81daccd08529b87230c6768b4e3c7 Mon Sep 17 00:00:00 2001 From: Aaron Pearce Date: Mon, 26 Sep 2016 13:17:55 +1300 Subject: [PATCH 258/470] Move from NSURL to URL --- Source/SwiftyJSON.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index bd33db6b..0b1eb3c4 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -790,12 +790,13 @@ extension JSON { extension JSON { //Optional URL - public var URL: NSURL? { + public var URL: URL? { get { switch self.type { case .string: if let encodedString_ = self.rawString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { - return NSURL(string: encodedString_) + // We have to use `Foundation.URL` otherwise it conflicts with the variable name. + return Foundation.URL(string: encodedString_) } else { return nil } From f6264e721048298ce66959f298a27aa09165efd3 Mon Sep 17 00:00:00 2001 From: Aaron Pearce Date: Mon, 26 Sep 2016 15:36:59 +1300 Subject: [PATCH 259/470] Fix the URL tests --- Tests/StringTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index e79992cc..8e720be4 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -38,7 +38,7 @@ class StringTests: XCTestCase { func testURL() { let json = JSON("http://github.com") - XCTAssertEqual(json.URL!, NSURL(string:"http://github.com")!) + XCTAssertEqual(json.URL!, URL(string:"http://github.com")!) } func testURLPercentEscapes() { @@ -46,6 +46,6 @@ class StringTests: XCTestCase { let urlString = "http://examble.com/unencoded" + emDash + "string" let encodedURLString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) let json = JSON(urlString) - XCTAssertEqual(json.URL!, NSURL(string: encodedURLString!)!, "Wrong unpacked ") + XCTAssertEqual(json.URL!, URL(string: encodedURLString!)!, "Wrong unpacked ") } } From c23d428a796ab554ccb936a4b3b426498fe5ee84 Mon Sep 17 00:00:00 2001 From: Aaron Pearce Date: Mon, 26 Sep 2016 15:38:25 +1300 Subject: [PATCH 260/470] Update BaseTests with new URL --- Tests/BaseTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 12b03233..ed7163a4 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -122,13 +122,13 @@ class BaseTests: XCTestCase { let user_name = user["name"].string let user_profile_image_url = user["profile_image_url"].URL XCTAssert(user_name == "OAuth Dancer") - XCTAssert(user_profile_image_url == NSURL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) + XCTAssert(user_profile_image_url == URL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) let user_dictionary = json[0]["user"].dictionary let user_dictionary_name = user_dictionary?["name"]?.string let user_dictionary_name_profile_image_url = user_dictionary?["profile_image_url"]?.URL XCTAssert(user_dictionary_name == "OAuth Dancer") - XCTAssert(user_dictionary_name_profile_image_url == NSURL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) + XCTAssert(user_dictionary_name_profile_image_url == URL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) } func testJSONNumberCompare() { From 197889498df0e5e79a8a474ad4124412efc03f36 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Mon, 26 Sep 2016 12:40:26 +0800 Subject: [PATCH 261/470] Fix infinite loop with JSON.null --- Source/SwiftyJSON.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 12e796d9..9ecec2db 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -208,6 +208,7 @@ public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { return left == right case (.dictionary(let left), .dictionary(let right)): return left == right + case (.null, .null): return true default: return false } From d075ce98e9c0cfe608a6ff1b28389527dc3cf718 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Mon, 26 Sep 2016 14:23:55 +0800 Subject: [PATCH 262/470] Update pod version for 3.1.0 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 335ca965..57c55b70 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "3.0.0" + s.version = "3.1.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From aba949498551d27829ab8b27ad9b21de08e5aef2 Mon Sep 17 00:00:00 2001 From: Sami Suteria Date: Mon, 26 Sep 2016 21:58:53 -0700 Subject: [PATCH 263/470] update readme with nested example --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 891c0ead..2c7f5709 100644 --- a/README.md +++ b/README.md @@ -386,6 +386,15 @@ json["list",3,"what"] = "that" let path = ["list",3,"what"] json[path] = "that" ``` +```swift +//With other JSON objects +let user: JSON = ["username" : "Steve", "password": "supersecurepassword"] +let auth: JSON = [ + "user": user.object //use user.object instead of just user + "apikey": "supersecretapitoken" +] +```` + ##Work with Alamofire SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: From 1c84dbe72cea0e979dd8608a5835638ebe7f6f13 Mon Sep 17 00:00:00 2001 From: Hector Matos Date: Tue, 27 Sep 2016 15:17:17 -0700 Subject: [PATCH 264/470] adds support for nested JSON in literals --- Source/SwiftyJSON.swift | 207 +++++++++++++++------------ SwiftyJSON.xcodeproj/project.pbxproj | 8 ++ Tests/NestedJSONTests.swift | 42 ++++++ 3 files changed, 168 insertions(+), 89 deletions(-) create mode 100644 Tests/NestedJSONTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index dd7c5ae8..bb4ddb52 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -34,6 +34,12 @@ public let ErrorWrongType: Int = 901 public let ErrorNotExist: Int = 500 public let ErrorInvalidJSON: Int = 490 +///Types +private let trueNumber = NSNumber(value: true) +private let falseNumber = NSNumber(value: false) +private let trueObjCType = String(cString: trueNumber.objCType) +private let falseObjCType = String(cString: falseNumber.objCType) + // MARK: - JSON Type /** @@ -52,8 +58,85 @@ public enum Type :Int{ case unknown } -// MARK: - JSON Base +// MARK: - NSNumber: Comparable +extension NSNumber { + var isBool:Bool { + get { + let objCType = String(cString: self.objCType) + if (self.compare(trueNumber) == ComparisonResult.orderedSame && objCType == trueObjCType) + || (self.compare(falseNumber) == ComparisonResult.orderedSame && objCType == falseObjCType){ + return true + } else { + return false + } + } + } +} + +func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) == ComparisonResult.orderedSame + } +} + +func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { + return !(lhs == rhs) +} +func <(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) == ComparisonResult.orderedAscending + } +} + +func >(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) == ComparisonResult.orderedDescending + } +} + +func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) != ComparisonResult.orderedDescending + } +} + +func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) != ComparisonResult.orderedAscending + } +} + +// MARK: - JSON Base public struct JSON { /** @@ -171,6 +254,9 @@ public struct JSON { self.rawString = string case _ as NSNull: _type = .null + case let array as [JSON]: + _type = .array + self.rawArray = array.map { $0.object } case let array as [Any]: _type = .array self.rawArray = array @@ -460,11 +546,38 @@ extension JSON: Swift.ExpressibleByFloatLiteral { } extension JSON: Swift.ExpressibleByDictionaryLiteral { - public init(dictionaryLiteral elements: (String, Any)...) { + let array = elements + self.init(dictionaryLiteral: array) + } + + public init(dictionaryLiteral elements: [(String, Any)]) { + let jsonFromDictionaryLiteral: ([String : Any]) -> JSON = { dictionary in + let initializeElement = Array(dictionary.keys).flatMap { key -> (String, Any)? in + if let value = dictionary[key] { + return (key, value) + } + return nil + } + return JSON(dictionaryLiteral: initializeElement) + } + self.init(elements.reduce([String : Any](minimumCapacity: elements.count)){(dictionary: [String : Any], element:(String, Any)) -> [String : Any] in var d = dictionary - d[element.0] = element.1 + let elementToSet: Any + if let json = element.1 as? JSON { + elementToSet = json.object + } else if let jsonArray = element.1 as? [JSON] { + elementToSet = JSON(jsonArray).object + } else if let dictionary = element.1 as? [String : Any] { + elementToSet = jsonFromDictionaryLiteral(dictionary).object + } else if let dictArray = element.1 as? [[String : Any]] { + let jsonArray = dictArray.map { jsonFromDictionaryLiteral($0) } + elementToSet = JSON(jsonArray).object + } else { + elementToSet = element.1 + } + d[element.0] = elementToSet return d } as Any) } @@ -783,7 +896,7 @@ extension JSON { if let errorValue = error, errorValue.code == ErrorNotExist || errorValue.code == ErrorIndexOutOfBounds || errorValue.code == ErrorWrongType { - return false + return false } return true } @@ -935,7 +1048,7 @@ extension JSON { if let newValue = newValue { self.object = NSNumber(value: newValue) } else { - self.object = NSNull() + self.object = NSNull() } } } @@ -1168,87 +1281,3 @@ public func <(lhs: JSON, rhs: JSON) -> Bool { return false } } - -private let trueNumber = NSNumber(value: true) -private let falseNumber = NSNumber(value: false) -private let trueObjCType = String(cString: trueNumber.objCType) -private let falseObjCType = String(cString: falseNumber.objCType) - -// MARK: - NSNumber: Comparable - -extension NSNumber { - var isBool:Bool { - get { - let objCType = String(cString: self.objCType) - if (self.compare(trueNumber) == ComparisonResult.orderedSame && objCType == trueObjCType) - || (self.compare(falseNumber) == ComparisonResult.orderedSame && objCType == falseObjCType){ - return true - } else { - return false - } - } - } -} - -func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == ComparisonResult.orderedSame - } -} - -func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { - return !(lhs == rhs) -} - -func <(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == ComparisonResult.orderedAscending - } -} - -func >(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == ComparisonResult.orderedDescending - } -} - -func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) != ComparisonResult.orderedDescending - } -} - -func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) != ComparisonResult.orderedAscending - } -} diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 32ea7003..0b4bd070 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; + 5DD502911D9B21810004C112 /* NestedJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD502901D9B21810004C112 /* NestedJSONTests.swift */; }; + 5DD502921D9B21810004C112 /* NestedJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD502901D9B21810004C112 /* NestedJSONTests.swift */; }; + 5DD502931D9B21810004C112 /* NestedJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD502901D9B21810004C112 /* NestedJSONTests.swift */; }; 7236B4EE1BAC14150020529B /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; 7236B4F11BAC14150020529B /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9C459EF41A910334008C9A41 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -92,6 +95,7 @@ 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 5DD502901D9B21810004C112 /* NestedJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedJSONTests.swift; sourceTree = ""; }; 7236B4F61BAC14150020529B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; @@ -225,6 +229,7 @@ A885D1DA19CFCFF0002FD4C3 /* Tests.json */, A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */, A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */, + 5DD502901D9B21810004C112 /* NestedJSONTests.swift */, A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */, A819C4A019E37FC600ADCC3D /* PrintableTests.swift */, A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */, @@ -538,6 +543,7 @@ files = ( A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */, A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */, + 5DD502911D9B21810004C112 /* NestedJSONTests.swift in Sources */, A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */, A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, @@ -574,6 +580,7 @@ files = ( 9C459EFB1A9103C1008C9A41 /* SequenceTypeTests.swift in Sources */, 9C459F001A9103C1008C9A41 /* ComparableTests.swift in Sources */, + 5DD502921D9B21810004C112 /* NestedJSONTests.swift in Sources */, 9C459F021A9103C1008C9A41 /* NumberTests.swift in Sources */, 9C459EFF1A9103C1008C9A41 /* RawRepresentableTests.swift in Sources */, 9C459EFA1A9103C1008C9A41 /* BaseTests.swift in Sources */, @@ -594,6 +601,7 @@ files = ( A8580F801BCF69A000DA927B /* PerformanceTests.swift in Sources */, A8580F811BCF69A000DA927B /* BaseTests.swift in Sources */, + 5DD502931D9B21810004C112 /* NestedJSONTests.swift in Sources */, A8580F821BCF69A000DA927B /* SequenceTypeTests.swift in Sources */, A8580F831BCF69A000DA927B /* PrintableTests.swift in Sources */, A8580F841BCF69A000DA927B /* SubscriptTests.swift in Sources */, diff --git a/Tests/NestedJSONTests.swift b/Tests/NestedJSONTests.swift new file mode 100644 index 00000000..5c75def7 --- /dev/null +++ b/Tests/NestedJSONTests.swift @@ -0,0 +1,42 @@ +// +// NestedJSONTests.swift +// SwiftyJSON +// +// Created by Hector Matos on 9/27/16. +// +// + +import XCTest +import SwiftyJSON + +class NestedJSONTests: XCTestCase { + let family: JSON = [ + "names" : [ + "Brooke Abigail Matos", + "Rowan Danger Matos" + ], + "motto" : "Hey, I don't know about you, but I'm feeling twenty-two! So, release the KrakenDev!" + ] + + func testTopLevelNestedJSON() { + let nestedJSON: JSON = [ + "family" : family + ] + XCTAssertNotNil(try? nestedJSON.rawData()) + } + + func testDeeplyNestedJSON() { + let nestedFamily: JSON = [ + "count": 1, + "families": [ + [ + "isACoolFamily" : true, + "family" : [ + "hello" : family + ] + ] + ] + ] + XCTAssertNotNil(try? nestedFamily.rawData()) + } +} From 46eb9a35f86e3d2f050e85526ad97e5fd3d4c030 Mon Sep 17 00:00:00 2001 From: Hector Matos Date: Tue, 27 Sep 2016 15:20:52 -0700 Subject: [PATCH 265/470] reverts improper moving of code --- Source/SwiftyJSON.swift | 174 ++++++++++++++++++++-------------------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index bb4ddb52..5a69a106 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -34,12 +34,6 @@ public let ErrorWrongType: Int = 901 public let ErrorNotExist: Int = 500 public let ErrorInvalidJSON: Int = 490 -///Types -private let trueNumber = NSNumber(value: true) -private let falseNumber = NSNumber(value: false) -private let trueObjCType = String(cString: trueNumber.objCType) -private let falseObjCType = String(cString: falseNumber.objCType) - // MARK: - JSON Type /** @@ -58,84 +52,6 @@ public enum Type :Int{ case unknown } -// MARK: - NSNumber: Comparable -extension NSNumber { - var isBool:Bool { - get { - let objCType = String(cString: self.objCType) - if (self.compare(trueNumber) == ComparisonResult.orderedSame && objCType == trueObjCType) - || (self.compare(falseNumber) == ComparisonResult.orderedSame && objCType == falseObjCType){ - return true - } else { - return false - } - } - } -} - -func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == ComparisonResult.orderedSame - } -} - -func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { - return !(lhs == rhs) -} - -func <(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == ComparisonResult.orderedAscending - } -} - -func >(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == ComparisonResult.orderedDescending - } -} - -func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) != ComparisonResult.orderedDescending - } -} - -func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { - - switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) != ComparisonResult.orderedAscending - } -} - // MARK: - JSON Base public struct JSON { @@ -579,7 +495,7 @@ extension JSON: Swift.ExpressibleByDictionaryLiteral { } d[element.0] = elementToSet return d - } as Any) + } as Any) } } @@ -896,7 +812,7 @@ extension JSON { if let errorValue = error, errorValue.code == ErrorNotExist || errorValue.code == ErrorIndexOutOfBounds || errorValue.code == ErrorWrongType { - return false + return false } return true } @@ -1048,7 +964,7 @@ extension JSON { if let newValue = newValue { self.object = NSNumber(value: newValue) } else { - self.object = NSNull() + self.object = NSNull() } } } @@ -1281,3 +1197,87 @@ public func <(lhs: JSON, rhs: JSON) -> Bool { return false } } + +private let trueNumber = NSNumber(value: true) +private let falseNumber = NSNumber(value: false) +private let trueObjCType = String(cString: trueNumber.objCType) +private let falseObjCType = String(cString: falseNumber.objCType) + +// MARK: - NSNumber: Comparable + +extension NSNumber { + var isBool:Bool { + get { + let objCType = String(cString: self.objCType) + if (self.compare(trueNumber) == ComparisonResult.orderedSame && objCType == trueObjCType) + || (self.compare(falseNumber) == ComparisonResult.orderedSame && objCType == falseObjCType){ + return true + } else { + return false + } + } + } +} + +func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) == ComparisonResult.orderedSame + } +} + +func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { + return !(lhs == rhs) +} + +func <(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) == ComparisonResult.orderedAscending + } +} + +func >(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) == ComparisonResult.orderedDescending + } +} + +func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) != ComparisonResult.orderedDescending + } +} + +func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { + + switch (lhs.isBool, rhs.isBool) { + case (false, true): + return false + case (true, false): + return false + default: + return lhs.compare(rhs) != ComparisonResult.orderedAscending + } +} From b0cff7c266ae7e521d05176df9ed277f0c6fd872 Mon Sep 17 00:00:00 2001 From: Hector Matos Date: Tue, 27 Sep 2016 15:56:11 -0700 Subject: [PATCH 266/470] adds performance enhancement to prevent merge conflicts --- Source/SwiftyJSON.swift | 21 +++++++++++---------- Tests/PerformanceTests.swift | 20 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5a69a106..5b0c16ff 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -478,8 +478,9 @@ extension JSON: Swift.ExpressibleByDictionaryLiteral { return JSON(dictionaryLiteral: initializeElement) } - self.init(elements.reduce([String : Any](minimumCapacity: elements.count)){(dictionary: [String : Any], element:(String, Any)) -> [String : Any] in - var d = dictionary + var dict = [String : Any](minimumCapacity: elements.count) + + for element in elements { let elementToSet: Any if let json = element.1 as? JSON { elementToSet = json.object @@ -493,9 +494,10 @@ extension JSON: Swift.ExpressibleByDictionaryLiteral { } else { elementToSet = element.1 } - d[element.0] = elementToSet - return d - } as Any) + dict[element.0] = elementToSet + } + + self.init(dict) } } @@ -626,12 +628,11 @@ extension JSON { //Optional [String : JSON] public var dictionary: [String : JSON]? { if self.type == .dictionary { - - return self.rawDictionary.reduce([String : JSON]()) { (dictionary: [String : JSON], element: (String, Any)) -> [String : JSON] in - var d = dictionary - d[element.0] = JSON(element.1) - return d + var d = [String : JSON](minimumCapacity: rawDictionary.count) + for (key, value) in rawDictionary { + d[key] = JSON(value) } + return d } else { return nil } diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index 21b9b31f..34f94b8a 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -99,4 +99,24 @@ class PerformanceTests: XCTestCase { } } + func testLargeDictionaryMethodPerformance() { + var data: [String: JSON] = [:] + (0...100000).forEach { n in + data["\(n)"] = JSON([ + "name": "item\(n)", + "id": n + ]) + } + let json = JSON(data) + + self.measure() { + autoreleasepool{ + if let dictionary = json.dictionary { + XCTAssertTrue(dictionary.count > 0) + } else { + XCTFail("dictionary should not be nil") + } + } + } + } } From 39a19dc33c7cfa8927f81722d591643f12d80ba8 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 28 Sep 2016 22:45:19 +0800 Subject: [PATCH 267/470] Update Alamofire example for Swift3 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7cdedb6b..47de1278 100644 --- a/README.md +++ b/README.md @@ -401,10 +401,10 @@ SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: ```swift Alamofire.request(.GET, url).validate().responseJSON { response in switch response.result { - case .Success(let value): + case .success(let value): let json = JSON(value) print("JSON: \(json)") - case .Failure(let error): + case .failure(let error): print(error) } } From ff43c8e31b4a74e9f98ead17d9b83fa9caf6c486 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Thu, 29 Sep 2016 11:04:55 +0800 Subject: [PATCH 268/470] Auto tagging releases --- .travis.yml | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 14a93dd0..c65386a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,24 @@ language: objective-c - osx_image: xcode8 xcode_sdk: iphonesimulator10.0 - -script: - - rvm get head # https://github.com/travis-ci/travis-ci/issues/6307 - - 'sh scripts/ci.sh' +env: + global: + - FRAMEWORK_NAME=SwiftyJSON +before_install: +- rvm get head +- brew update +- brew outdated carthage || brew upgrade carthage +before_deploy: +- carthage build --no-skip-current +- carthage archive $FRAMEWORK_NAME +script: +- sh scripts/ci.sh +deploy: + provider: releases + api_key: + secure: MufQRIzcHPU5fn9gyXl7kDGaLihN6zGABx9UWqNtkwq0AxV0aYNWys11nrKDIgoZFR+MbQHMoodpZK03yDdCLG03ncnOr3aytLOpI0imuDFWx16sieiVoYmnP5bfNFTN0qqXdfBy0OOsx4wO+F5Pwg5y1TgGYnKpXtEfdIU3Om4= + file: SwiftyJSON.framework.zip + skip_cleanup: true + on: + repo: SwiftyJSON/SwiftyJSON + tags: true From 522e74bf59874fb29b0a23206fb3f31e6d276d09 Mon Sep 17 00:00:00 2001 From: Jobins John Date: Mon, 3 Oct 2016 13:39:19 +0400 Subject: [PATCH 269/470] Copyright Year Update Copyright year updated in file header --- Example/Example/AppDelegate.swift | 2 +- Example/Example/ViewController.swift | 2 +- Source/SwiftyJSON.h | 2 +- Source/SwiftyJSON.swift | 62 ++++++++++++++++++---------- Tests/ArrayTests.swift | 2 +- Tests/ComparableTests.swift | 2 +- Tests/DictionaryTests.swift | 2 +- Tests/LiteralConvertibleTests.swift | 2 +- Tests/NumberTests.swift | 2 +- Tests/PerformanceTests.swift | 2 +- Tests/PrintableTests.swift | 2 +- Tests/RawRepresentableTests.swift | 2 +- Tests/RawTests.swift | 2 +- Tests/SequenceTypeTests.swift | 2 +- Tests/StringTests.swift | 2 +- Tests/SubscriptTests.swift | 2 +- 16 files changed, 56 insertions(+), 36 deletions(-) diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 31b98b35..6c0aead8 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -1,6 +1,6 @@ // SwiftyJSON.h // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 373be9bb..e12a4090 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -1,6 +1,6 @@ // SwiftyJSON.h // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Source/SwiftyJSON.h b/Source/SwiftyJSON.h index 74552a7c..ac942218 100644 --- a/Source/SwiftyJSON.h +++ b/Source/SwiftyJSON.h @@ -1,6 +1,6 @@ // SwiftyJSON.h // -// Copyright (c) 2014 Ruoyu Fu, Pinglin Tang +// Copyright (c) 2014 - 2016 Ruoyu Fu, Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5b0c16ff..c489a0f5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1,6 +1,6 @@ // SwiftyJSON.swift // -// Copyright (c) 2014 Ruoyu Fu, Pinglin Tang +// Copyright (c) 2014 - 2016 Ruoyu Fu, Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -198,14 +198,17 @@ public struct JSON { public static var null: JSON { get { return JSON(NSNull()) } } } -public enum JSONIndex:Comparable { +public enum JSONIndex:Comparable +{ case array(Int) case dictionary(DictionaryIndex) case null } -public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - switch (lhs, rhs) { +public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool +{ + switch (lhs, rhs) + { case (.array(let left), .array(let right)): return left == right case (.dictionary(let left), .dictionary(let right)): @@ -216,8 +219,10 @@ public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { } } -public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - switch (lhs, rhs) { +public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool +{ + switch (lhs, rhs) + { case (.array(let left), .array(let right)): return left < right case (.dictionary(let left), .dictionary(let right)): @@ -228,12 +233,15 @@ public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool { } -extension JSON: Collection{ +extension JSON: Collection +{ public typealias Index = JSONIndex - public var startIndex: Index{ - switch type { + public var startIndex: Index + { + switch type + { case .array: return .array(rawArray.startIndex) case .dictionary: @@ -243,8 +251,10 @@ extension JSON: Collection{ } } - public var endIndex: Index{ - switch type { + public var endIndex: Index + { + switch type + { case .array: return .array(rawArray.endIndex) case .dictionary: @@ -254,8 +264,10 @@ extension JSON: Collection{ } } - public func index(after i: Index) -> Index { - switch i { + public func index(after i: Index) -> Index + { + switch i + { case .array(let idx): return .array(rawArray.index(after: idx)) case .dictionary(let idx): @@ -266,8 +278,10 @@ extension JSON: Collection{ } - public subscript (position: Index) -> (String, JSON) { - switch position { + public subscript (position: Index) -> (String, JSON) + { + switch position + { case .array(let idx): return (String(idx), JSON(self.rawArray[idx])) case .dictionary(let idx): @@ -285,7 +299,8 @@ extension JSON: Collection{ /** * To mark both String and Int can be used in subscript. */ -public enum JSONKey { +public enum JSONKey +{ case index(Int) case key(String) } @@ -891,14 +906,19 @@ extension JSON { } } - public var int: Int? { - get { + public var int: Int? + { + get + { return self.number?.intValue } - set { - if let newValue = newValue { + set + { + if let newValue = newValue + { self.object = NSNumber(value: newValue) - } else { + } else + { self.object = NSNull() } } diff --git a/Tests/ArrayTests.swift b/Tests/ArrayTests.swift index 1c6b1ee4..e2d471a6 100644 --- a/Tests/ArrayTests.swift +++ b/Tests/ArrayTests.swift @@ -1,6 +1,6 @@ // ArrayTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/ComparableTests.swift b/Tests/ComparableTests.swift index 5ee2f072..53b7c231 100644 --- a/Tests/ComparableTests.swift +++ b/Tests/ComparableTests.swift @@ -1,6 +1,6 @@ // ComparableTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/DictionaryTests.swift b/Tests/DictionaryTests.swift index 12074ed3..13208ded 100644 --- a/Tests/DictionaryTests.swift +++ b/Tests/DictionaryTests.swift @@ -1,6 +1,6 @@ // DictionaryTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift index 1f6cf031..35abdf7d 100644 --- a/Tests/LiteralConvertibleTests.swift +++ b/Tests/LiteralConvertibleTests.swift @@ -1,6 +1,6 @@ // LiteralConvertibleTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/NumberTests.swift b/Tests/NumberTests.swift index e578bf83..54c48806 100644 --- a/Tests/NumberTests.swift +++ b/Tests/NumberTests.swift @@ -1,6 +1,6 @@ // NumberTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/PerformanceTests.swift b/Tests/PerformanceTests.swift index 34f94b8a..80b3c028 100644 --- a/Tests/PerformanceTests.swift +++ b/Tests/PerformanceTests.swift @@ -1,6 +1,6 @@ // PerformanceTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/PrintableTests.swift b/Tests/PrintableTests.swift index e9d38811..09c97781 100644 --- a/Tests/PrintableTests.swift +++ b/Tests/PrintableTests.swift @@ -1,6 +1,6 @@ // PrintableTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift index c4e79258..342cd782 100644 --- a/Tests/RawRepresentableTests.swift +++ b/Tests/RawRepresentableTests.swift @@ -1,6 +1,6 @@ // RawRepresentableTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/RawTests.swift b/Tests/RawTests.swift index 7ba7a334..1160726d 100644 --- a/Tests/RawTests.swift +++ b/Tests/RawTests.swift @@ -1,6 +1,6 @@ // RawTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift index 3aae1c19..a9ff6cf6 100644 --- a/Tests/SequenceTypeTests.swift +++ b/Tests/SequenceTypeTests.swift @@ -1,7 +1,7 @@ // // SequenceTypeTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/StringTests.swift b/Tests/StringTests.swift index 8e720be4..1d46eb88 100644 --- a/Tests/StringTests.swift +++ b/Tests/StringTests.swift @@ -1,6 +1,6 @@ // StringTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SubscriptTests.swift b/Tests/SubscriptTests.swift index bdbd821a..66d5c20f 100644 --- a/Tests/SubscriptTests.swift +++ b/Tests/SubscriptTests.swift @@ -1,6 +1,6 @@ // SubscriptTests.swift // -// Copyright (c) 2014 Pinglin Tang +// Copyright (c) 2014 - 2016 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal From c7eedf9f4436e1b092238cb585cc441907d00d35 Mon Sep 17 00:00:00 2001 From: Jobins John Date: Mon, 3 Oct 2016 14:10:04 +0400 Subject: [PATCH 270/470] Copyright year upgraded --- Tests/BaseTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/BaseTests.swift b/Tests/BaseTests.swift index 7de2881d..b8a51a08 100644 --- a/Tests/BaseTests.swift +++ b/Tests/BaseTests.swift @@ -1,6 +1,6 @@ // BaseTests.swift // -// Copyright (c) 2014 Ruoyu Fu, Pinglin Tang +// Copyright (c) 2014 - 2016 Ruoyu Fu, Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal From 325529ec51675b029cf1af31eb84219b893c1fd7 Mon Sep 17 00:00:00 2001 From: Jobins John Date: Mon, 3 Oct 2016 14:10:19 +0400 Subject: [PATCH 271/470] Upgraded to swift 3.0 --- Example/Example/Base.lproj/LaunchScreen.xib | 4 ++-- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Example/Example/Base.lproj/LaunchScreen.xib b/Example/Example/Base.lproj/LaunchScreen.xib index b999ccb2..43a0234f 100644 --- a/Example/Example/Base.lproj/LaunchScreen.xib +++ b/Example/Example/Base.lproj/LaunchScreen.xib @@ -1,5 +1,5 @@ - + @@ -13,7 +13,7 @@ - - + @@ -79,4 +79,7 @@ + + + diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index e12a4090..db1d1da1 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -69,12 +69,7 @@ class ViewController: UITableViewController { override func prepare(for segue: UIStoryboardSegue, sender: Any!) { var nextController: UIViewController? - switch UIDevice.current.systemVersion.compare("8.0.0", options: NSString.CompareOptions.numeric) { - case .orderedSame, .orderedDescending: - nextController = (segue.destination as! UINavigationController).topViewController - case .orderedAscending: - nextController = segue.destination - } + nextController = segue.destination if let indexPath = self.tableView.indexPathForSelectedRow { let row = (indexPath as NSIndexPath).row From 32adaff4fa7628824fb658880b5053a45c70caa1 Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Thu, 13 Oct 2016 11:06:39 +1100 Subject: [PATCH 287/470] Explicitly set Prov Style Automatic for iOS target --- SwiftyJSON.xcodeproj/project.pbxproj | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 81a1e577..9b3d00bf 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -432,6 +432,7 @@ 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; LastSwiftMigration = 0800; + ProvisioningStyle = Automatic; }; 2E4FEFE519575BE100351305 = { CreatedOnToolsVersion = 6.0; @@ -744,7 +745,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -764,7 +767,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; From e81fb1c2585091a0b323e315b353cc22ad6985b0 Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Thu, 13 Oct 2016 11:07:21 +1100 Subject: [PATCH 288/470] Explictily set Prov Style Automatic for watchOS --- SwiftyJSON.xcodeproj/project.pbxproj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 9b3d00bf..92fa4324 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -449,6 +449,9 @@ A8580F731BCF5C5B00DA927B = { CreatedOnToolsVersion = 7.1; }; + E4D7CCDE1B9465A700EE7221 = { + ProvisioningStyle = Automatic; + }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -989,7 +992,9 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1012,7 +1017,9 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; From db404fca6c7562050b3e1bd30341dcb979211b90 Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Thu, 13 Oct 2016 11:07:45 +1100 Subject: [PATCH 289/470] Explicitly set Prov Style Automatic for tvOS --- SwiftyJSON.xcodeproj/project.pbxproj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 92fa4324..840df705 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -440,6 +440,9 @@ ProvisioningStyle = Manual; TestTargetID = 2E4FEFDA19575BE100351305; }; + 7236B4EC1BAC14150020529B = { + ProvisioningStyle = Automatic; + }; 9C7DFC5A1A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; }; @@ -824,7 +827,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -846,7 +851,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; From 553610566ec6600a3db1cceb5efcd637897e4ce3 Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Fri, 21 Oct 2016 20:51:29 +1100 Subject: [PATCH 290/470] Explictily set Prov Style Automatic for macOS --- SwiftyJSON.xcodeproj/project.pbxproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 840df705..b254f287 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -445,6 +445,7 @@ }; 9C7DFC5A1A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; + ProvisioningStyle = Automatic; }; 9C7DFC641A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; @@ -874,7 +875,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; - CODE_SIGN_IDENTITY = ""; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -902,7 +903,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; - CODE_SIGN_IDENTITY = ""; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; From 5b7400f279122871095ffbdbfe6c913ecda6b14e Mon Sep 17 00:00:00 2001 From: Jeff Kang Date: Fri, 28 Oct 2016 16:46:34 +0900 Subject: [PATCH 291/470] Add getting a string using a path to the element. --- Example/Playground.playground/Contents.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index bfe9c3e6..5ccdfcce 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -77,3 +77,22 @@ print(arrayOfString) // Getting a string from a JSON Dictionary jsonDictionary["country"].stringValue +//Getting a string using a path to the element +let path: [JSONSubscriptType] = ["users", 1, "info", "name"] +let feed = jsonArray[path].string + +////Just the same +//let name = json[1]["list"][2]["name"].string +////Alternatively +//let name = json[1,"list",2,"name"].string +// +// +//```swift +////With a hard way +//let name = json[].string +//``` +//```swift +////With a custom way +//let keys:[SubscriptType] = [1,"list",2,"name"] +//let name = json[keys].string +//``` From 1dbcdaed717cd85f01aba0c0d1c576bcb790aefa Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 28 Oct 2016 17:40:58 +0800 Subject: [PATCH 292/470] Fix examples in README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 34f12b82..5cc5c24d 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ let name = json["name"].stringValue ``` ```swift //Getting a string using a path to the element -let path = [1,"list",2,"name"] +let path: [JSONSubscriptType] = [1,"list",2,"name"] let name = json[path].string //Just the same let name = json[1]["list"][2]["name"].string @@ -401,7 +401,7 @@ json["address"] = "L.A." // Add the "address": "L.A." in json var json: JSON = ["name": "Jack", "age": 25, "list": ["a", "b", "c", ["what": "this"]]] json["list"][3]["what"] = "that" json["list",3,"what"] = "that" -let path = ["list",3,"what"] +let path: [JSONSubscriptType] = ["list",3,"what"] json[path] = "that" ``` ```swift From 3e54d90db10335c428405cf96b4ac4e407607ac5 Mon Sep 17 00:00:00 2001 From: mc1024 Date: Fri, 28 Oct 2016 16:38:17 -0400 Subject: [PATCH 293/470] Fix warning In XCode 8.1 (8B62) Expression implicitly coerced from 'String?' to Any --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 7e71a187..3e9c3266 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -856,7 +856,7 @@ extension JSON { } } set { - self.object = newValue?.absoluteString + self.object = newValue?.absoluteString ?? NSNull() } } } From 9f5cfa06ec279bcab828d2e7856ca40b00c2a1dc Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Thu, 13 Oct 2016 11:06:39 +1100 Subject: [PATCH 294/470] Explicitly set Prov Style Automatic for iOS target --- SwiftyJSON.xcodeproj/project.pbxproj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index f3fa05ab..e3ced065 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -432,6 +432,7 @@ 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; LastSwiftMigration = 0800; + ProvisioningStyle = Automatic; }; 2E4FEFE519575BE100351305 = { CreatedOnToolsVersion = 6.0; @@ -748,8 +749,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -769,8 +771,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; From e7b7e26dc75ae38caafc80ed8802885163424350 Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Thu, 13 Oct 2016 11:07:21 +1100 Subject: [PATCH 295/470] Explictily set Prov Style Automatic for watchOS --- SwiftyJSON.xcodeproj/project.pbxproj | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index e3ced065..23ed1cda 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -449,6 +449,9 @@ A8580F731BCF5C5B00DA927B = { CreatedOnToolsVersion = 7.1; }; + E4D7CCDE1B9465A700EE7221 = { + ProvisioningStyle = Automatic; + }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -995,8 +998,13 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; +<<<<<<< HEAD "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; +======= + "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; +>>>>>>> Explictily set Prov Style Automatic for watchOS DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -1019,8 +1027,13 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; +<<<<<<< HEAD "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; +======= + "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; +>>>>>>> Explictily set Prov Style Automatic for watchOS DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; From 423bdc0f2adbcb39c314b85bcd8ce027e335eb53 Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Thu, 13 Oct 2016 11:07:45 +1100 Subject: [PATCH 296/470] Explicitly set Prov Style Automatic for tvOS --- SwiftyJSON.xcodeproj/project.pbxproj | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 23ed1cda..33353551 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -440,6 +440,9 @@ ProvisioningStyle = Manual; TestTargetID = 2E4FEFDA19575BE100351305; }; + 7236B4EC1BAC14150020529B = { + ProvisioningStyle = Automatic; + }; 9C7DFC5A1A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; }; @@ -828,8 +831,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -851,8 +855,9 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer"; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -998,11 +1003,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; -<<<<<<< HEAD - "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; -======= "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; ->>>>>>> Explictily set Prov Style Automatic for watchOS DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1027,11 +1028,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; -<<<<<<< HEAD - "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; -======= "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; ->>>>>>> Explictily set Prov Style Automatic for watchOS DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; From eadd072159f1626c060cc69711ffa45bb04f6e98 Mon Sep 17 00:00:00 2001 From: Giovanni Lodi Date: Fri, 21 Oct 2016 20:51:29 +1100 Subject: [PATCH 297/470] Explictily set Prov Style Automatic for macOS --- SwiftyJSON.xcodeproj/project.pbxproj | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 33353551..d940cb1e 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -445,6 +445,7 @@ }; 9C7DFC5A1A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; + ProvisioningStyle = Automatic; }; 9C7DFC641A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; @@ -878,7 +879,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; - CODE_SIGN_IDENTITY = ""; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -906,7 +907,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; - CODE_SIGN_IDENTITY = ""; + CODE_SIGN_IDENTITY = "Mac Developer"; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; From 58fad8a2f19701069222029a16a6e927330a8b67 Mon Sep 17 00:00:00 2001 From: Jeff Kang Date: Mon, 31 Oct 2016 15:57:47 +0900 Subject: [PATCH 298/470] Finish subscript part. Add descriptions. --- Example/Playground.playground/Contents.swift | 44 ++++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index 5ccdfcce..90b99433 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -1,9 +1,15 @@ //: Playground - noun: a place where people can play - /*: - ## Basic setting for playground + # SwiftyJSON + SwiftyJSON makes it easy to deal with JSON data in Swift. + + You must have to build `SwiftyJSON iOS` package for import. + */ +/*: + ### Basic setting for playground */ import SwiftyJSON +import Foundation var jsonData: Data? @@ -18,9 +24,9 @@ let jsonObject = try JSONSerialization.jsonObject(with: jsonData!, options: .all let jsonString = String(data: jsonData!, encoding: .utf8) /*: - # Usage + ## Usage - ## Initialization + ### Initialization */ import SwiftyJSON @@ -37,7 +43,7 @@ let dataFromString = jsonString?.data(using: .utf8) let json3 = JSON(data: dataFromString!) /*: - ## Subscript + ### Subscript */ // Example json var jsonArray: JSON = [ @@ -78,21 +84,15 @@ print(arrayOfString) jsonDictionary["country"].stringValue //Getting a string using a path to the element -let path: [JSONSubscriptType] = ["users", 1, "info", "name"] -let feed = jsonArray[path].string +let path = ["users", 1, "info", "name"] as [JSONSubscriptType] +var name = jsonArray["users",1,"info","name"].string + +//With a custom way +let keys: [JSONSubscriptType] = ["users", 1, "info", "name"] +name = jsonArray[keys].string + +//Just the same +name = jsonArray["users"][1]["info"]["name"].string -////Just the same -//let name = json[1]["list"][2]["name"].string -////Alternatively -//let name = json[1,"list",2,"name"].string -// -// -//```swift -////With a hard way -//let name = json[].string -//``` -//```swift -////With a custom way -//let keys:[SubscriptType] = [1,"list",2,"name"] -//let name = json[keys].string -//``` +//Alternatively +name = jsonArray["users",1,"info","name"].string \ No newline at end of file From e2be46e1656f64ba264f0f87c50cf4ce1b15a9ff Mon Sep 17 00:00:00 2001 From: Jeff Kang Date: Mon, 31 Oct 2016 16:06:13 +0900 Subject: [PATCH 299/470] Turn on render documentation mode. --- Example/Playground.playground/contents.xcplayground | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Playground.playground/contents.xcplayground b/Example/Playground.playground/contents.xcplayground index 35968656..89da2d47 100644 --- a/Example/Playground.playground/contents.xcplayground +++ b/Example/Playground.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file From da5c307822dc54e7ab23a5e4192f13c72ceb22d8 Mon Sep 17 00:00:00 2001 From: Jeff Kang Date: Mon, 31 Oct 2016 16:29:37 +0900 Subject: [PATCH 300/470] Fix syntax. --- README.md | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5cc5c24d..84570529 100644 --- a/README.md +++ b/README.md @@ -33,13 +33,11 @@ Take the Twitter API for example. Say we want to retrieve a user's "name" value The code would look like this: ```swift - if let statusesArray = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: AnyObject]], let user = statusesArray[0]["user"] as? [String: AnyObject], let username = user["name"] as? String { // Finally we got the username } - ``` It's not good. @@ -47,30 +45,26 @@ It's not good. Even if we use optional chaining, it would be messy: ```swift - if let JSONObject = try JSONSerialization.jsonObject(with: data,, options: .allowFragments) as? [[String: AnyObject]], let username = (JSONObject[0]["user"] as? [String: AnyObject])?["name"] as? String { // There's our username } - ``` + An unreadable mess--for something that should really be simple! With SwiftyJSON all you have to do is: ```swift - let json = JSON(data: dataFromNetworking) if let userName = json[0]["user"]["name"].string { //Now you got your value } - ``` And don't worry about the Optional Wrapping thing. It's done for you automatically. ```swift - let json = JSON(data: dataFromNetworking) if let userName = json[999999]["wrong_key"]["wrong_name"].string { //Calm down, take it easy, the ".string" property still produces the correct Optional String type with safety @@ -78,7 +72,6 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { //Print the error print(json[999999]["wrong_key"]["wrong_name"]) } - ``` ## Requirements @@ -91,6 +84,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { #### CocoaPods (iOS 8+, OS X 10.9+) You can use [CocoaPods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: + ```ruby platform :ios, '8.0' use_frameworks! @@ -99,12 +93,14 @@ target 'MyApp' do pod 'SwiftyJSON' end ``` + Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 8.0: #### Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: + ``` github "SwiftyJSON/SwiftyJSON" ``` @@ -112,6 +108,7 @@ github "SwiftyJSON/SwiftyJSON" #### Swift Package Manager You can use [The Swift Package Manager](https://swift.org/package-manager) to install `SwiftyJSON` by adding the proper description to your `Package.swift` file: + ```swift import PackageDescription @@ -140,12 +137,15 @@ To use this library in your project manually you may: ```swift import SwiftyJSON ``` + ```swift let json = JSON(data: dataFromNetworking) ``` + ```swift let json = JSON(jsonObject) ``` + ```swift if let dataFromString = jsonString.data(using: .utf8, allowLossyConversion: false) { let json = JSON(data: dataFromString) @@ -168,6 +168,7 @@ let arrayNames = json["users"].arrayValue.map({$0["name"].stringValue}) //Getting a string from a JSON Dictionary let name = json["name"].stringValue ``` + ```swift //Getting a string using a path to the element let path: [JSONSubscriptType] = [1,"list",2,"name"] @@ -177,10 +178,12 @@ let name = json[1]["list"][2]["name"].string //Alternatively let name = json[1,"list",2,"name"].string ``` + ```swift //With a hard way let name = json[].string ``` + ```swift //With a custom way let keys:[SubscriptType] = [1,"list",2,"name"] @@ -195,7 +198,9 @@ for (key,subJson):(String, JSON) in json { //Do something you want } ``` + *The first element is always a String, even if the JSON is an Array* + ```swift //If json is .Array //The `index` is 0.. = json["list"].arrayValue ``` + ```swift //If not a Dictionary or nil, return [:] let user: Dictionary = json["user"].dictionaryValue @@ -314,6 +328,7 @@ let user: Dictionary = json["user"].dictionaryValue json["name"] = JSON("new-name") json[0] = JSON(1) ``` + ```swift json["id"].int = 1234567890 json["coordinate"].double = 8766.766 @@ -327,15 +342,18 @@ json.dictionaryObject = ["name":"Jack", "age":25] ```swift let jsonObject: AnyObject = json.object ``` + ```swift if let jsonObject: AnyObject = json.rawValue ``` + ```swift //convert the JSON to raw NSData if let data = json.rawData() { //Do something you want } ``` + ```swift //convert the JSON to a raw String if let string = json.rawString() { @@ -353,34 +371,42 @@ if json["name"].exists() #### Literal convertibles For more info about literal convertibles: [Swift Literal Convertibles](http://nshipster.com/swift-literal-convertible/) + ```swift //StringLiteralConvertible let json: JSON = "I'm a json" ``` + ```swift //IntegerLiteralConvertible let json: JSON = 12345 ``` + ```swift //BooleanLiteralConvertible let json: JSON = true ``` + ```swift //FloatLiteralConvertible let json: JSON = 2.8765 ``` + ```swift //DictionaryLiteralConvertible let json: JSON = ["I":"am", "a":"json"] ``` + ```swift //ArrayLiteralConvertible let json: JSON = ["I", "am", "a", "json"] ``` + ```swift //NilLiteralConvertible let json: JSON = nil ``` + ```swift //With subscript in array var json: JSON = [1,2,3] @@ -389,6 +415,7 @@ json[1] = 200 json[2] = 300 json[999] = 300 //Don't worry, nothing will happen ``` + ```swift //With subscript in dictionary var json: JSON = ["name": "Jack", "age": 25] @@ -396,6 +423,7 @@ json["name"] = "Mike" json["age"] = "25" //It's OK to set String json["address"] = "L.A." // Add the "address": "L.A." in json ``` + ```swift //Array & Dictionary var json: JSON = ["name": "Jack", "age": 25, "list": ["a", "b", "c", ["what": "this"]]] @@ -404,6 +432,7 @@ json["list",3,"what"] = "that" let path: [JSONSubscriptType] = ["list",3,"what"] json[path] = "that" ``` + ```swift //With other JSON objects let user: JSON = ["username" : "Steve", "password": "supersecurepassword"] @@ -411,11 +440,12 @@ let auth: JSON = [ "user": user.object //use user.object instead of just user "apikey": "supersecretapitoken" ] -```` +``` -##Work with Alamofire +## Work with Alamofire SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: + ```swift Alamofire.request(.GET, url).validate().responseJSON { response in switch response.result { From ef668d869f7cbbb54419d7fbf4b981de4ac3c651 Mon Sep 17 00:00:00 2001 From: Sam Agnew Date: Fri, 4 Nov 2016 14:27:36 -0400 Subject: [PATCH 301/470] Fix typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84570529..4fa31853 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ let package = Package( ) ``` -Note that the [Swift Package Manager](https://swift.org/package-manager) is still in early design and development, for more infomation checkout its [GitHub Page](https://github.com/apple/swift-package-manager) +Note that the [Swift Package Manager](https://swift.org/package-manager) is still in early design and development, for more information checkout its [GitHub Page](https://github.com/apple/swift-package-manager) #### Manually (iOS 7+, OS X 10.9+) From 2c9f373d53e5a5f4fc4eb6e81c089505507719a7 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Mon, 7 Nov 2016 00:17:25 +0800 Subject: [PATCH 302/470] Re-organize tests to satisfy SPM --- SwiftyJSON.xcodeproj/project.pbxproj | 19 ++++++++++--------- Tests/{ => SwiftyJSONTests}/ArrayTests.swift | 0 Tests/{ => SwiftyJSONTests}/BaseTests.swift | 0 .../ComparableTests.swift | 0 .../DictionaryTests.swift | 0 Tests/{ => SwiftyJSONTests}/Info-OSX.plist | 0 Tests/{ => SwiftyJSONTests}/Info-iOS.plist | 0 Tests/{ => SwiftyJSONTests}/Info-tvOS.plist | 0 .../LiteralConvertibleTests.swift | 0 .../NestedJSONTests.swift | 0 Tests/{ => SwiftyJSONTests}/NumberTests.swift | 0 .../PerformanceTests.swift | 0 .../PrintableTests.swift | 0 .../RawRepresentableTests.swift | 0 Tests/{ => SwiftyJSONTests}/RawTests.swift | 0 .../SequenceTypeTests.swift | 0 Tests/{ => SwiftyJSONTests}/StringTests.swift | 0 .../SubscriptTests.swift | 0 Tests/{ => SwiftyJSONTests}/Tests.json | 0 19 files changed, 10 insertions(+), 9 deletions(-) rename Tests/{ => SwiftyJSONTests}/ArrayTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/BaseTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/ComparableTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/DictionaryTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/Info-OSX.plist (100%) rename Tests/{ => SwiftyJSONTests}/Info-iOS.plist (100%) rename Tests/{ => SwiftyJSONTests}/Info-tvOS.plist (100%) rename Tests/{ => SwiftyJSONTests}/LiteralConvertibleTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/NestedJSONTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/NumberTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/PerformanceTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/PrintableTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/RawRepresentableTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/RawTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/SequenceTypeTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/StringTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/SubscriptTests.swift (100%) rename Tests/{ => SwiftyJSONTests}/Tests.json (100%) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index d940cb1e..4bddfa14 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -183,7 +183,7 @@ isa = PBXGroup; children = ( 2E4FEFDD19575BE100351305 /* Source */, - 2E4FEFEA19575BE100351305 /* Tests */, + 2E4FEFEA19575BE100351305 /* SwiftyJSONTests */, 2E4FEFDC19575BE100351305 /* Products */, ); sourceTree = ""; @@ -223,7 +223,7 @@ name = "Supporting Files"; sourceTree = ""; }; - 2E4FEFEA19575BE100351305 /* Tests */ = { + 2E4FEFEA19575BE100351305 /* SwiftyJSONTests */ = { isa = PBXGroup; children = ( A885D1DA19CFCFF0002FD4C3 /* Tests.json */, @@ -243,7 +243,8 @@ A8B66C8D19E52F4200540692 /* ArrayTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); - path = Tests; + name = SwiftyJSONTests; + path = Tests/SwiftyJSONTests; sourceTree = ""; }; 2E4FEFEB19575BE100351305 /* Supporting Files */ = { @@ -804,7 +805,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "Tests/Info-iOS.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; @@ -818,7 +819,7 @@ buildSettings = { CODE_SIGN_IDENTITY = ""; DEVELOPMENT_TEAM = ""; - INFOPLIST_FILE = "Tests/Info-iOS.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; @@ -938,7 +939,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "Tests/Info-OSX.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; @@ -955,7 +956,7 @@ COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ""; - INFOPLIST_FILE = "Tests/Info-OSX.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; @@ -971,7 +972,7 @@ CODE_SIGN_IDENTITY = ""; DEBUG_INFORMATION_FORMAT = dwarf; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "Tests/Info-tvOS.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-tvOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; @@ -988,7 +989,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "Tests/Info-tvOS.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-tvOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; diff --git a/Tests/ArrayTests.swift b/Tests/SwiftyJSONTests/ArrayTests.swift similarity index 100% rename from Tests/ArrayTests.swift rename to Tests/SwiftyJSONTests/ArrayTests.swift diff --git a/Tests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift similarity index 100% rename from Tests/BaseTests.swift rename to Tests/SwiftyJSONTests/BaseTests.swift diff --git a/Tests/ComparableTests.swift b/Tests/SwiftyJSONTests/ComparableTests.swift similarity index 100% rename from Tests/ComparableTests.swift rename to Tests/SwiftyJSONTests/ComparableTests.swift diff --git a/Tests/DictionaryTests.swift b/Tests/SwiftyJSONTests/DictionaryTests.swift similarity index 100% rename from Tests/DictionaryTests.swift rename to Tests/SwiftyJSONTests/DictionaryTests.swift diff --git a/Tests/Info-OSX.plist b/Tests/SwiftyJSONTests/Info-OSX.plist similarity index 100% rename from Tests/Info-OSX.plist rename to Tests/SwiftyJSONTests/Info-OSX.plist diff --git a/Tests/Info-iOS.plist b/Tests/SwiftyJSONTests/Info-iOS.plist similarity index 100% rename from Tests/Info-iOS.plist rename to Tests/SwiftyJSONTests/Info-iOS.plist diff --git a/Tests/Info-tvOS.plist b/Tests/SwiftyJSONTests/Info-tvOS.plist similarity index 100% rename from Tests/Info-tvOS.plist rename to Tests/SwiftyJSONTests/Info-tvOS.plist diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift similarity index 100% rename from Tests/LiteralConvertibleTests.swift rename to Tests/SwiftyJSONTests/LiteralConvertibleTests.swift diff --git a/Tests/NestedJSONTests.swift b/Tests/SwiftyJSONTests/NestedJSONTests.swift similarity index 100% rename from Tests/NestedJSONTests.swift rename to Tests/SwiftyJSONTests/NestedJSONTests.swift diff --git a/Tests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift similarity index 100% rename from Tests/NumberTests.swift rename to Tests/SwiftyJSONTests/NumberTests.swift diff --git a/Tests/PerformanceTests.swift b/Tests/SwiftyJSONTests/PerformanceTests.swift similarity index 100% rename from Tests/PerformanceTests.swift rename to Tests/SwiftyJSONTests/PerformanceTests.swift diff --git a/Tests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift similarity index 100% rename from Tests/PrintableTests.swift rename to Tests/SwiftyJSONTests/PrintableTests.swift diff --git a/Tests/RawRepresentableTests.swift b/Tests/SwiftyJSONTests/RawRepresentableTests.swift similarity index 100% rename from Tests/RawRepresentableTests.swift rename to Tests/SwiftyJSONTests/RawRepresentableTests.swift diff --git a/Tests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift similarity index 100% rename from Tests/RawTests.swift rename to Tests/SwiftyJSONTests/RawTests.swift diff --git a/Tests/SequenceTypeTests.swift b/Tests/SwiftyJSONTests/SequenceTypeTests.swift similarity index 100% rename from Tests/SequenceTypeTests.swift rename to Tests/SwiftyJSONTests/SequenceTypeTests.swift diff --git a/Tests/StringTests.swift b/Tests/SwiftyJSONTests/StringTests.swift similarity index 100% rename from Tests/StringTests.swift rename to Tests/SwiftyJSONTests/StringTests.swift diff --git a/Tests/SubscriptTests.swift b/Tests/SwiftyJSONTests/SubscriptTests.swift similarity index 100% rename from Tests/SubscriptTests.swift rename to Tests/SwiftyJSONTests/SubscriptTests.swift diff --git a/Tests/Tests.json b/Tests/SwiftyJSONTests/Tests.json similarity index 100% rename from Tests/Tests.json rename to Tests/SwiftyJSONTests/Tests.json From 2eb271f87a251577b20add3f6954ba447f512f76 Mon Sep 17 00:00:00 2001 From: Simon Tsai Date: Thu, 10 Nov 2016 08:06:27 -0500 Subject: [PATCH 303/470] =?UTF-8?q?The=20=E2=80=98isBool=E2=80=99=20functi?= =?UTF-8?q?on=20on=20the=20NSNumber=20extension=20uses=20=E2=80=98trueObjC?= =?UTF-8?q?Type=E2=80=99,=20which=20represents=20the=20type=20encoding=20f?= =?UTF-8?q?or=20=E2=80=98true=E2=80=99=20represented=20as=20an=20NSNumber,?= =?UTF-8?q?=20and=20=E2=80=98falseObjCType=E2=80=99,=20which=20represents?= =?UTF-8?q?=20the=20type=20encoding=20for=20=E2=80=98false=E2=80=99=20repr?= =?UTF-8?q?esented=20as=20an=20NSNumber.=20Both=20type=20encodings=20are?= =?UTF-8?q?=20equal=20to=20=E2=80=98c=E2=80=99.=20However,=20an=20NSNumber?= =?UTF-8?q?=20that=20wraps=20around=20a=20value=20of=20type=20Int8=20also?= =?UTF-8?q?=20has=20a=20type=20encoding=20of=20=E2=80=98c=E2=80=99.=20Ther?= =?UTF-8?q?efore,=20a=20user=20who=20passes=20in=20a=20value=20of=200=20or?= =?UTF-8?q?=201=20(of=20type=20Int8)=20into=20JSON=20will=20expect=20to=20?= =?UTF-8?q?see=20the=20numbers=200=20or=201=20as=20the=20output=20because?= =?UTF-8?q?=20that=20was=20the=20intent.=20Unfortunately,=20that=20value?= =?UTF-8?q?=20will=20be=20wrapped=20into=20NSNumber=20and=20be=20considere?= =?UTF-8?q?d=20a=20bool,=20so=20the=20user=20will=20see=20=E2=80=98true?= =?UTF-8?q?=E2=80=99=20or=20=E2=80=98false=E2=80=99=20instead.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Therefore, when setting a new value of type Int8 on the computed properties ‘int8’ or ‘int8Value’, the new value should be used to directly set ‘object’, which should then check for the Int8 type and use an Int instead. This is fine because an Int8 converted to an Int will always work and retain the same behavior of JSON, and also because the user’s intent is to use a number, not a boolean. Having said that, the tests for Int8 don’t test the right thing. The user’s intent is to use an integer, which is a number. However, the test assumes hardware implementation and accepts the fact that it can either be true or a number, which is unintuitive. Int8 is a pragmatic refinement to the semantic meaning of an integer, and should therefore be used as a number like the user intends, not a boolean. --- Source/SwiftyJSON.swift | 7 +++++-- Tests/SwiftyJSONTests/NumberTests.swift | 12 ++---------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3e9c3266..4aa6fcc7 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -157,6 +157,9 @@ public struct JSON { set { _error = nil switch newValue { + case let int8Value as Int8 where type(of: newValue) == Int8.self: + _type = .number + self.rawNumber = NSNumber(value: Int(int8Value)) case let number as NSNumber: if number.isBool { _type = .bool @@ -964,7 +967,7 @@ extension JSON { } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + self.object = newValue } else { self.object = NSNull() } @@ -976,7 +979,7 @@ extension JSON { return self.numberValue.int8Value } set { - self.object = NSNumber(value: newValue) + self.object = newValue } } diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index 54c48806..37e89cc8 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -192,11 +192,7 @@ class NumberTests: XCTestCase { print(json.number) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) - #if (arch(x86_64) || arch(arm64)) - XCTAssertEqual(json.stringValue, "false") - #elseif (arch(i386) || arch(arm)) - XCTAssertEqual(json.stringValue, "0") - #endif + XCTAssertEqual(json.stringValue, "0") let n1 = NSNumber(value: 1 as Int8) @@ -205,11 +201,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.int8Value == n1.int8Value) XCTAssertTrue(json.number! == n1) XCTAssertEqual(json.numberValue, n1) - #if (arch(x86_64) || arch(arm64)) - XCTAssertEqual(json.stringValue, "true") - #elseif (arch(i386) || arch(arm)) - XCTAssertEqual(json.stringValue, "1") - #endif + XCTAssertEqual(json.stringValue, "1") } func testUInt8() { From 6f0ddada0be966886a67884e9be70bbdc005b1c0 Mon Sep 17 00:00:00 2001 From: skyline75489 Date: Sun, 13 Nov 2016 17:19:17 +0800 Subject: [PATCH 304/470] Fix 'AnyObject' in comment and README.md --- README.md | 12 ++++++------ Source/SwiftyJSON.swift | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 4fa31853..0f29db0b 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,8 @@ Take the Twitter API for example. Say we want to retrieve a user's "name" value The code would look like this: ```swift -if let statusesArray = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: AnyObject]], - let user = statusesArray[0]["user"] as? [String: AnyObject], +if let statusesArray = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: Any]], + let user = statusesArray[0]["user"] as? [String: Any], let username = user["name"] as? String { // Finally we got the username } @@ -45,8 +45,8 @@ It's not good. Even if we use optional chaining, it would be messy: ```swift -if let JSONObject = try JSONSerialization.jsonObject(with: data,, options: .allowFragments) as? [[String: AnyObject]], - let username = (JSONObject[0]["user"] as? [String: AnyObject])?["name"] as? String { +if let JSONObject = try JSONSerialization.jsonObject(with: data,, options: .allowFragments) as? [[String: Any]], + let username = (JSONObject[0]["user"] as? [String: Any])?["name"] as? String { // There's our username } ``` @@ -340,11 +340,11 @@ json.dictionaryObject = ["name":"Jack", "age":25] #### Raw object ```swift -let jsonObject: AnyObject = json.object +let jsonObject: Any = json.object ``` ```swift -if let jsonObject: AnyObject = json.rawValue +if let jsonObject: Any = json.rawValue ``` ```swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3e9c3266..48464179 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -617,7 +617,7 @@ extension JSON { } } - //Optional [AnyObject] + //Optional [Any] public var arrayObject: [Any]? { get { switch self.type { @@ -659,7 +659,7 @@ extension JSON { return self.dictionary ?? [:] } - //Optional [String : AnyObject] + //Optional [String : Any] public var dictionaryObject: [String : Any]? { get { switch self.type { From d983bd9cc9b9b9e8b19ddad5f02612ae6d343101 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 16 Nov 2016 23:01:12 +0800 Subject: [PATCH 305/470] Attemp to fix #697 --- Source/SwiftyJSON.swift | 301 ++++++++++++++++++++++------------------ 1 file changed, 169 insertions(+), 132 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3e9c3266..6034a6b9 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -38,11 +38,11 @@ public let ErrorInvalidJSON: Int = 490 /** JSON's type definitions. - + See http://www.json.org */ public enum Type :Int{ - + case number case string case bool @@ -54,14 +54,14 @@ public enum Type :Int{ // MARK: - JSON Base public struct JSON { - + /** Creates a JSON using the data. - + - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - parameter opt: The JSON serialization reading options. `.AllowFragments` by default. - parameter error: The NSErrorPointer used to return the error. `nil` by default. - + - returns: The created JSON */ public init(data:Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer = nil) { @@ -75,45 +75,45 @@ public struct JSON { self.init(NSNull()) } } - + /** Creates a JSON from JSON string - parameter string: Normal json string like '{"a":"b"}' - + - returns: The created JSON */ public static func parse(_ string:String) -> JSON { return string.data(using: String.Encoding.utf8) .flatMap{ JSON(data: $0) } ?? JSON(NSNull()) } - + /** Creates a JSON using the object. - + - parameter object: The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. - + - returns: The created JSON */ public init(_ object: Any) { self.object = object } - + /** Creates a JSON from a [JSON] - + - parameter jsonArray: A Swift array of JSON objects - + - returns: The created JSON */ public init(_ jsonArray:[JSON]) { self.init(jsonArray.map { $0.object }) } - + /** Creates a JSON from a [String: JSON] - + - parameter jsonDictionary: A Swift dictionary of JSON objects - + - returns: The created JSON */ public init(_ jsonDictionary:[String: JSON]) { @@ -123,7 +123,7 @@ public struct JSON { } self.init(dictionary) } - + /// Private object fileprivate var rawArray: [Any] = [] fileprivate var rawDictionary: [String : Any] = [:] @@ -135,7 +135,7 @@ public struct JSON { fileprivate var _type: Type = .null /// prviate error fileprivate var _error: NSError? = nil - + /// Object in JSON public var object: Any { get { @@ -185,13 +185,13 @@ public struct JSON { } } } - + /// JSON type public var type: Type { get { return _type } } - + /// Error in JSON public var error: NSError? { get { return self._error } } - + /// The static null JSON @available(*, unavailable, renamed:"null") public static var nullJSON: JSON { get { return null } } @@ -203,41 +203,77 @@ public enum JSONIndex:Comparable case array(Int) case dictionary(DictionaryIndex) case null -} -public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool -{ - switch (lhs, rhs) + static public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool { - case (.array(let left), .array(let right)): - return left == right - case (.dictionary(let left), .dictionary(let right)): - return left == right - case (.null, .null): return true - default: - return false + switch (lhs, rhs) + { + case (.array(let left), .array(let right)): + return left == right + case (.dictionary(let left), .dictionary(let right)): + return left == right + case (.null, .null): return true + default: + return false + } + } + + static public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool + { + switch (lhs, rhs) + { + case (.array(let left), .array(let right)): + return left < right + case (.dictionary(let left), .dictionary(let right)): + return left < right + default: + return false + } } + } -public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool +public enum JSONRawIndex: Comparable { - switch (lhs, rhs) + case array(Int) + case dictionary(DictionaryIndex) + case null + + static public func ==(lhs: JSONRawIndex, rhs: JSONRawIndex) -> Bool { - case (.array(let left), .array(let right)): - return left < right - case (.dictionary(let left), .dictionary(let right)): - return left < right - default: - return false + switch (lhs, rhs) + { + case (.array(let left), .array(let right)): + return left == right + case (.dictionary(let left), .dictionary(let right)): + return left == right + case (.null, .null): return true + default: + return false + } } -} + static public func <(lhs: JSONRawIndex, rhs: JSONRawIndex) -> Bool + { + switch (lhs, rhs) + { + case (.array(let left), .array(let right)): + return left < right + case (.dictionary(let left), .dictionary(let right)): + return left < right + default: + return false + } + } + + +} extension JSON: Collection { - - public typealias Index = JSONIndex - + + public typealias Index = JSONRawIndex + public var startIndex: Index { switch type @@ -245,12 +281,12 @@ extension JSON: Collection case .array: return .array(rawArray.startIndex) case .dictionary: - return .dictionary(dictionaryValue.startIndex) + return .dictionary(rawDictionary.startIndex) default: return .null } } - + public var endIndex: Index { switch type @@ -258,12 +294,12 @@ extension JSON: Collection case .array: return .array(rawArray.endIndex) case .dictionary: - return .dictionary(dictionaryValue.endIndex) + return .dictionary(rawDictionary.endIndex) default: return .null } } - + public func index(after i: Index) -> Index { switch i @@ -271,13 +307,13 @@ extension JSON: Collection case .array(let idx): return .array(rawArray.index(after: idx)) case .dictionary(let idx): - return .dictionary(dictionaryValue.index(after: idx)) + return .dictionary(rawDictionary.index(after: idx)) default: return .null } - + } - + public subscript (position: Index) -> (String, JSON) { switch position @@ -285,13 +321,14 @@ extension JSON: Collection case .array(let idx): return (String(idx), JSON(self.rawArray[idx])) case .dictionary(let idx): - return dictionaryValue[idx] + let (key, value) = self.rawDictionary[idx] + return (key, JSON(value)) default: return ("", JSON.null) } } - - + + } // MARK: - Subscript @@ -322,7 +359,7 @@ extension String: JSONSubscriptType { } extension JSON { - + /// If `type` is `.Array`, return json whose object is `array[index]`, otherwise return null json with error. fileprivate subscript(index index: Int) -> JSON { get { @@ -346,7 +383,7 @@ extension JSON { } } } - + /// If `type` is `.Dictionary`, return json whose object is `dictionary[key]` , otherwise return null json with error. fileprivate subscript(key key: String) -> JSON { get { @@ -368,7 +405,7 @@ extension JSON { } } } - + /// If `sub` is `Int`, return `subscript(index:)`; If `sub` is `String`, return `subscript(key:)`. fileprivate subscript(sub sub: JSONSubscriptType) -> JSON { get { @@ -384,18 +421,18 @@ extension JSON { } } } - + /** Find a json in the complex data structures by using array of Int and/or String as path. - + - parameter path: The target json's path. Example: - + let json = JSON[data] let path = [9,"list","person","name"] let name = json[path] - + The same as: let name = json[9]["list"]["person"]["name"] - + - returns: Return a json found by the path or a null json with error */ public subscript(path: [JSONSubscriptType]) -> JSON { @@ -416,16 +453,16 @@ extension JSON { } } } - + /** Find a json in the complex data structures by using array of Int and/or String as path. - + - parameter path: The target json's path. Example: - + let name = json[9,"list","person","name"] - + The same as: let name = json[9]["list"]["person"]["name"] - + - returns: Return a json found by the path or a null json with error */ public subscript(path: JSONSubscriptType...) -> JSON { @@ -441,36 +478,36 @@ extension JSON { // MARK: - LiteralConvertible extension JSON: Swift.ExpressibleByStringLiteral { - + public init(stringLiteral value: StringLiteralType) { self.init(value as Any) } - + public init(extendedGraphemeClusterLiteral value: StringLiteralType) { self.init(value as Any) } - + public init(unicodeScalarLiteral value: StringLiteralType) { self.init(value as Any) } } extension JSON: Swift.ExpressibleByIntegerLiteral { - + public init(integerLiteral value: IntegerLiteralType) { self.init(value as Any) } } extension JSON: Swift.ExpressibleByBooleanLiteral { - + public init(booleanLiteral value: BooleanLiteralType) { self.init(value as Any) } } extension JSON: Swift.ExpressibleByFloatLiteral { - + public init(floatLiteral value: FloatLiteralType) { self.init(value as Any) } @@ -481,7 +518,7 @@ extension JSON: Swift.ExpressibleByDictionaryLiteral { let array = elements self.init(dictionaryLiteral: array) } - + public init(dictionaryLiteral elements: [(String, Any)]) { let jsonFromDictionaryLiteral: ([String : Any]) -> JSON = { dictionary in let initializeElement = Array(dictionary.keys).flatMap { key -> (String, Any)? in @@ -492,9 +529,9 @@ extension JSON: Swift.ExpressibleByDictionaryLiteral { } return JSON(dictionaryLiteral: initializeElement) } - + var dict = [String : Any](minimumCapacity: elements.count) - + for element in elements { let elementToSet: Any if let json = element.1 as? JSON { @@ -511,13 +548,13 @@ extension JSON: Swift.ExpressibleByDictionaryLiteral { } dict[element.0] = elementToSet } - + self.init(dict) } } extension JSON: Swift.ExpressibleByArrayLiteral { - + public init(arrayLiteral elements: Any...) { self.init(elements as Any) } @@ -534,7 +571,7 @@ extension JSON: Swift.ExpressibleByNilLiteral { // MARK: - Raw extension JSON: Swift.RawRepresentable { - + public init?(rawValue: Any) { if JSON(rawValue).type == .unknown { return nil @@ -542,19 +579,19 @@ extension JSON: Swift.RawRepresentable { self.init(rawValue) } } - + public var rawValue: Any { return self.object } - + public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data { guard JSONSerialization.isValidJSONObject(self.object) else { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "JSON is invalid"]) } - + return try JSONSerialization.data(withJSONObject: self.object, options: opt) } - + public func rawString(_ encoding: String.Encoding = String.Encoding.utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? { switch self.type { case .array, .dictionary: @@ -581,7 +618,7 @@ extension JSON: Swift.RawRepresentable { // MARK: - Printable, DebugPrintable extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertible { - + public var description: String { if let string = self.rawString(options:.prettyPrinted) { return string @@ -589,7 +626,7 @@ extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertibl return "unknown" } } - + public var debugDescription: String { return description } @@ -598,7 +635,7 @@ extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertibl // MARK: - Array extension JSON { - + //Optional [JSON] public var array: [JSON]? { get { @@ -609,14 +646,14 @@ extension JSON { } } } - + //Non-optional [JSON] public var arrayValue: [JSON] { get { return self.array ?? [] } } - + //Optional [AnyObject] public var arrayObject: [Any]? { get { @@ -640,7 +677,7 @@ extension JSON { // MARK: - Dictionary extension JSON { - + //Optional [String : JSON] public var dictionary: [String : JSON]? { if self.type == .dictionary { @@ -653,12 +690,12 @@ extension JSON { return nil } } - + //Non-optional [String : JSON] public var dictionaryValue: [String : JSON] { return self.dictionary ?? [:] } - + //Optional [String : AnyObject] public var dictionaryObject: [String : Any]? { get { @@ -682,7 +719,7 @@ extension JSON { // MARK: - Bool extension JSON { // : Swift.Bool - + //Optional bool public var bool: Bool? { get { @@ -701,7 +738,7 @@ extension JSON { // : Swift.Bool } } } - + //Non-optional bool public var boolValue: Bool { get { @@ -727,7 +764,7 @@ extension JSON { // : Swift.Bool // MARK: - String extension JSON { - + //Optional string public var string: String? { get { @@ -746,7 +783,7 @@ extension JSON { } } } - + //Non-optional string public var stringValue: String { get { @@ -769,7 +806,7 @@ extension JSON { // MARK: - Number extension JSON { - + //Optional number public var number: NSNumber? { get { @@ -786,7 +823,7 @@ extension JSON { self.object = newValue ?? NSNull() } } - + //Non-optional number public var numberValue: NSNumber { get { @@ -813,7 +850,7 @@ extension JSON { //MARK: - Null extension JSON { - + public var null: NSNull? { get { switch self.type { @@ -839,7 +876,7 @@ extension JSON { //MARK: - URL extension JSON { - + //Optional URL public var URL: URL? { get { @@ -864,7 +901,7 @@ extension JSON { // MARK: - Int, Double, Float, Int8, Int16, Int32, Int64 extension JSON { - + public var double: Double? { get { return self.number?.doubleValue @@ -877,7 +914,7 @@ extension JSON { } } } - + public var doubleValue: Double { get { return self.numberValue.doubleValue @@ -886,7 +923,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var float: Float? { get { return self.number?.floatValue @@ -899,7 +936,7 @@ extension JSON { } } } - + public var floatValue: Float { get { return self.numberValue.floatValue @@ -908,7 +945,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int: Int? { get @@ -926,7 +963,7 @@ extension JSON { } } } - + public var intValue: Int { get { return self.numberValue.intValue @@ -935,7 +972,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt: UInt? { get { return self.number?.uintValue @@ -948,7 +985,7 @@ extension JSON { } } } - + public var uIntValue: UInt { get { return self.numberValue.uintValue @@ -957,7 +994,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int8: Int8? { get { return self.number?.int8Value @@ -970,7 +1007,7 @@ extension JSON { } } } - + public var int8Value: Int8 { get { return self.numberValue.int8Value @@ -979,7 +1016,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt8: UInt8? { get { return self.number?.uint8Value @@ -992,7 +1029,7 @@ extension JSON { } } } - + public var uInt8Value: UInt8 { get { return self.numberValue.uint8Value @@ -1001,7 +1038,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int16: Int16? { get { return self.number?.int16Value @@ -1014,7 +1051,7 @@ extension JSON { } } } - + public var int16Value: Int16 { get { return self.numberValue.int16Value @@ -1023,7 +1060,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt16: UInt16? { get { return self.number?.uint16Value @@ -1036,7 +1073,7 @@ extension JSON { } } } - + public var uInt16Value: UInt16 { get { return self.numberValue.uint16Value @@ -1045,7 +1082,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int32: Int32? { get { return self.number?.int32Value @@ -1058,7 +1095,7 @@ extension JSON { } } } - + public var int32Value: Int32 { get { return self.numberValue.int32Value @@ -1067,7 +1104,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt32: UInt32? { get { return self.number?.uint32Value @@ -1080,7 +1117,7 @@ extension JSON { } } } - + public var uInt32Value: UInt32 { get { return self.numberValue.uint32Value @@ -1089,7 +1126,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var int64: Int64? { get { return self.number?.int64Value @@ -1102,7 +1139,7 @@ extension JSON { } } } - + public var int64Value: Int64 { get { return self.numberValue.int64Value @@ -1111,7 +1148,7 @@ extension JSON { self.object = NSNumber(value: newValue) } } - + public var uInt64: UInt64? { get { return self.number?.uint64Value @@ -1124,7 +1161,7 @@ extension JSON { } } } - + public var uInt64Value: UInt64 { get { return self.numberValue.uint64Value @@ -1139,7 +1176,7 @@ extension JSON { extension JSON : Swift.Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber == rhs.rawNumber @@ -1159,7 +1196,7 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { } public func <=(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber <= rhs.rawNumber @@ -1179,7 +1216,7 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { } public func >=(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber >= rhs.rawNumber @@ -1199,7 +1236,7 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { } public func >(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber > rhs.rawNumber @@ -1211,7 +1248,7 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { } public func <(lhs: JSON, rhs: JSON) -> Bool { - + switch (lhs.type, rhs.type) { case (.number, .number): return lhs.rawNumber < rhs.rawNumber @@ -1258,7 +1295,7 @@ func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { } func <(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1270,7 +1307,7 @@ func <(lhs: NSNumber, rhs: NSNumber) -> Bool { } func >(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1282,7 +1319,7 @@ func >(lhs: NSNumber, rhs: NSNumber) -> Bool { } func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1294,7 +1331,7 @@ func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { } func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { - + switch (lhs.isBool, rhs.isBool) { case (false, true): return false From e64f17ffdbc3a11bafbb200b6d5e07933d7c603e Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 16 Nov 2016 23:07:25 +0800 Subject: [PATCH 306/470] Add performance test --- Tests/SwiftyJSONTests/SequenceTypeTests.swift | 60 +++++++++++-------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/Tests/SwiftyJSONTests/SequenceTypeTests.swift b/Tests/SwiftyJSONTests/SequenceTypeTests.swift index a9ff6cf6..62bd7dcf 100644 --- a/Tests/SwiftyJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftyJSONTests/SequenceTypeTests.swift @@ -46,7 +46,7 @@ class SequenceTypeTests: XCTestCase { XCTFail("Can't find the test JSON file") } } - + func testArrayAllNumber() { var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] XCTAssertEqual(json.count, 5) @@ -62,11 +62,11 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(index, 5) XCTAssertEqual(array, [1,2.0,3.3,123456789,987654321.123456789]) } - + func testArrayAllBool() { var json:JSON = JSON([true, false, false, true, true]) XCTAssertEqual(json.count, 5) - + var index = 0 var array = [Bool]() for (i, sub) in json { @@ -78,11 +78,11 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(index, 5) XCTAssertEqual(array, [true, false, false, true, true]) } - + func testArrayAllString() { var json:JSON = JSON(rawValue: ["aoo","bpp","zoo"] as NSArray)! XCTAssertEqual(json.count, 3) - + var index = 0 var array = [String]() for (i, sub) in json { @@ -94,11 +94,11 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(index, 3) XCTAssertEqual(array, ["aoo","bpp","zoo"]) } - + func testArrayWithNull() { var json:JSON = JSON(rawValue: ["aoo","bpp", NSNull() ,"zoo"] as NSArray)! XCTAssertEqual(json.count, 4) - + var index = 0 var array = [AnyObject]() for (i, sub) in json { @@ -111,11 +111,11 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual(array[0] as? String, "aoo") XCTAssertEqual(array[2] as? NSNull, NSNull()) } - + func testArrayAllDictionary() { var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] XCTAssertEqual(json.count, 3) - + var index = 0 var array = [AnyObject]() for (i, sub) in json { @@ -131,11 +131,11 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual((array[1] as! [String : String])["b"]!, "B") XCTAssertEqual((array[2] as! [String : NSNull])["null"]!, NSNull()) } - + func testDictionaryAllNumber() { var json:JSON = ["double":1.11111, "int":987654321] XCTAssertEqual(json.count, 2) - + var index = 0 var dictionary = [String:NSNumber]() for (key, sub) in json { @@ -143,16 +143,16 @@ class SequenceTypeTests: XCTestCase { dictionary[key] = sub.number! index += 1 } - + XCTAssertEqual(index, 2) XCTAssertEqual(dictionary["double"]! as NSNumber, 1.11111) XCTAssertEqual(dictionary["int"]! as NSNumber, 987654321) } - + func testDictionaryAllBool() { var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] XCTAssertEqual(json.count, 5) - + var index = 0 var dictionary = [String:Bool]() for (key, sub) in json { @@ -160,16 +160,16 @@ class SequenceTypeTests: XCTestCase { dictionary[key] = sub.bool! index += 1 } - + XCTAssertEqual(index, 5) XCTAssertEqual(dictionary["t"]! as Bool, true) XCTAssertEqual(dictionary["false"]! as Bool, false) } - + func testDictionaryAllString() { var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! XCTAssertEqual(json.count, 3) - + var index = 0 var dictionary = [String:String]() for (key, sub) in json { @@ -177,16 +177,16 @@ class SequenceTypeTests: XCTestCase { dictionary[key] = sub.string! index += 1 } - + XCTAssertEqual(index, 3) XCTAssertEqual(dictionary["a"]! as String, "aoo") XCTAssertEqual(dictionary["bb"]! as String, "bpp") } - + func testDictionaryWithNull() { var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! XCTAssertEqual(json.count, 4) - + var index = 0 var dictionary = [String:AnyObject]() for (key, sub) in json { @@ -194,18 +194,18 @@ class SequenceTypeTests: XCTestCase { dictionary[key] = sub.object as AnyObject? index += 1 } - + XCTAssertEqual(index, 4) XCTAssertEqual(dictionary["a"]! as? String, "aoo") XCTAssertEqual(dictionary["bb"]! as? String, "bpp") XCTAssertEqual(dictionary["null"]! as? NSNull, NSNull()) } - + func testDictionaryAllArray() { var json:JSON = JSON (["Number":[NSNumber(value:1),NSNumber(value:2.123456),NSNumber(value:123456789)], "String":["aa","bbb","cccc"], "Mix":[true, "766", NSNull(), 655231.9823]]) XCTAssertEqual(json.count, 3) - + var index = 0 var dictionary = [String:AnyObject]() for (key, sub) in json { @@ -213,7 +213,7 @@ class SequenceTypeTests: XCTestCase { dictionary[key] = sub.object as AnyObject? index += 1 } - + XCTAssertEqual(index, 3) XCTAssertEqual((dictionary["Number"] as! NSArray)[0] as? Int, 1) XCTAssertEqual((dictionary["Number"] as! NSArray)[1] as? Double, 2.123456) @@ -223,4 +223,16 @@ class SequenceTypeTests: XCTestCase { XCTAssertEqual((dictionary["Mix"] as! NSArray)[2] as? NSNull, NSNull()) XCTAssertEqual((dictionary["Mix"] as! NSArray)[3] as? Double, 655231.9823) } + + func testDictionaryIteratingPerformance() { + var json: JSON = [:] + for i in 1...1000 { + json[String(i)] = "hello" + } + measure { + for (key, value) in json { + print(key, value) + } + } + } } From 885c387169ed3f62032158a6f5235884d436a1f9 Mon Sep 17 00:00:00 2001 From: Zhigang Fang Date: Wed, 16 Nov 2016 23:22:21 +0800 Subject: [PATCH 307/470] Update version in pod spec --- SwiftyJSON.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 1a29fe55..111a6976 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "3.1.1" + s.version = "3.1.3" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -11,7 +11,7 @@ Pod::Spec.new do |s| s.ios.deployment_target = "8.0" s.watchos.deployment_target = "2.0" s.tvos.deployment_target = "9.0" - s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => "v#{s.version}" } + s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => s.version } s.source_files = "Source/*.swift" s.pod_target_xcconfig = { 'SWIFT_VERSION' => '3.0', From c911942dd1ccd710d8ae106ca51654864bed1d16 Mon Sep 17 00:00:00 2001 From: Simon Tsai Date: Wed, 16 Nov 2016 11:23:13 -0500 Subject: [PATCH 308/470] Instead of checking for the Int8 type explicitly when setting 'object', cast the Int8 value to an Int and pass that into an NSNumber when setting 'int8' or 'int8Value' --- Source/SwiftyJSON.swift | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 4aa6fcc7..c9de1969 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -157,9 +157,6 @@ public struct JSON { set { _error = nil switch newValue { - case let int8Value as Int8 where type(of: newValue) == Int8.self: - _type = .number - self.rawNumber = NSNumber(value: Int(int8Value)) case let number as NSNumber: if number.isBool { _type = .bool @@ -967,7 +964,7 @@ extension JSON { } set { if let newValue = newValue { - self.object = newValue + self.object = NSNumber(value: Int(newValue)) } else { self.object = NSNull() } @@ -979,7 +976,7 @@ extension JSON { return self.numberValue.int8Value } set { - self.object = newValue + self.object = NSNumber(value: Int(newValue)) } } From 9a79305facf4a0966022b5431b242609e65af6b0 Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Mon, 26 Sep 2016 09:19:18 -0700 Subject: [PATCH 309/470] represent strings with nil as if it was nsnull --- Source/SwiftyJSON.swift | 71 ++++++++++++++++++++-- Tests/SwiftyJSONTests/PrintableTests.swift | 42 +++++++++++++ 2 files changed, 107 insertions(+), 6 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 43483c11..ab0c676f 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -171,8 +171,9 @@ public struct JSON { case _ as NSNull: _type = .null case let array as [JSON]: - _type = .array - self.rawArray = array.map { $0.object } + _type = .array + case nil: + _type = .null case let array as [Any]: _type = .array self.rawArray = array @@ -591,13 +592,71 @@ extension JSON: Swift.RawRepresentable { return try JSONSerialization.data(withJSONObject: self.object, options: opt) } + + public func rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted, maxDepth: Int = 10) -> String? { + do { + return try _rawString(encoding, options: opt, maxDepth: maxDepth) + } catch { + print("Could not serialize object to JSON because:", error.localizedDescription) + return nil + } + } - public func rawString(_ encoding: String.Encoding = String.Encoding.utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? { + private func _rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted, maxDepth: Int = 10) throws -> String? { + if (maxDepth < 0) { + throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Element too deep. Increase maxDepth and make sure there is no reference loop"]) + } switch self.type { - case .array, .dictionary: + case .dictionary: + do { + guard let dict = self.object as? [String: Any?] else { + return nil + } + let body = try dict.keys.map { key throws -> String in + guard let value = dict[key] else { + return "\"\(key)\": null" + } + guard value != nil else { + return "\"\(key)\": null" + } + + let nestedValue = JSON(value) + guard let nestedString = try nestedValue._rawString(encoding, options: opt, maxDepth: maxDepth - 1) else { + throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) + } + if nestedValue.type == .string { + return "\"\(key)\": \"\(nestedString.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\""))\"" + } else { + return "\"\(key)\": \(nestedString)" + } + } + + return "{\(body.joined(separator: ","))}" + } catch _ { + return nil + } + case .array: do { - let data = try self.rawData(options: opt) - return String(data: data, encoding: encoding) + guard let array = self.object as? [Any?] else { + return nil + } + let body = try array.map { value throws -> String in + guard value != nil else { + return "null" + } + + let nestedValue = JSON(value) + guard let nestedString = try nestedValue._rawString(encoding, options: opt, maxDepth: maxDepth - 1) else { + throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) + } + if nestedValue.type == .string { + return "\"\(nestedString.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\""))\"" + } else { + return nestedString + } + } + + return "[\(body.joined(separator: ","))]" } catch _ { return nil } diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index 5672c13a..849b6581 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -62,6 +62,26 @@ class PrintableTests: XCTestCase { XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) XCTAssertTrue(json.debugDescription.lengthOfBytes(using: String.Encoding.utf8) > 0) } + + func testArrayWithStrings() { + let array = ["\"123\""] + let json = JSON(array) + var description = json.description.replacingOccurrences(of: "\n", with: "") + description = description.replacingOccurrences(of: " ", with: "") + XCTAssertEqual(description, "[\"\\\"123\\\"\"]") + XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) + XCTAssertTrue(json.debugDescription.lengthOfBytes(using: String.Encoding.utf8) > 0) + } + + func testArrayWithOptionals() { + let array = [1,2,"4",5,"6",nil] as [Any?] + let json = JSON(array) + var description = json.description.replacingOccurrences(of: "\n", with: "") + description = description.replacingOccurrences(of: " ", with: "") + XCTAssertEqual(description, "[1,2,\"4\",5,\"6\",null]") + XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) + XCTAssertTrue(json.debugDescription.lengthOfBytes(using: String.Encoding.utf8) > 0) + } func testDictionary() { let json:JSON = ["1":2,"2":"two", "3":3] @@ -72,4 +92,26 @@ class PrintableTests: XCTestCase { XCTAssertTrue(debugDescription.range(of: "\"2\":\"two\"", options: String.CompareOptions.caseInsensitive) != nil) XCTAssertTrue(debugDescription.range(of: "\"3\":3", options: String.CompareOptions.caseInsensitive) != nil) } + + func testDictionaryWithStrings() { + let dict = ["foo":"{\"bar\":123}"] as [String : Any] + let json = JSON(dict) + var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") + debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") + XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) + let exceptedResult = "{\"foo\":\"{\\\"bar\\\":123}\"}" + XCTAssertEqual(debugDescription, exceptedResult) + } + + func testDictionaryWithOptionals() { + let dict = ["1":2, "2":"two", "3": nil] as [String: Any?] + let json = JSON(dict) + var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") + debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") + print("debugDescription", debugDescription) + XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) + XCTAssertTrue(debugDescription.range(of: "\"1\":2", options: NSString.CompareOptions.caseInsensitive) != nil) + XCTAssertTrue(debugDescription.range(of: "\"2\":\"two\"", options: NSString.CompareOptions.caseInsensitive) != nil) + XCTAssertTrue(debugDescription.range(of: "\"3\":null", options: NSString.CompareOptions.caseInsensitive) != nil) + } } From 62b490c5f972198480cd0c5bcdc6ad9a27841320 Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Mon, 26 Sep 2016 10:00:23 -0700 Subject: [PATCH 310/470] make casting nil to nsnull optional --- Source/SwiftyJSON.swift | 120 +++++++++++++-------- Tests/SwiftyJSONTests/PrintableTests.swift | 21 ++-- 2 files changed, 91 insertions(+), 50 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index ab0c676f..58d0617b 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -591,52 +591,79 @@ extension JSON: Swift.RawRepresentable { } return try JSONSerialization.data(withJSONObject: self.object, options: opt) - } - - public func rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted, maxDepth: Int = 10) -> String? { - do { - return try _rawString(encoding, options: opt, maxDepth: maxDepth) - } catch { - print("Could not serialize object to JSON because:", error.localizedDescription) - return nil - } - } - - private func _rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted, maxDepth: Int = 10) throws -> String? { - if (maxDepth < 0) { - throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Element too deep. Increase maxDepth and make sure there is no reference loop"]) + } + + public func rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? { + do { + return try _rawString(encoding, options: [.jsonSerialization: opt]) + } catch { + print("Could not serialize object to JSON because:", error.localizedDescription) + return nil + } + } + + public func rawString(options: [writtingOptionsKeys: Any]) -> String? { + let encoding = options[.encoding] as? String.Encoding ?? String.Encoding.utf8 + let maxObjectDepth = options[.maxObjextDepth] as? Int ?? 10 + do { + return try _rawString(encoding, options: options, maxObjectDepth: maxObjectDepth) + } catch { + print("Could not serialize object to JSON because:", error.localizedDescription) + return nil + } + } + + private func _rawString( + _ encoding: String.Encoding = .utf8, + options: [writtingOptionsKeys: Any], + maxObjectDepth: Int = 10 + ) throws -> String? { + if (maxObjectDepth < 0) { + throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Element too deep. Increase maxObjectDepth and make sure there is no reference loop"]) } switch self.type { - case .dictionary: + case .dictionary: + do { + if !(options[.castNilToNSNull] as? Bool ?? false) { + let jsonOption = options[.jsonSerialization] as? JSONSerialization.WritingOptions ?? JSONSerialization.WritingOptions.prettyPrinted + let data = try self.rawData(options: jsonOption) + return String(data: data, encoding: encoding) + } + + guard let dict = self.object as? [String: Any?] else { + return nil + } + let body = try dict.keys.map { key throws -> String in + guard let value = dict[key] else { + return "\"\(key)\": null" + } + guard value != nil else { + return "\"\(key)\": null" + } + + let nestedValue = JSON(value) + guard let nestedString = try nestedValue._rawString(encoding, options: options, maxObjectDepth: maxObjectDepth - 1) else { + throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) + } + if nestedValue.type == .string { + return "\"\(key)\": \"\(nestedString.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\""))\"" + } else { + return "\"\(key)\": \(nestedString)" + } + } + + return "{\(body.joined(separator: ","))}" + } catch _ { + return nil + } + case .array: do { - guard let dict = self.object as? [String: Any?] else { - return nil - } - let body = try dict.keys.map { key throws -> String in - guard let value = dict[key] else { - return "\"\(key)\": null" - } - guard value != nil else { - return "\"\(key)\": null" - } + if !(options[.castNilToNSNull] as? Bool ?? false) { + let jsonOption = options[.jsonSerialization] as? JSONSerialization.WritingOptions ?? JSONSerialization.WritingOptions.prettyPrinted + let data = try self.rawData(options: jsonOption) + return String(data: data, encoding: encoding) + } - let nestedValue = JSON(value) - guard let nestedString = try nestedValue._rawString(encoding, options: opt, maxDepth: maxDepth - 1) else { - throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) - } - if nestedValue.type == .string { - return "\"\(key)\": \"\(nestedString.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\""))\"" - } else { - return "\"\(key)\": \(nestedString)" - } - } - - return "{\(body.joined(separator: ","))}" - } catch _ { - return nil - } - case .array: - do { guard let array = self.object as? [Any?] else { return nil } @@ -646,7 +673,7 @@ extension JSON: Swift.RawRepresentable { } let nestedValue = JSON(value) - guard let nestedString = try nestedValue._rawString(encoding, options: opt, maxDepth: maxDepth - 1) else { + guard let nestedString = try nestedValue._rawString(encoding, options: options, maxObjectDepth: maxObjectDepth - 1) else { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) } if nestedValue.type == .string { @@ -1404,3 +1431,10 @@ func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { return lhs.compare(rhs) != .orderedAscending } } + +public enum writtingOptionsKeys { + case jsonSerialization + case castNilToNSNull + case maxObjextDepth + case encoding +} diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index 849b6581..d8361685 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -76,7 +76,11 @@ class PrintableTests: XCTestCase { func testArrayWithOptionals() { let array = [1,2,"4",5,"6",nil] as [Any?] let json = JSON(array) - var description = json.description.replacingOccurrences(of: "\n", with: "") + guard var description = json.rawString(options: [.castNilToNSNull: true]) else { + XCTFail("could not represent array") + return + } + description = description.replacingOccurrences(of: "\n", with: "") description = description.replacingOccurrences(of: " ", with: "") XCTAssertEqual(description, "[1,2,\"4\",5,\"6\",null]") XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) @@ -106,12 +110,15 @@ class PrintableTests: XCTestCase { func testDictionaryWithOptionals() { let dict = ["1":2, "2":"two", "3": nil] as [String: Any?] let json = JSON(dict) - var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") - debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") - print("debugDescription", debugDescription) + guard var description = json.rawString(options: [.castNilToNSNull: true]) else { + XCTFail("could not represent dictionary") + return + } + description = description.replacingOccurrences(of: "\n", with: "") + description = description.replacingOccurrences(of: " ", with: "") XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) - XCTAssertTrue(debugDescription.range(of: "\"1\":2", options: NSString.CompareOptions.caseInsensitive) != nil) - XCTAssertTrue(debugDescription.range(of: "\"2\":\"two\"", options: NSString.CompareOptions.caseInsensitive) != nil) - XCTAssertTrue(debugDescription.range(of: "\"3\":null", options: NSString.CompareOptions.caseInsensitive) != nil) + XCTAssertTrue(description.range(of: "\"1\":2", options: NSString.CompareOptions.caseInsensitive) != nil) + XCTAssertTrue(description.range(of: "\"2\":\"two\"", options: NSString.CompareOptions.caseInsensitive) != nil) + XCTAssertTrue(description.range(of: "\"3\":null", options: NSString.CompareOptions.caseInsensitive) != nil) } } From 5c18ba9df5307ebacfbf9046562a1ac2fd376bc9 Mon Sep 17 00:00:00 2001 From: Guillaume Sabran Date: Wed, 16 Nov 2016 14:40:21 -0800 Subject: [PATCH 311/470] update readme --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 0f29db0b..f1c1ab62 100644 --- a/README.md +++ b/README.md @@ -442,6 +442,17 @@ let auth: JSON = [ ] ``` +## String representation +There are two options available: +- use the default Swift one +- use a custom one that will handle optionals well and represent `nil` as `"null"`: +```swift +let data = ["1":2, "2":"two", "3": nil] as [String: Any?] +let json = JSON(dict) +let representation = json.rawString(options: [.castNilToNSNull: true]) +// representation is "{\"1\":2,\"2\":\"two\",\"3\":null}", which represents {"1":2,"2":"two","3":null} +``` + ## Work with Alamofire SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: From 588db575856bfb1625d22cec5c16f15008327df9 Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Thu, 17 Nov 2016 16:34:02 +0100 Subject: [PATCH 312/470] Added a function to deep merge a JSON object into another JSON object destructively and non-destructively. --- Source/SwiftyJSON.swift | 36 +++++++++++ SwiftyJSON.xcodeproj/project.pbxproj | 8 +++ Tests/SwiftyJSONTests/MergeTests.swift | 84 ++++++++++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 Tests/SwiftyJSONTests/MergeTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 58d0617b..3e533bb2 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -123,6 +123,42 @@ public struct JSON { } self.init(dictionary) } + + /** + Merges another JSON into this JSON, whereas primitive values which are not present in this JSON are getting added, + present values getting overwritten, array values getting appended and nested JSONs getting merged the same way. + + - parameter other: The JSON which gets merged into this JSON + */ + public mutating func merge(_ other: JSON) { + if self.type == other.type { + switch self.type { + case .dictionary: + for (key, _) in other { + self[key].merge(other[key]) + } + case .array: + self = JSON(self.arrayValue + other.arrayValue) + default: + self = other + } + } else { + self = other + } + } + + /** + Merges another JSON into this JSON and returns a new JSON, whereas primitive values which are not present in this JSON are getting added, + present values getting overwritten, array values getting appended and nested JSONS getting merged the same way. + + - parameter other: The JSON which gets merged into this JSON + - returns: New merged JSON + */ + public func merged(other: JSON) -> JSON { + var merged = self + merged.merge(other) + return merged + } /// Private object fileprivate var rawArray: [Any] = [] diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 4bddfa14..c4e6df5e 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 1B587CC61DDE04770012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; + 1B587CC71DDE04780012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; + 1B587CC81DDE04790012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; 2E4FEFE119575BE100351305 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 2E4FEFE719575BE100351305 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */; }; 5DD502911D9B21810004C112 /* NestedJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD502901D9B21810004C112 /* NestedJSONTests.swift */; }; @@ -91,6 +94,7 @@ /* Begin PBXFileReference section */ 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; + 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MergeTests.swift; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; @@ -226,6 +230,7 @@ 2E4FEFEA19575BE100351305 /* SwiftyJSONTests */ = { isa = PBXGroup; children = ( + 1B587CC41DDE04360012D8DB /* MergeTests.swift */, A885D1DA19CFCFF0002FD4C3 /* Tests.json */, A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */, A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */, @@ -550,6 +555,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1B587CC61DDE04770012D8DB /* MergeTests.swift in Sources */, A87080E819E439DA00CDE086 /* NumberTests.swift in Sources */, A87080E419E3C2A600CDE086 /* SequenceTypeTests.swift in Sources */, 5DD502911D9B21810004C112 /* NestedJSONTests.swift in Sources */, @@ -587,6 +593,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1B587CC71DDE04780012D8DB /* MergeTests.swift in Sources */, 9C459EFB1A9103C1008C9A41 /* SequenceTypeTests.swift in Sources */, 9C459F001A9103C1008C9A41 /* ComparableTests.swift in Sources */, 5DD502921D9B21810004C112 /* NestedJSONTests.swift in Sources */, @@ -608,6 +615,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 1B587CC81DDE04790012D8DB /* MergeTests.swift in Sources */, A8580F801BCF69A000DA927B /* PerformanceTests.swift in Sources */, A8580F811BCF69A000DA927B /* BaseTests.swift in Sources */, 5DD502931D9B21810004C112 /* NestedJSONTests.swift in Sources */, diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift new file mode 100644 index 00000000..10564bf7 --- /dev/null +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -0,0 +1,84 @@ +// +// JSONTests.swift +// +// Created by Daniel Kiedrowski on 17.11.16. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import XCTest +import SwiftyJSON + +class JSONTests: XCTestCase { + func testPrimitiveType() { + let A = JSON("a") + let B = JSON("b") + XCTAssertEqual(A.merged(other: B), B) + } + + func testMergeEqual() { + let json = JSON(["a": "A"]) + XCTAssertEqual(json.merged(other: json), json) + } + + func testMergeUnequalValues() { + let A = JSON(["a": "A"]) + let B = JSON(["a": "B"]) + XCTAssertEqual(A.merged(other: B), B) + } + + func testMergeUnequalKeysAndValues() { + let A = JSON(["a": "A"]) + let B = JSON(["b": "B"]) + XCTAssertEqual(A.merged(other: B), JSON(["a": "A", "b": "B"])) + } + + func testMergeFilledAndEmpty() { + let A = JSON(["a": "A"]) + let B = JSON([:]) + XCTAssertEqual(A.merged(other: B), A) + } + + func testMergeEmptyAndFilled() { + let A = JSON([:]) + let B = JSON(["a": "A"]) + XCTAssertEqual(A.merged(other: B), B) + } + + func testMergeArray() { + let A = JSON(["a"]) + let B = JSON(["b"]) + XCTAssertEqual(A.merged(other: B), JSON(["a", "b"])) + } + + func testMergeNestedJSONs() { + let A = JSON([ + "nested": [ + "A": "a" + ] + ]) + + let B = JSON([ + "nested": [ + "A": "b" + ] + ]) + + XCTAssertEqual(A.merged(other: B), B) + } +} From 6de5453a604597914d23b5a0cd4f9ea6581dc21c Mon Sep 17 00:00:00 2001 From: Fang-Pen Lin Date: Sun, 20 Nov 2016 22:27:25 -0800 Subject: [PATCH 313/470] Fix duplicate comma typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1c1ab62..0d2798a6 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ It's not good. Even if we use optional chaining, it would be messy: ```swift -if let JSONObject = try JSONSerialization.jsonObject(with: data,, options: .allowFragments) as? [[String: Any]], +if let JSONObject = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: Any]], let username = (JSONObject[0]["user"] as? [String: Any])?["name"] as? String { // There's our username } From 1eac774469ff84924dc998932b7b245656c15c7f Mon Sep 17 00:00:00 2001 From: Christopher Katzmann Date: Mon, 21 Nov 2016 15:25:31 -0600 Subject: [PATCH 314/470] update Integration section of README to reflect latest version in SPM usage subsection --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f1c1ab62..5d86f477 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ let package = Package( name: "YOUR_PROJECT_NAME", targets: [], dependencies: [ - .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", versions: Version(1,0,0).. Date: Mon, 21 Nov 2016 20:10:06 -0800 Subject: [PATCH 315/470] Fix all compilation warnings --- Source/SwiftyJSON.swift | 10 +++++----- Tests/SwiftyJSONTests/NumberTests.swift | 4 +--- Tests/SwiftyJSONTests/RawTests.swift | 12 ++++-------- Tests/SwiftyJSONTests/StringTests.swift | 8 +++++--- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 58d0617b..f74e21b5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -170,7 +170,7 @@ public struct JSON { self.rawString = string case _ as NSNull: _type = .null - case let array as [JSON]: + case _ as [JSON]: _type = .array case nil: _type = .null @@ -637,11 +637,11 @@ extension JSON: Swift.RawRepresentable { guard let value = dict[key] else { return "\"\(key)\": null" } - guard value != nil else { + guard let unwrappedValue = value else { return "\"\(key)\": null" } - let nestedValue = JSON(value) + let nestedValue = JSON(unwrappedValue) guard let nestedString = try nestedValue._rawString(encoding, options: options, maxObjectDepth: maxObjectDepth - 1) else { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) } @@ -668,11 +668,11 @@ extension JSON: Swift.RawRepresentable { return nil } let body = try array.map { value throws -> String in - guard value != nil else { + guard let unwrappedValue = value else { return "null" } - let nestedValue = JSON(value) + let nestedValue = JSON(unwrappedValue) guard let nestedString = try nestedValue._rawString(encoding, options: options, maxObjectDepth: maxObjectDepth - 1) else { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) } diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index 37e89cc8..828bae68 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -189,7 +189,6 @@ class NumberTests: XCTestCase { json.int8Value = n0.int8Value XCTAssertTrue(json.int8! == n0.int8Value) XCTAssertTrue(json.int8Value == n0.int8Value) - print(json.number) XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) XCTAssertEqual(json.stringValue, "0") @@ -260,8 +259,7 @@ class NumberTests: XCTestCase { json.int16Value = n0.int16Value XCTAssertTrue(json.int16! == n0.int16Value) XCTAssertTrue(json.int16Value == n0.int16Value) - print(json.number) - XCTAssertTrue(json.number! == n0) + XCTAssertEqual(json.number, n0) XCTAssertEqual(json.numberValue, n0) XCTAssertEqual(json.stringValue, "0") diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift index a31b84ef..d45f1cec 100644 --- a/Tests/SwiftyJSONTests/RawTests.swift +++ b/Tests/SwiftyJSONTests/RawTests.swift @@ -75,25 +75,21 @@ class RawTests: XCTestCase { func testString() { let json:JSON = "I'm a json" - print(json.rawString()) - XCTAssertTrue(json.rawString() == "I'm a json") + XCTAssertEqual(json.rawString(), "I'm a json") } func testNumber() { let json:JSON = 123456789.123 - print(json.rawString()) - XCTAssertTrue(json.rawString() == "123456789.123") + XCTAssertEqual(json.rawString(), "123456789.123") } func testBool() { let json:JSON = true - print(json.rawString()) - XCTAssertTrue(json.rawString() == "true") + XCTAssertEqual(json.rawString(), "true") } func testNull() { let json:JSON = JSON.null - print(json.rawString()) - XCTAssertTrue(json.rawString() == "null") + XCTAssertEqual(json.rawString(), "null") } } diff --git a/Tests/SwiftyJSONTests/StringTests.swift b/Tests/SwiftyJSONTests/StringTests.swift index 7fcd48c6..9ba2b1df 100644 --- a/Tests/SwiftyJSONTests/StringTests.swift +++ b/Tests/SwiftyJSONTests/StringTests.swift @@ -59,10 +59,12 @@ class StringTests: XCTestCase { func testURLPercentEscapes() { let emDash = "\\u2014" let urlString = "http://examble.com/unencoded" + emDash + "string" - let encodedURLString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) + guard let encodedURLString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else { + return XCTFail("Couldn't encode URL string \(urlString)") + } let json = JSON(urlString) - XCTAssertEqual(json.URL!, URL(string: encodedURLString!)!, "Wrong unpacked ") + XCTAssertEqual(json.URL!, URL(string: encodedURLString)!, "Wrong unpacked ") let preEscaped = JSON(encodedURLString) - XCTAssertEqual(preEscaped.URL!, URL(string: encodedURLString!)!, "Wrong unpacked ") + XCTAssertEqual(preEscaped.URL!, URL(string: encodedURLString)!, "Wrong unpacked ") } } From d5552cb78fa3182042f06b2792022d4b5e7cb861 Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Tue, 22 Nov 2016 10:31:22 +0100 Subject: [PATCH 316/470] Added label with: to merge and merged. --- Source/SwiftyJSON.swift | 8 ++++---- Tests/SwiftyJSONTests/MergeTests.swift | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3e533bb2..fe75812b 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -130,12 +130,12 @@ public struct JSON { - parameter other: The JSON which gets merged into this JSON */ - public mutating func merge(_ other: JSON) { + public mutating func merge(with other: JSON) { if self.type == other.type { switch self.type { case .dictionary: for (key, _) in other { - self[key].merge(other[key]) + self[key].merge(with: other[key]) } case .array: self = JSON(self.arrayValue + other.arrayValue) @@ -154,9 +154,9 @@ public struct JSON { - parameter other: The JSON which gets merged into this JSON - returns: New merged JSON */ - public func merged(other: JSON) -> JSON { + public func merged(with other: JSON) -> JSON { var merged = self - merged.merge(other) + merged.merge(with: other) return merged } diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift index 10564bf7..30aec15b 100644 --- a/Tests/SwiftyJSONTests/MergeTests.swift +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -28,42 +28,42 @@ class JSONTests: XCTestCase { func testPrimitiveType() { let A = JSON("a") let B = JSON("b") - XCTAssertEqual(A.merged(other: B), B) + XCTAssertEqual(A.merged(with: B), B) } func testMergeEqual() { let json = JSON(["a": "A"]) - XCTAssertEqual(json.merged(other: json), json) + XCTAssertEqual(json.merged(with: json), json) } func testMergeUnequalValues() { let A = JSON(["a": "A"]) let B = JSON(["a": "B"]) - XCTAssertEqual(A.merged(other: B), B) + XCTAssertEqual(A.merged(with: B), B) } func testMergeUnequalKeysAndValues() { let A = JSON(["a": "A"]) let B = JSON(["b": "B"]) - XCTAssertEqual(A.merged(other: B), JSON(["a": "A", "b": "B"])) + XCTAssertEqual(A.merged(with: B), JSON(["a": "A", "b": "B"])) } func testMergeFilledAndEmpty() { let A = JSON(["a": "A"]) let B = JSON([:]) - XCTAssertEqual(A.merged(other: B), A) + XCTAssertEqual(A.merged(with: B), A) } func testMergeEmptyAndFilled() { let A = JSON([:]) let B = JSON(["a": "A"]) - XCTAssertEqual(A.merged(other: B), B) + XCTAssertEqual(A.merged(with: B), B) } func testMergeArray() { let A = JSON(["a"]) let B = JSON(["b"]) - XCTAssertEqual(A.merged(other: B), JSON(["a", "b"])) + XCTAssertEqual(A.merged(with: B), JSON(["a", "b"])) } func testMergeNestedJSONs() { @@ -79,6 +79,6 @@ class JSONTests: XCTestCase { ] ]) - XCTAssertEqual(A.merged(other: B), B) + XCTAssertEqual(A.merged(with: B), B) } } From c28f3f537ae5d1a01bf618b4a8fe297e7d658875 Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Tue, 22 Nov 2016 10:51:32 +0100 Subject: [PATCH 317/470] Added documentation for merging two JSONs. --- README.md | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/README.md b/README.md index f1c1ab62..a7dac962 100644 --- a/README.md +++ b/README.md @@ -442,6 +442,54 @@ let auth: JSON = [ ] ``` +#### Merging + +It is possible to merge one JSON into another JSON. Merging a JSON into another JSON adds all non existing values to the original JSON which are only present in the `other` JSON. + +If both JSONs contain a value for the same key, _mostly_ this value gets overwritten in the original JSON, but there are two cases where it provides some special treatment: + +- In case of both values being a `JSON.Type.array` the values form the array found in the `other` JSON getting appended to the original JSON's array value. +- In case of both values being a `JSON.Type.dictionary` both JSON-values are getting merged the same way the encapsulating JSON is merged. + +In case, where two fields in a JSON have a different types, the value will get always overwritten. + +There are two different fashions for merging: `merge`modifies the original JSON, whereas `merged` works non-destructively on a copy. + +```swift +let original: JSON = [ + "first_name": "John", + "age": 20, + "skills": ["Coding", "Reading"], + "address": [ + "street": "Front St", + "zip": "12345", + ] +] + +let update: JSON = [ + "last_name": "Doe", + "age": 21, + "skills": ["Writing"], + "address": [ + "zip": "12342", + "city": "New York City" + ] +] + +let updated = original.merge(with: update) +// [ +// "first_name": "John", +// "last_name": "Doe", +// "age": 21, +// "skills": ["Coding", "Reading", "Writing"], +// "address": [ +// "street": "Front St", +// "zip": "12342", +// "city": "New York City" +// ] +// ] +``` + ## String representation There are two options available: - use the default Swift one From c4a4de08b0f9413466aa224755dcd52ba830cf18 Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Tue, 22 Nov 2016 11:00:07 +0100 Subject: [PATCH 318/470] Added pull request #725 to change log. --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b15b869..779cc304 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,9 @@ - Allow .number to parse number from string instead of just numberValue [\#219](https://github.com/SwiftyJSON/SwiftyJSON/pull/219) ([yonaskolb](https://github.com/yonaskolb)) -- Fixed spelling and grammar mistakes in README.md. Made some swift syntax... [\#214](https://github.com/SwiftyJSON/SwiftyJSON/pull/214) ([pRizz](https://github.com/pRizz)) +- Fixed spelling and grammar mistakes in README.md. Made some swift syntax... [\#214](https://github.com/SwiftyJSON/SwiftyJSON/pull/725) ([danielkiedrowski](https://github.com/danielkiedrowski)) + +- Added a function to deep merge a JSON object into another JSON object... [\#725](https://github.com/SwiftyJSON/SwiftyJSON/pull/219) ([yonaskolb](https://github.com/yonaskolb)) ## [2.2.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.2.0) (2015-04-13) From b35672498e5e5c6bcda8e088d9453eb6b7d289f7 Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Tue, 22 Nov 2016 11:04:12 +0100 Subject: [PATCH 319/470] Corrected commit #c4a4de0. Sorry. --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 779cc304..6a0935d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,9 +40,9 @@ - Allow .number to parse number from string instead of just numberValue [\#219](https://github.com/SwiftyJSON/SwiftyJSON/pull/219) ([yonaskolb](https://github.com/yonaskolb)) -- Fixed spelling and grammar mistakes in README.md. Made some swift syntax... [\#214](https://github.com/SwiftyJSON/SwiftyJSON/pull/725) ([danielkiedrowski](https://github.com/danielkiedrowski)) +- Fixed spelling and grammar mistakes in README.md. Made some swift syntax... [\#214](https://github.com/SwiftyJSON/SwiftyJSON/pull/214) ([pRizz](https://github.com/pRizz)) -- Added a function to deep merge a JSON object into another JSON object... [\#725](https://github.com/SwiftyJSON/SwiftyJSON/pull/219) ([yonaskolb](https://github.com/yonaskolb)) +- Added a function to deep merge a JSON object into another JSON object... [\#725](https://github.com/SwiftyJSON/SwiftyJSON/pull/725) ([danielkiedrowski](https://github.com/danielkiedrowski)) ## [2.2.0](https://github.com/SwiftyJSON/SwiftyJSON/tree/2.2.0) (2015-04-13) From 361356df1c66e4079425614a6d2d6d4f96845de2 Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Tue, 22 Nov 2016 11:35:20 +0100 Subject: [PATCH 320/470] Updated TOC of README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a7dac962..b103b826 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Setter](#setter) - [Raw object](#raw-object) - [Literal convertibles](#literal-convertibles) + - [Merging](#merging) 5. [Work with Alamofire](#work-with-alamofire) > For Legacy Swift support, take a look at the [swift2 branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift2) From ae338a61420df6fc06f7d85fe7c219d8ad243ae8 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 23 Nov 2016 23:21:53 +0800 Subject: [PATCH 321/470] Update scripts --- scripts/ci.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/ci.sh b/scripts/ci.sh index 98277210..6c0a3a2d 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -2,8 +2,8 @@ set -e -xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" test +travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty -xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" test +travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" build-for-testing test | xcpretty -xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" test \ No newline at end of file +travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" build-for-testing test | xcpretty From 493d6ba4ff6ccb3aa2bac06dad43b326b878da86 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Thu, 24 Nov 2016 00:42:23 +0800 Subject: [PATCH 322/470] Fix travis_retry command not found --- .travis.yml | 5 ++++- scripts/ci.sh | 9 --------- 2 files changed, 4 insertions(+), 10 deletions(-) delete mode 100755 scripts/ci.sh diff --git a/.travis.yml b/.travis.yml index c65386a0..63840195 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,7 +12,10 @@ before_deploy: - carthage build --no-skip-current - carthage archive $FRAMEWORK_NAME script: -- sh scripts/ci.sh +- set -o pipefail +- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty +- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" build-for-testing test | xcpretty +- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" build-for-testing test | xcpretty deploy: provider: releases api_key: diff --git a/scripts/ci.sh b/scripts/ci.sh deleted file mode 100755 index 6c0a3a2d..00000000 --- a/scripts/ci.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -set -e - -travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty - -travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" build-for-testing test | xcpretty - -travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" build-for-testing test | xcpretty From 950c01f2fb3f12ecffccbe4ce780889e9d352eda Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Fri, 2 Dec 2016 11:30:28 +0100 Subject: [PATCH 323/470] Added a security mechanism to prevent total overwriting of the source JSON in case that the JSON differ in type on the top level. --- Source/SwiftyJSON.swift | 40 ++++++++++++++++---------- Tests/SwiftyJSONTests/MergeTests.swift | 7 +++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 03dcc0f6..6719aa10 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -131,20 +131,7 @@ public struct JSON { - parameter other: The JSON which gets merged into this JSON */ public mutating func merge(with other: JSON) { - if self.type == other.type { - switch self.type { - case .dictionary: - for (key, _) in other { - self[key].merge(with: other[key]) - } - case .array: - self = JSON(self.arrayValue + other.arrayValue) - default: - self = other - } - } else { - self = other - } + self.merge(with: other, typecheck: true) } /** @@ -156,9 +143,32 @@ public struct JSON { */ public func merged(with other: JSON) -> JSON { var merged = self - merged.merge(with: other) + merged.merge(with: other, typecheck: true) return merged } + + // Private woker function which does the actual merging + // Typecheck is set to true for the first recursion level to prevent total override of the source JSON + private mutating func merge(with other: JSON, typecheck: Bool) { + if self.type == other.type { + switch self.type { + case .dictionary: + for (key, _) in other { + self[key].merge(with: other[key], typecheck: false) + } + case .array: + self = JSON(self.arrayValue + other.arrayValue) + default: + self = other + } + } else { + if typecheck { + print("Couldn't merge, because the JSONs differ in type on top level.") + } else { + self = other + } + } + } /// Private object fileprivate var rawArray: [Any] = [] diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift index 30aec15b..18d88a98 100644 --- a/Tests/SwiftyJSONTests/MergeTests.swift +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -25,6 +25,13 @@ import XCTest import SwiftyJSON class JSONTests: XCTestCase { + + func testDifferingTypes() { + let A = JSON("a") + let B = JSON(1) + XCTAssertEqual(A.merged(with: B), A) + } + func testPrimitiveType() { let A = JSON("a") let B = JSON("b") From bdcf170b142a3d117395590acbc09e7c7b36089b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20B=C3=B8geskov?= Date: Fri, 2 Dec 2016 12:46:22 +0100 Subject: [PATCH 324/470] Created new init instead of multiple small ones. --- Source/SwiftyJSON.swift | 66 +++++++++++++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f74e21b5..d8311361 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -64,14 +64,46 @@ public struct JSON { - returns: The created JSON */ - public init(data:Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer = nil) { + public init(data: Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer = nil) { do { let object: Any = try JSONSerialization.jsonObject(with: data, options: opt) - self.init(object) + self.init(jsonObject: object) } catch let aError as NSError { if error != nil { error?.pointee = aError } + self.init(jsonObject: NSNull()) + } + } + + /** + Creates a JSON object + - parameter object: the object + - note: this does not parse a `String` into JSON, instead use `init(parseJSON: String)` + - returns: the created JSON object + */ + public init(_ object: Any) { + switch object { + case let object as [JSON] where object.count > 0: + self.init(array: object) + case let object as [String: JSON] where object.count > 0: + self.init(dictionary: object) + case let object as Data: + self.init(data: object) + default: + self.init(jsonObject: object) + } + } + + /** + Parses the JSON string into a JSON object + - parameter json: the JSON string + - returns: the created JSON object + */ + public init(parseJSON json: String) { + if let data = json.data(using: .utf8) { + self.init(data) + } else { self.init(NSNull()) } } @@ -82,8 +114,9 @@ public struct JSON { - returns: The created JSON */ - public static func parse(_ string:String) -> JSON { - return string.data(using: String.Encoding.utf8) + @available(*, deprecated: 3.2, message: "Use instead `init(parseJSON: )`") + public static func parse(json: String) -> JSON { + return json.data(using: String.Encoding.utf8) .flatMap{ JSON(data: $0) } ?? JSON(NSNull()) } @@ -94,8 +127,8 @@ public struct JSON { - returns: The created JSON */ - public init(_ object: Any) { - self.object = object + private init(jsonObject: Any) { + self.object = jsonObject } /** @@ -105,8 +138,8 @@ public struct JSON { - returns: The created JSON */ - public init(_ jsonArray:[JSON]) { - self.init(jsonArray.map { $0.object }) + private init(array: [JSON]) { + self.init(array.map { $0.object }) } /** @@ -116,12 +149,13 @@ public struct JSON { - returns: The created JSON */ - public init(_ jsonDictionary:[String: JSON]) { - var dictionary = [String: Any](minimumCapacity: jsonDictionary.count) - for (key, json) in jsonDictionary { - dictionary[key] = json.object + private init(dictionary: [String: JSON]) { + var newDictionary = [String: Any](minimumCapacity: dictionary.count) + for (key, json) in dictionary { + newDictionary[key] = json.object } - self.init(dictionary) + + self.init(newDictionary) } /// Private object @@ -165,10 +199,10 @@ public struct JSON { _type = .number self.rawNumber = number } - case let string as String: + case let string as String: _type = .string self.rawString = string - case _ as NSNull: + case _ as NSNull: _type = .null case _ as [JSON]: _type = .array @@ -726,6 +760,8 @@ extension JSON { public var array: [JSON]? { get { if self.type == .array { + print(self.rawArray) + print(self.rawArray.map{ JSON($0) }) return self.rawArray.map{ JSON($0) } } else { return nil From f0f6ead40a1fb0e323da1d2b8765e1ffe1c79669 Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Sat, 3 Dec 2016 10:14:05 +0100 Subject: [PATCH 325/470] Use exceptions to communicate merging error to user, if he tries to merge JSONs differing in type on top level. --- Source/SwiftyJSON.swift | 16 ++++++++------- Tests/SwiftyJSONTests/MergeTests.swift | 28 +++++++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 6719aa10..f2840328 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -129,9 +129,10 @@ public struct JSON { present values getting overwritten, array values getting appended and nested JSONs getting merged the same way. - parameter other: The JSON which gets merged into this JSON + - throws `ErrorWrongType` if the other JSONs differs in type on the top level. */ - public mutating func merge(with other: JSON) { - self.merge(with: other, typecheck: true) + public mutating func merge(with other: JSON) throws { + try self.merge(with: other, typecheck: true) } /** @@ -140,21 +141,22 @@ public struct JSON { - parameter other: The JSON which gets merged into this JSON - returns: New merged JSON + - throws `ErrorWrongType` if the other JSONs differs in type on the top level. */ - public func merged(with other: JSON) -> JSON { + public func merged(with other: JSON) throws -> JSON { var merged = self - merged.merge(with: other, typecheck: true) + try merged.merge(with: other, typecheck: true) return merged } // Private woker function which does the actual merging // Typecheck is set to true for the first recursion level to prevent total override of the source JSON - private mutating func merge(with other: JSON, typecheck: Bool) { + private mutating func merge(with other: JSON, typecheck: Bool) throws { if self.type == other.type { switch self.type { case .dictionary: for (key, _) in other { - self[key].merge(with: other[key], typecheck: false) + try self[key].merge(with: other[key], typecheck: false) } case .array: self = JSON(self.arrayValue + other.arrayValue) @@ -163,7 +165,7 @@ public struct JSON { } } else { if typecheck { - print("Couldn't merge, because the JSONs differ in type on top level.") + throw NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Couldn't merge, because the JSONs differ in type on top level."]) } else { self = other } diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift index 18d88a98..ddc4a24f 100644 --- a/Tests/SwiftyJSONTests/MergeTests.swift +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -29,48 +29,58 @@ class JSONTests: XCTestCase { func testDifferingTypes() { let A = JSON("a") let B = JSON(1) - XCTAssertEqual(A.merged(with: B), A) + + do { + _ = try A.merged(with: B) + XCTFail() + } catch (let error) { + let error = error as NSError + XCTAssertEqual(error.code, ErrorWrongType) + XCTAssertEqual(error.domain, ErrorDomain) + XCTAssertEqual(error.userInfo[NSLocalizedDescriptionKey] as! String, + "Couldn't merge, because the JSONs differ in type on top level.") + } } func testPrimitiveType() { let A = JSON("a") let B = JSON("b") - XCTAssertEqual(A.merged(with: B), B) + XCTAssertEqual(try! A.merged(with: B), B) } func testMergeEqual() { let json = JSON(["a": "A"]) - XCTAssertEqual(json.merged(with: json), json) + XCTAssertEqual(try! json.merged(with: json), json) } func testMergeUnequalValues() { let A = JSON(["a": "A"]) let B = JSON(["a": "B"]) - XCTAssertEqual(A.merged(with: B), B) + XCTAssertEqual(try! A.merged(with: B), B) } func testMergeUnequalKeysAndValues() { let A = JSON(["a": "A"]) let B = JSON(["b": "B"]) - XCTAssertEqual(A.merged(with: B), JSON(["a": "A", "b": "B"])) + XCTAssertEqual(try! A.merged(with: B), JSON(["a": "A", "b": "B"])) } func testMergeFilledAndEmpty() { let A = JSON(["a": "A"]) let B = JSON([:]) - XCTAssertEqual(A.merged(with: B), A) + XCTAssertEqual(try! A.merged(with: B), A) } func testMergeEmptyAndFilled() { let A = JSON([:]) let B = JSON(["a": "A"]) - XCTAssertEqual(A.merged(with: B), B) + XCTAssertEqual(try! A.merged(with: B), B) } func testMergeArray() { let A = JSON(["a"]) let B = JSON(["b"]) - XCTAssertEqual(A.merged(with: B), JSON(["a", "b"])) + XCTAssertEqual(try! A.merged(with: B), JSON(["a", "b"])) } func testMergeNestedJSONs() { @@ -86,6 +96,6 @@ class JSONTests: XCTestCase { ] ]) - XCTAssertEqual(A.merged(with: B), B) + XCTAssertEqual(try! A.merged(with: B), B) } } From d2b4ae9ab4ba70bb37cd3e78639815075ac302ec Mon Sep 17 00:00:00 2001 From: Daniel Kiedrowski Date: Sat, 3 Dec 2016 10:21:55 +0100 Subject: [PATCH 326/470] Removed erroneous spaces and added spaces instead of tabs. --- README.md | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 736e0ee2..e6888341 100644 --- a/README.md +++ b/README.md @@ -452,43 +452,43 @@ If both JSONs contain a value for the same key, _mostly_ this value gets overwri - In case of both values being a `JSON.Type.array` the values form the array found in the `other` JSON getting appended to the original JSON's array value. - In case of both values being a `JSON.Type.dictionary` both JSON-values are getting merged the same way the encapsulating JSON is merged. -In case, where two fields in a JSON have a different types, the value will get always overwritten. +In case, where two fields in a JSON have a different types, the value will get always overwritten. -There are two different fashions for merging: `merge`modifies the original JSON, whereas `merged` works non-destructively on a copy. +There are two different fashions for merging: `merge` modifies the original JSON, whereas `merged` works non-destructively on a copy. ```swift let original: JSON = [ - "first_name": "John", - "age": 20, - "skills": ["Coding", "Reading"], - "address": [ - "street": "Front St", - "zip": "12345", - ] + "first_name": "John", + "age": 20, + "skills": ["Coding", "Reading"], + "address": [ + "street": "Front St", + "zip": "12345", + ] ] let update: JSON = [ - "last_name": "Doe", - "age": 21, - "skills": ["Writing"], - "address": [ - "zip": "12342", - "city": "New York City" - ] + "last_name": "Doe", + "age": 21, + "skills": ["Writing"], + "address": [ + "zip": "12342", + "city": "New York City" + ] ] let updated = original.merge(with: update) // [ -// "first_name": "John", -// "last_name": "Doe", -// "age": 21, -// "skills": ["Coding", "Reading", "Writing"], -// "address": [ -// "street": "Front St", -// "zip": "12342", -// "city": "New York City" -// ] -// ] +// "first_name": "John", +// "last_name": "Doe", +// "age": 21, +// "skills": ["Coding", "Reading", "Writing"], +// "address": [ +// "street": "Front St", +// "zip": "12342", +// "city": "New York City" +// ] +// ] ``` ## String representation From 007d544ebd0bc429acc3b65680b291107ea0c684 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20B=C3=B8geskov?= Date: Mon, 5 Dec 2016 08:33:54 +0100 Subject: [PATCH 327/470] Removed print statements --- Source/SwiftyJSON.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index d8311361..9bf6cbf5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -760,8 +760,6 @@ extension JSON { public var array: [JSON]? { get { if self.type == .array { - print(self.rawArray) - print(self.rawArray.map{ JSON($0) }) return self.rawArray.map{ JSON($0) } } else { return nil From ec2a1c7847e6da0165a1223754a73678c075257d Mon Sep 17 00:00:00 2001 From: looseyi <13615033587@126.com> Date: Thu, 8 Dec 2016 15:46:45 +0800 Subject: [PATCH 328/470] replace JSONRawIndex and JSONIndex with generics and desclear by typealise --- Source/SwiftyJSON.swift | 55 +++++++---------------------------------- 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f2840328..ea8491b9 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -213,7 +213,7 @@ public struct JSON { _type = .number self.rawNumber = number } - case let string as String: + case let string as String: _type = .string self.rawString = string case _ as NSNull: @@ -247,16 +247,14 @@ public struct JSON { public static var null: JSON { get { return JSON(NSNull()) } } } -public enum JSONIndex:Comparable +public enum Index: Comparable { case array(Int) - case dictionary(DictionaryIndex) + case dictionary(DictionaryIndex) case null - static public func ==(lhs: JSONIndex, rhs: JSONIndex) -> Bool - { - switch (lhs, rhs) - { + static public func ==(lhs: Index, rhs: Index) -> Bool { + switch (lhs, rhs) { case (.array(let left), .array(let right)): return left == right case (.dictionary(let left), .dictionary(let right)): @@ -267,10 +265,8 @@ public enum JSONIndex:Comparable } } - static public func <(lhs: JSONIndex, rhs: JSONIndex) -> Bool - { - switch (lhs, rhs) - { + static public func <(lhs: Index, rhs: Index) -> Bool { + switch (lhs, rhs) { case (.array(let left), .array(let right)): return left < right case (.dictionary(let left), .dictionary(let right)): @@ -279,44 +275,11 @@ public enum JSONIndex:Comparable return false } } - } -public enum JSONRawIndex: Comparable -{ - case array(Int) - case dictionary(DictionaryIndex) - case null +public typealias JSONIndex = Index +public typealias JSONRawIndex = Index - static public func ==(lhs: JSONRawIndex, rhs: JSONRawIndex) -> Bool - { - switch (lhs, rhs) - { - case (.array(let left), .array(let right)): - return left == right - case (.dictionary(let left), .dictionary(let right)): - return left == right - case (.null, .null): return true - default: - return false - } - } - - static public func <(lhs: JSONRawIndex, rhs: JSONRawIndex) -> Bool - { - switch (lhs, rhs) - { - case (.array(let left), .array(let right)): - return left < right - case (.dictionary(let left), .dictionary(let right)): - return left < right - default: - return false - } - } - - -} extension JSON: Collection { From fa439d70acd2df5c1c057ce5f519614ea8e88b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mads=20B=C3=B8geskov?= Date: Sat, 10 Dec 2016 09:27:45 +0100 Subject: [PATCH 329/470] Updated constructor to be more precise. --- Source/SwiftyJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 9bf6cbf5..bb6e66b1 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -100,8 +100,8 @@ public struct JSON { - parameter json: the JSON string - returns: the created JSON object */ - public init(parseJSON json: String) { - if let data = json.data(using: .utf8) { + public init(parseJSON jsonString: String) { + if let data = jsonString.data(using: .utf8) { self.init(data) } else { self.init(NSNull()) From 7afc077db6cd7dad2e81388bc8c3b6e959f90c50 Mon Sep 17 00:00:00 2001 From: Yoshitaka Seki Date: Sun, 11 Dec 2016 20:29:10 +0900 Subject: [PATCH 330/470] Turn JSON.URL into lower-cased JSON.url --- Source/SwiftyJSON.swift | 2 +- Tests/SwiftyJSONTests/BaseTests.swift | 4 ++-- Tests/SwiftyJSONTests/StringTests.swift | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f70e4f82..1e60cfb0 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1010,7 +1010,7 @@ extension JSON { extension JSON { //Optional URL - public var URL: URL? { + public var url: URL? { get { switch self.type { case .string: diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 0ec670ed..47eb56f8 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -120,13 +120,13 @@ class BaseTests: XCTestCase { let user = json[0]["user"] let user_name = user["name"].string - let user_profile_image_url = user["profile_image_url"].URL + let user_profile_image_url = user["profile_image_url"].url XCTAssert(user_name == "OAuth Dancer") XCTAssert(user_profile_image_url == URL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) let user_dictionary = json[0]["user"].dictionary let user_dictionary_name = user_dictionary?["name"]?.string - let user_dictionary_name_profile_image_url = user_dictionary?["profile_image_url"]?.URL + let user_dictionary_name_profile_image_url = user_dictionary?["profile_image_url"]?.url XCTAssert(user_dictionary_name == "OAuth Dancer") XCTAssert(user_dictionary_name_profile_image_url == URL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) } diff --git a/Tests/SwiftyJSONTests/StringTests.swift b/Tests/SwiftyJSONTests/StringTests.swift index 9ba2b1df..d9d5508e 100644 --- a/Tests/SwiftyJSONTests/StringTests.swift +++ b/Tests/SwiftyJSONTests/StringTests.swift @@ -36,9 +36,9 @@ class StringTests: XCTestCase { XCTAssertEqual(json.stringValue, "12345?67890.@#") } - func testURL() { + func testUrl() { let json = JSON("http://github.com") - XCTAssertEqual(json.URL!, URL(string:"http://github.com")!) + XCTAssertEqual(json.url!, URL(string:"http://github.com")!) } func testBool() { @@ -56,15 +56,15 @@ class StringTests: XCTestCase { XCTAssertTrue(json.boolValue) } - func testURLPercentEscapes() { + func testUrlPercentEscapes() { let emDash = "\\u2014" let urlString = "http://examble.com/unencoded" + emDash + "string" guard let encodedURLString = urlString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) else { return XCTFail("Couldn't encode URL string \(urlString)") } let json = JSON(urlString) - XCTAssertEqual(json.URL!, URL(string: encodedURLString)!, "Wrong unpacked ") + XCTAssertEqual(json.url!, URL(string: encodedURLString)!, "Wrong unpacked ") let preEscaped = JSON(encodedURLString) - XCTAssertEqual(preEscaped.URL!, URL(string: encodedURLString)!, "Wrong unpacked ") + XCTAssertEqual(preEscaped.url!, URL(string: encodedURLString)!, "Wrong unpacked ") } } From b311c581af557425db1cebfba2654c3b8b79ceea Mon Sep 17 00:00:00 2001 From: Jeff Kang Date: Fri, 16 Dec 2016 14:12:03 +0900 Subject: [PATCH 331/470] Add a title of NavigationBar with type --- Example/Example/ViewController.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index db1d1da1..3a35287c 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -29,6 +29,10 @@ class ViewController: UITableViewController { // MARK: - Table view data source + override func viewDidLoad() { + self.title = "SwiftyJSON(\(json.type))" + } + override func numberOfSections(in tableView: UITableView) -> Int { return 1 } From b295b6219cfbf8aac954c4471897ae8bb5754ba4 Mon Sep 17 00:00:00 2001 From: Naeem Shaikh Date: Fri, 16 Dec 2016 12:20:29 +0530 Subject: [PATCH 332/470] Update Work with Alamofire --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e6888341..b14c762e 100644 --- a/README.md +++ b/README.md @@ -507,7 +507,7 @@ let representation = json.rawString(options: [.castNilToNSNull: true]) SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: ```swift -Alamofire.request(.GET, url).validate().responseJSON { response in +Alamofire.request(url, method: .get).validate().responseJSON { response in switch response.result { case .success(let value): let json = JSON(value) From 2c48d85304e0409e99a9ab584d3903dd2a6086ed Mon Sep 17 00:00:00 2001 From: Laurin Brandner Date: Wed, 21 Dec 2016 17:52:47 +0100 Subject: [PATCH 333/470] Convert to latest swift version --- Source/SwiftyJSON.swift | 14 +++++++------- SwiftyJSON.xcodeproj/project.pbxproj | 6 ++++-- Tests/SwiftyJSONTests/PrintableTests.swift | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 1e60cfb0..f74ab534 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -115,7 +115,7 @@ public struct JSON { - returns: The created JSON */ @available(*, deprecated: 3.2, message: "Use instead `init(parseJSON: )`") - public static func parse(json: String) -> JSON { + public static func parse(_ json: String) -> JSON { return json.data(using: String.Encoding.utf8) .flatMap{ JSON(data: $0) } ?? JSON(NSNull()) } @@ -127,7 +127,7 @@ public struct JSON { - returns: The created JSON */ - private init(jsonObject: Any) { + fileprivate init(jsonObject: Any) { self.object = jsonObject } @@ -138,7 +138,7 @@ public struct JSON { - returns: The created JSON */ - private init(array: [JSON]) { + fileprivate init(array: [JSON]) { self.init(array.map { $0.object }) } @@ -149,7 +149,7 @@ public struct JSON { - returns: The created JSON */ - private init(dictionary: [String: JSON]) { + fileprivate init(dictionary: [String: JSON]) { var newDictionary = [String: Any](minimumCapacity: dictionary.count) for (key, json) in dictionary { newDictionary[key] = json.object @@ -185,7 +185,7 @@ public struct JSON { // Private woker function which does the actual merging // Typecheck is set to true for the first recursion level to prevent total override of the source JSON - private mutating func merge(with other: JSON, typecheck: Bool) throws { + fileprivate mutating func merge(with other: JSON, typecheck: Bool) throws { if self.type == other.type { switch self.type { case .dictionary: @@ -647,7 +647,7 @@ extension JSON: Swift.RawRepresentable { } } - public func rawString(options: [writtingOptionsKeys: Any]) -> String? { + public func rawString(_ options: [writtingOptionsKeys: Any]) -> String? { let encoding = options[.encoding] as? String.Encoding ?? String.Encoding.utf8 let maxObjectDepth = options[.maxObjextDepth] as? Int ?? 10 do { @@ -658,7 +658,7 @@ extension JSON: Swift.RawRepresentable { } } - private func _rawString( + fileprivate func _rawString( _ encoding: String.Encoding = .utf8, options: [writtingOptionsKeys: Any], maxObjectDepth: Int = 10 diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index c4e6df5e..53df83b1 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -437,12 +437,12 @@ TargetAttributes = { 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0820; ProvisioningStyle = Automatic; }; 2E4FEFE519575BE100351305 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0820; ProvisioningStyle = Manual; TestTargetID = 2E4FEFDA19575BE100351305; }; @@ -819,6 +819,7 @@ METAL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -833,6 +834,7 @@ METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index d8361685..bcdeaaae 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -76,7 +76,7 @@ class PrintableTests: XCTestCase { func testArrayWithOptionals() { let array = [1,2,"4",5,"6",nil] as [Any?] let json = JSON(array) - guard var description = json.rawString(options: [.castNilToNSNull: true]) else { + guard var description = json.rawString([.castNilToNSNull: true]) else { XCTFail("could not represent array") return } @@ -110,7 +110,7 @@ class PrintableTests: XCTestCase { func testDictionaryWithOptionals() { let dict = ["1":2, "2":"two", "3": nil] as [String: Any?] let json = JSON(dict) - guard var description = json.rawString(options: [.castNilToNSNull: true]) else { + guard var description = json.rawString([.castNilToNSNull: true]) else { XCTFail("could not represent dictionary") return } From ad28952c6e370d6674be1e3e35149c9850b2d6d5 Mon Sep 17 00:00:00 2001 From: Laurin Brandner Date: Wed, 21 Dec 2016 17:53:18 +0100 Subject: [PATCH 334/470] Update to recommended proj settings --- SwiftyJSON.xcodeproj/project.pbxproj | 18 +++++++++--------- .../xcschemes/SwiftyJSON OSX.xcscheme | 2 +- .../xcschemes/SwiftyJSON iOS.xcscheme | 2 +- .../xcschemes/SwiftyJSON tvOS.xcscheme | 2 +- .../xcschemes/SwiftyJSON watchOS.xcscheme | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 53df83b1..985b9fc5 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -433,7 +433,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0820; TargetAttributes = { 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; @@ -765,7 +765,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -787,7 +787,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -843,7 +843,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -867,7 +867,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=appletvos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -890,7 +890,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; - CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -918,7 +918,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; - CODE_SIGN_IDENTITY = "Mac Developer"; + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; @@ -1015,7 +1015,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1040,7 +1040,7 @@ APPLICATION_EXTENSION_API_ONLY = YES; BITCODE_GENERATION_MODE = bitcode; CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=watchos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme index 6d7a6f62..33f6b13c 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -1,6 +1,6 @@ Date: Wed, 21 Dec 2016 17:58:45 +0100 Subject: [PATCH 335/470] Convert every target --- Example/Example.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 717e1606..b114ac1e 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -129,7 +129,7 @@ TargetAttributes = { A82A1C1819D926B8009A653D = { CreatedOnToolsVersion = 6.0.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 0820; ProvisioningStyle = Manual; }; }; From db78d800097d90b9e90274a04344d5f6551d83a7 Mon Sep 17 00:00:00 2001 From: kscheff Date: Thu, 22 Dec 2016 13:34:15 +0100 Subject: [PATCH 336/470] Update README.md The example seems to be wrongly assing the dictionary to the name data instead of dict. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b14c762e..6256c843 100644 --- a/README.md +++ b/README.md @@ -496,7 +496,7 @@ There are two options available: - use the default Swift one - use a custom one that will handle optionals well and represent `nil` as `"null"`: ```swift -let data = ["1":2, "2":"two", "3": nil] as [String: Any?] +let dict = ["1":2, "2":"two", "3": nil] as [String: Any?] let json = JSON(dict) let representation = json.rawString(options: [.castNilToNSNull: true]) // representation is "{\"1\":2,\"2\":\"two\",\"3\":null}", which represents {"1":2,"2":"two","3":null} From 29a064b923b1199625b22334c4bc5f030bc85c25 Mon Sep 17 00:00:00 2001 From: "Robert M. Ryan" Date: Sun, 1 Jan 2017 21:33:57 -0800 Subject: [PATCH 337/470] Fix init(data:) error handling: The problem is that when users call `let json = JSON(data: data)`, they are not informed of the error, relying on the presence of `NSNull` value. That sort of use of non-standard sentinel value is discouraged. And the reliance of the `NSErrorPointer` is a pattern that pre-dates Swift 2 (and was intended for interacting with Objective-C API, not to be adopted within a Swift API itself). Bottom line, the error handling in `init(data:options:error:)` was distinctly unswifty. This attempts to remedy that. 1. Change init(data:options:) to throw errors, removing the `NSErrorPointer` reference. 2. Changed existing code that called `init(data:)` to reflect this error throwing behavior. 3. Also changed default reading options to be `[]` rather than `.allowFragments`, so that it's more consistent with standard `JSONSerialization` behavior. Also, I want to stop the perpetuation of the use of `.allowFragments` as a matter of standard practice, because generally if you have a fragment of JSON, you really want to know about that error. 4. Added test to demonstrate the catching of thrown error. --- Example/Playground.playground/Contents.swift | 6 ++-- Source/SwiftyJSON.swift | 23 ++++++------ Tests/SwiftyJSONTests/BaseTests.swift | 35 +++++++++++++++---- Tests/SwiftyJSONTests/PerformanceTests.swift | 26 +++++++++++--- Tests/SwiftyJSONTests/SequenceTypeTests.swift | 5 ++- 5 files changed, 67 insertions(+), 28 deletions(-) diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index 90b99433..87aebe68 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -31,7 +31,7 @@ let jsonString = String(data: jsonData!, encoding: .utf8) */ import SwiftyJSON -let json1 = JSON(data: jsonData!) +let json1 = try? JSON(data: jsonData!) /*: or */ @@ -40,7 +40,7 @@ let json2 = JSON(jsonObject) or */ let dataFromString = jsonString?.data(using: .utf8) -let json3 = JSON(data: dataFromString!) +let json3 = try? JSON(data: dataFromString!) /*: ### Subscript @@ -95,4 +95,4 @@ name = jsonArray[keys].string name = jsonArray["users"][1]["info"]["name"].string //Alternatively -name = jsonArray["users",1,"info","name"].string \ No newline at end of file +name = jsonArray["users",1,"info","name"].string diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f74ab534..966098f3 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -59,21 +59,14 @@ public struct JSON { Creates a JSON using the data. - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - - parameter opt: The JSON serialization reading options. `.AllowFragments` by default. + - parameter opt: The JSON serialization reading options. `[]` by default. - parameter error: The NSErrorPointer used to return the error. `nil` by default. - returns: The created JSON */ - public init(data: Data, options opt: JSONSerialization.ReadingOptions = .allowFragments, error: NSErrorPointer = nil) { - do { - let object: Any = try JSONSerialization.jsonObject(with: data, options: opt) - self.init(jsonObject: object) - } catch let aError as NSError { - if error != nil { - error?.pointee = aError - } - self.init(jsonObject: NSNull()) - } + public init(data: Data, options opt: JSONSerialization.ReadingOptions = []) throws { + let object: Any = try JSONSerialization.jsonObject(with: data, options: opt) + self.init(jsonObject: object) } /** @@ -89,7 +82,11 @@ public struct JSON { case let object as [String: JSON] where object.count > 0: self.init(dictionary: object) case let object as Data: - self.init(data: object) + do { + try self.init(data: object) + } catch { + self.init(jsonObject: NSNull()) + } default: self.init(jsonObject: object) } @@ -117,7 +114,7 @@ public struct JSON { @available(*, deprecated: 3.2, message: "Use instead `init(parseJSON: )`") public static func parse(_ json: String) -> JSON { return json.data(using: String.Encoding.utf8) - .flatMap{ JSON(data: $0) } ?? JSON(NSNull()) + .flatMap{ try? JSON(data: $0) } ?? JSON(NSNull()) } /** diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 47eb56f8..60ed2f9f 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -43,7 +43,10 @@ class BaseTests: XCTestCase { } func testInit() { - let json0 = JSON(data:self.testData) + guard let json0 = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } XCTAssertEqual(json0.array!.count, 3) XCTAssertEqual(JSON("123").description, "123") XCTAssertEqual(JSON(["1":"2"])["1"].string!, "2") @@ -76,7 +79,10 @@ class BaseTests: XCTestCase { } func testJSONDoesProduceValidWithCorrectKeyPath() { - let json = JSON(data:self.testData) + guard let json = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } let tweets = json let tweets_array = json.array @@ -225,7 +231,10 @@ class BaseTests: XCTestCase { } func testErrorHandle() { - let json = JSON(data:self.testData) + guard let json = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } if let _ = json["wrong-type"].string { XCTFail("Should not run into here") } else { @@ -245,11 +254,14 @@ class BaseTests: XCTestCase { } func testReturnObject() { - let json = JSON(data:self.testData) + guard let json = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } XCTAssertNotNil(json.object) } - func testNumberCompare(){ + func testNumberCompare() { XCTAssertEqual(NSNumber(value: 888332), NSNumber(value:888332)) XCTAssertNotEqual(NSNumber(value: 888332.1), NSNumber(value:888332)) XCTAssertLessThan(NSNumber(value: 888332).doubleValue, NSNumber(value:888332.1).doubleValue) @@ -260,5 +272,16 @@ class BaseTests: XCTestCase { XCTAssertEqual(NSNumber(value: true), NSNumber(value:true)) } - + func testErrorThrowing() { + let invalidJson = "{\"foo\": 300]" // deliberately incorrect JSON + let invalidData = invalidJson.data(using: .utf8)! + + do { + let _ = try JSON(data: invalidData) + XCTFail("Should have thrown error; we should not have gotten here") + } catch { + // everything is OK + } + } + } diff --git a/Tests/SwiftyJSONTests/PerformanceTests.swift b/Tests/SwiftyJSONTests/PerformanceTests.swift index 80b3c028..4907cc65 100644 --- a/Tests/SwiftyJSONTests/PerformanceTests.swift +++ b/Tests/SwiftyJSONTests/PerformanceTests.swift @@ -45,14 +45,20 @@ class PerformanceTests: XCTestCase { func testInitPerformance() { self.measure() { for _ in 1...100 { - let json = JSON(data:self.testData) + guard let json = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } XCTAssertTrue(json != JSON.null) } } } func testObjectMethodPerformance() { - let json = JSON(data:self.testData) + guard let json = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } self.measure() { for _ in 1...100 { let object:Any? = json.object @@ -62,7 +68,10 @@ class PerformanceTests: XCTestCase { } func testArrayMethodPerformance() { - let json = JSON(data:self.testData) + guard let json = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } self.measure() { for _ in 1...100 { autoreleasepool{ @@ -75,7 +84,11 @@ class PerformanceTests: XCTestCase { } func testDictionaryMethodPerformance() { - let json = JSON(data:testData)[0] + guard let json = try? JSON(data: self.testData)[0] else { + XCTFail("Unable to parse testData") + return + } + self.measure() { for _ in 1...100 { autoreleasepool{ @@ -88,7 +101,10 @@ class PerformanceTests: XCTestCase { } func testRawStringMethodPerformance() { - let json = JSON(data:testData) + guard let json = try? JSON(data: self.testData) else { + XCTFail("Unable to parse testData") + return + } self.measure() { for _ in 1...100 { autoreleasepool{ diff --git a/Tests/SwiftyJSONTests/SequenceTypeTests.swift b/Tests/SwiftyJSONTests/SequenceTypeTests.swift index 62bd7dcf..1cf8af3f 100644 --- a/Tests/SwiftyJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftyJSONTests/SequenceTypeTests.swift @@ -29,7 +29,10 @@ class SequenceTypeTests: XCTestCase { func testJSONFile() { if let file = Bundle(for:BaseTests.self).path(forResource: "Tests", ofType: "json") { let testData = try? Data(contentsOf: URL(fileURLWithPath: file)) - let json = JSON(data:testData!) + guard let json = try? JSON(data: testData!) else { + XCTFail("Unable to parse the data") + return + } for (index, sub) in json { switch (index as NSString).integerValue { case 0: From 94d7f0593a031811cfef7c803b335aa51600fe7a Mon Sep 17 00:00:00 2001 From: skyline75489 Date: Tue, 3 Jan 2017 09:34:20 +0800 Subject: [PATCH 338/470] Hello 2017 --- Source/SwiftyJSON.h | 2 +- Source/SwiftyJSON.swift | 2 +- Tests/SwiftyJSONTests/ArrayTests.swift | 2 +- Tests/SwiftyJSONTests/BaseTests.swift | 2 +- Tests/SwiftyJSONTests/ComparableTests.swift | 2 +- Tests/SwiftyJSONTests/DictionaryTests.swift | 2 +- Tests/SwiftyJSONTests/LiteralConvertibleTests.swift | 2 +- Tests/SwiftyJSONTests/NumberTests.swift | 2 +- Tests/SwiftyJSONTests/PerformanceTests.swift | 2 +- Tests/SwiftyJSONTests/PrintableTests.swift | 2 +- Tests/SwiftyJSONTests/RawRepresentableTests.swift | 2 +- Tests/SwiftyJSONTests/RawTests.swift | 2 +- Tests/SwiftyJSONTests/SequenceTypeTests.swift | 2 +- Tests/SwiftyJSONTests/StringTests.swift | 2 +- Tests/SwiftyJSONTests/SubscriptTests.swift | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Source/SwiftyJSON.h b/Source/SwiftyJSON.h index ac942218..d69a7643 100644 --- a/Source/SwiftyJSON.h +++ b/Source/SwiftyJSON.h @@ -1,6 +1,6 @@ // SwiftyJSON.h // -// Copyright (c) 2014 - 2016 Ruoyu Fu, Pinglin Tang +// Copyright (c) 2014 - 2017 Ruoyu Fu, Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f74ab534..e79c10d1 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1,6 +1,6 @@ // SwiftyJSON.swift // -// Copyright (c) 2014 - 2016 Ruoyu Fu, Pinglin Tang +// Copyright (c) 2014 - 2017 Ruoyu Fu, Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/ArrayTests.swift b/Tests/SwiftyJSONTests/ArrayTests.swift index e2d471a6..c3c53de3 100644 --- a/Tests/SwiftyJSONTests/ArrayTests.swift +++ b/Tests/SwiftyJSONTests/ArrayTests.swift @@ -1,6 +1,6 @@ // ArrayTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 47eb56f8..0c0ff8e5 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -1,6 +1,6 @@ // BaseTests.swift // -// Copyright (c) 2014 - 2016 Ruoyu Fu, Pinglin Tang +// Copyright (c) 2014 - 2017 Ruoyu Fu, Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/ComparableTests.swift b/Tests/SwiftyJSONTests/ComparableTests.swift index c027b07a..f238012f 100644 --- a/Tests/SwiftyJSONTests/ComparableTests.swift +++ b/Tests/SwiftyJSONTests/ComparableTests.swift @@ -1,6 +1,6 @@ // ComparableTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/DictionaryTests.swift b/Tests/SwiftyJSONTests/DictionaryTests.swift index 13208ded..5f9c822f 100644 --- a/Tests/SwiftyJSONTests/DictionaryTests.swift +++ b/Tests/SwiftyJSONTests/DictionaryTests.swift @@ -1,6 +1,6 @@ // DictionaryTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift index c55f2516..fa88e231 100644 --- a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift +++ b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift @@ -1,6 +1,6 @@ // LiteralConvertibleTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index 828bae68..0ae66b54 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -1,6 +1,6 @@ // NumberTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/PerformanceTests.swift b/Tests/SwiftyJSONTests/PerformanceTests.swift index 80b3c028..e3ed9760 100644 --- a/Tests/SwiftyJSONTests/PerformanceTests.swift +++ b/Tests/SwiftyJSONTests/PerformanceTests.swift @@ -1,6 +1,6 @@ // PerformanceTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index bcdeaaae..f60fc8c1 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -1,6 +1,6 @@ // PrintableTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/RawRepresentableTests.swift b/Tests/SwiftyJSONTests/RawRepresentableTests.swift index 342cd782..9ebf9b2e 100644 --- a/Tests/SwiftyJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftyJSONTests/RawRepresentableTests.swift @@ -1,6 +1,6 @@ // RawRepresentableTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift index d45f1cec..7693d8e3 100644 --- a/Tests/SwiftyJSONTests/RawTests.swift +++ b/Tests/SwiftyJSONTests/RawTests.swift @@ -1,6 +1,6 @@ // RawTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/SequenceTypeTests.swift b/Tests/SwiftyJSONTests/SequenceTypeTests.swift index 62bd7dcf..8f164c4c 100644 --- a/Tests/SwiftyJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftyJSONTests/SequenceTypeTests.swift @@ -1,7 +1,7 @@ // // SequenceTypeTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/StringTests.swift b/Tests/SwiftyJSONTests/StringTests.swift index d9d5508e..8d8e6ebc 100644 --- a/Tests/SwiftyJSONTests/StringTests.swift +++ b/Tests/SwiftyJSONTests/StringTests.swift @@ -1,6 +1,6 @@ // StringTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/Tests/SwiftyJSONTests/SubscriptTests.swift b/Tests/SwiftyJSONTests/SubscriptTests.swift index e9acc8c1..2a5cd97e 100644 --- a/Tests/SwiftyJSONTests/SubscriptTests.swift +++ b/Tests/SwiftyJSONTests/SubscriptTests.swift @@ -1,6 +1,6 @@ // SubscriptTests.swift // -// Copyright (c) 2014 - 2016 Pinglin Tang +// Copyright (c) 2014 - 2017 Pinglin Tang // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal From dadbfcffd5f51e2b488a26e83f188d96755e5393 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 10 Jan 2017 17:35:24 +0800 Subject: [PATCH 339/470] Bump version to 3.1.4 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 111a6976..2d822e31 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "3.1.3" + s.version = "3.1.4" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From a76d81d3c8ac68e52ada6c74fd6eca2b6082f757 Mon Sep 17 00:00:00 2001 From: Craig Grummitt Date: Tue, 10 Jan 2017 13:42:36 -0500 Subject: [PATCH 340/470] Fixed Spelling mistake - writing has one 't' --- Source/SwiftyJSON.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index e79c10d1..14a1e60c 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -647,7 +647,7 @@ extension JSON: Swift.RawRepresentable { } } - public func rawString(_ options: [writtingOptionsKeys: Any]) -> String? { + public func rawString(_ options: [writingOptionsKeys: Any]) -> String? { let encoding = options[.encoding] as? String.Encoding ?? String.Encoding.utf8 let maxObjectDepth = options[.maxObjextDepth] as? Int ?? 10 do { @@ -660,7 +660,7 @@ extension JSON: Swift.RawRepresentable { fileprivate func _rawString( _ encoding: String.Encoding = .utf8, - options: [writtingOptionsKeys: Any], + options: [writingOptionsKeys: Any], maxObjectDepth: Int = 10 ) throws -> String? { if (maxObjectDepth < 0) { @@ -1477,7 +1477,7 @@ func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -public enum writtingOptionsKeys { +public enum writingOptionsKeys { case jsonSerialization case castNilToNSNull case maxObjextDepth From 1c5e9025062dd521fe6cb30ae9f20828ad08ece7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E5=B8=85?= Date: Sat, 4 Feb 2017 16:03:12 +0800 Subject: [PATCH 341/470] fix nested JSON problems with JSON initialize method --- Source/SwiftyJSON.swift | 132 +++++++----------------- SwiftyJSON.xcodeproj/project.pbxproj | 4 + Tests/SwiftyJSONTests/NestedTests.swift | 53 ++++++++++ 3 files changed, 93 insertions(+), 96 deletions(-) create mode 100644 Tests/SwiftyJSONTests/NestedTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 14a1e60c..72aeb717 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -84,10 +84,6 @@ public struct JSON { */ public init(_ object: Any) { switch object { - case let object as [JSON] where object.count > 0: - self.init(array: object) - case let object as [String: JSON] where object.count > 0: - self.init(dictionary: object) case let object as Data: self.init(data: object) default: @@ -130,33 +126,6 @@ public struct JSON { fileprivate init(jsonObject: Any) { self.object = jsonObject } - - /** - Creates a JSON from a [JSON] - - - parameter jsonArray: A Swift array of JSON objects - - - returns: The created JSON - */ - fileprivate init(array: [JSON]) { - self.init(array.map { $0.object }) - } - - /** - Creates a JSON from a [String: JSON] - - - parameter jsonDictionary: A Swift dictionary of JSON objects - - - returns: The created JSON - */ - fileprivate init(dictionary: [String: JSON]) { - var newDictionary = [String: Any](minimumCapacity: dictionary.count) - for (key, json) in dictionary { - newDictionary[key] = json.object - } - - self.init(newDictionary) - } /** Merges another JSON into this JSON, whereas primitive values which are not present in this JSON are getting added, @@ -238,7 +207,7 @@ public struct JSON { } set { _error = nil - switch newValue { + switch unwrap(newValue) { case let number as NSNumber: if number.isBool { _type = .bool @@ -252,10 +221,8 @@ public struct JSON { self.rawString = string case _ as NSNull: _type = .null - case _ as [JSON]: - _type = .array - case nil: - _type = .null + case nil: + _type = .null case let array as [Any]: _type = .array self.rawArray = array @@ -281,8 +248,25 @@ public struct JSON { public static var null: JSON { get { return JSON(NSNull()) } } } -public enum Index: Comparable -{ +// unwrap nested JSON +private func unwrap(_ object: Any) -> Any { + switch object { + case let json as JSON: + return unwrap(json.object) + case let array as [Any]: + return array.map(unwrap) + case let dictionary as [String : Any]: + var unwrapedDic = dictionary + for (k, v) in dictionary { + unwrapedDic[k] = unwrap(v) + } + return unwrapedDic + default: + return object + } +} + +public enum Index: Comparable { case array(Int) case dictionary(DictionaryIndex) case null @@ -314,16 +298,12 @@ public enum Index: Comparable public typealias JSONIndex = Index public typealias JSONRawIndex = Index - -extension JSON: Collection -{ +extension JSON: Swift.Collection { public typealias Index = JSONRawIndex - public var startIndex: Index - { - switch type - { + public var startIndex: Index { + switch type { case .array: return .array(rawArray.startIndex) case .dictionary: @@ -333,10 +313,8 @@ extension JSON: Collection } } - public var endIndex: Index - { - switch type - { + public var endIndex: Index { + switch type { case .array: return .array(rawArray.endIndex) case .dictionary: @@ -346,10 +324,8 @@ extension JSON: Collection } } - public func index(after i: Index) -> Index - { - switch i - { + public func index(after i: Index) -> Index { + switch i { case .array(let idx): return .array(rawArray.index(after: idx)) case .dictionary(let idx): @@ -357,13 +333,10 @@ extension JSON: Collection default: return .null } - } - public subscript (position: Index) -> (String, JSON) - { - switch position - { + public subscript (position: Index) -> (String, JSON) { + switch position { case .array(let idx): return (String(idx), JSON(self.rawArray[idx])) case .dictionary(let idx): @@ -373,8 +346,6 @@ extension JSON: Collection return ("", JSON.null) } } - - } // MARK: - Subscript @@ -382,8 +353,7 @@ extension JSON: Collection /** * To mark both String and Int can be used in subscript. */ -public enum JSONKey -{ +public enum JSONKey { case index(Int) case key(String) } @@ -561,41 +531,11 @@ extension JSON: Swift.ExpressibleByFloatLiteral { extension JSON: Swift.ExpressibleByDictionaryLiteral { public init(dictionaryLiteral elements: (String, Any)...) { - let array = elements - self.init(dictionaryLiteral: array) - } - - public init(dictionaryLiteral elements: [(String, Any)]) { - let jsonFromDictionaryLiteral: ([String : Any]) -> JSON = { dictionary in - let initializeElement = Array(dictionary.keys).flatMap { key -> (String, Any)? in - if let value = dictionary[key] { - return (key, value) - } - return nil - } - return JSON(dictionaryLiteral: initializeElement) - } - - var dict = [String : Any](minimumCapacity: elements.count) - - for element in elements { - let elementToSet: Any - if let json = element.1 as? JSON { - elementToSet = json.object - } else if let jsonArray = element.1 as? [JSON] { - elementToSet = JSON(jsonArray).object - } else if let dictionary = element.1 as? [String : Any] { - elementToSet = jsonFromDictionaryLiteral(dictionary).object - } else if let dictArray = element.1 as? [[String : Any]] { - let jsonArray = dictArray.map { jsonFromDictionaryLiteral($0) } - elementToSet = JSON(jsonArray).object - } else { - elementToSet = element.1 - } - dict[element.0] = elementToSet + var dictionary = [String : Any](minimumCapacity: elements.count) + for (k, v) in elements { + dictionary[k] = v } - - self.init(dict) + self.init(dictionary as Any) } } diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 985b9fc5..dd7a4035 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 170ECF711E45BFF500FD325C /* NestedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 170ECF701E45BFF500FD325C /* NestedTests.swift */; }; 1B587CC61DDE04770012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; 1B587CC71DDE04780012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; 1B587CC81DDE04790012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; @@ -94,6 +95,7 @@ /* Begin PBXFileReference section */ 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; + 170ECF701E45BFF500FD325C /* NestedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedTests.swift; sourceTree = ""; }; 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MergeTests.swift; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; @@ -246,6 +248,7 @@ A863BE2719EED46F0092A41F /* RawTests.swift */, A8B66C8B19E51D6500540692 /* DictionaryTests.swift */, A8B66C8D19E52F4200540692 /* ArrayTests.swift */, + 170ECF701E45BFF500FD325C /* NestedTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); name = SwiftyJSONTests; @@ -563,6 +566,7 @@ A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A863BE2819EED46F0092A41F /* RawTests.swift in Sources */, + 170ECF711E45BFF500FD325C /* NestedTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */, diff --git a/Tests/SwiftyJSONTests/NestedTests.swift b/Tests/SwiftyJSONTests/NestedTests.swift new file mode 100644 index 00000000..0de5448c --- /dev/null +++ b/Tests/SwiftyJSONTests/NestedTests.swift @@ -0,0 +1,53 @@ +// +// NestedTests.swift +// SwiftyJSON +// +// Created by 丁帅 on 2017/2/4. +// +// + +import XCTest +import SwiftyJSON + +class NestedTests: XCTestCase { + + func testArrayJSON() { + let arr: [JSON] = ["a", 1, ["b", 2]] + let json = JSON(arr) + XCTAssertEqual(json[0].string, "a") + XCTAssertEqual(json[2,1].int, 2) + } + + func testDictionaryJSON() { + let json: JSON = ["a": JSON("1"), "b": JSON([1, 2, "3"]), "c": JSON(["aa": "11", "bb": 22])] + XCTAssertEqual(json["a"].string, "1") + XCTAssertEqual(json["b"].array!, [1, 2, "3"]) + XCTAssertEqual(json["c"]["aa"].string, "11") + + print(json["b"].arrayObject!) + } + + func testNextedJSON() { + let inner = JSON.init([ + "some_field": "1" + "2", + ]) + + let json = JSON.init([ + "outer_field": "1" + "2", + "inner_json": inner + ]) + + XCTAssertEqual(json["inner_json"], ["some_field": "12"]) + + let foo = "foo" + + let json2 = JSON.init([ + "outer_field": foo, + "inner_json": inner + ]) + + XCTAssertEqual(json2["inner_json"], ["some_field": "12"]) + + } + +} From 19d5cd3809d73f8f932b6699fc84f8755063045c Mon Sep 17 00:00:00 2001 From: Humoud Date: Sun, 12 Feb 2017 14:41:04 +0300 Subject: [PATCH 342/470] add Work with Moya section to README.MD --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 6256c843..6c462346 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Literal convertibles](#literal-convertibles) - [Merging](#merging) 5. [Work with Alamofire](#work-with-alamofire) +6. [Work with Moya](#work-with-moya) > For Legacy Swift support, take a look at the [swift2 branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift2) @@ -517,3 +518,23 @@ Alamofire.request(url, method: .get).validate().responseJSON { response in } } ``` + + +## Work with Moya + +SwiftyJSON parse data to JSON: + +```swift +let provider = MoyaProvider() +provider.request(.showProducts) { result in + switch result { + case let .success(moyaResponse): + let data = moyaResponse.data + let json = JSON(data: data) // convert network data to json + print(json) + case let .failure(error): + print("error: \(error)") + } +} + +``` From fcd1c6796777349662ead65bda2507354387514d Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Mon, 13 Feb 2017 22:25:45 +0800 Subject: [PATCH 343/470] [Optimization] Update LLVM and Swift compiler level --- SwiftyJSON.xcodeproj/project.pbxproj | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 985b9fc5..183662cd 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -771,6 +771,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = "Source/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -778,6 +779,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; }; name = Debug; @@ -793,6 +795,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Source/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -809,6 +812,7 @@ buildSettings = { CODE_SIGN_IDENTITY = ""; DEVELOPMENT_TEAM = ""; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -819,6 +823,7 @@ METAL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 3.0; }; name = Debug; @@ -828,6 +833,7 @@ buildSettings = { CODE_SIGN_IDENTITY = ""; DEVELOPMENT_TEAM = ""; + GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -849,6 +855,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = "Source/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -857,6 +864,7 @@ PRODUCT_NAME = SwiftyJSON; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -873,6 +881,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Source/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; @@ -897,6 +906,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -911,6 +921,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; }; @@ -926,6 +937,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; + GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Source/Info-OSX.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; @@ -945,6 +957,7 @@ CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; FRAMEWORK_SEARCH_PATHS = ""; + GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -956,6 +969,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; name = Debug; }; @@ -966,6 +980,7 @@ COMBINE_HIDPI_IMAGES = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ""; + GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-OSX.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -982,12 +997,14 @@ CODE_SIGN_IDENTITY = ""; DEBUG_INFORMATION_FORMAT = dwarf; GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-tvOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -999,6 +1016,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-tvOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; @@ -1021,6 +1039,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = "Source/Info-OSX.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -1029,6 +1048,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1046,6 +1066,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; + GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Source/Info-OSX.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; From 78470aa6f0f72b3f202acee395f1e77e1dd29717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E5=B8=85?= Date: Thu, 16 Feb 2017 18:20:40 +0800 Subject: [PATCH 344/470] rawValue test --- Tests/SwiftyJSONTests/NestedTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/NestedTests.swift b/Tests/SwiftyJSONTests/NestedTests.swift index 0de5448c..6a136043 100644 --- a/Tests/SwiftyJSONTests/NestedTests.swift +++ b/Tests/SwiftyJSONTests/NestedTests.swift @@ -46,7 +46,7 @@ class NestedTests: XCTestCase { "inner_json": inner ]) - XCTAssertEqual(json2["inner_json"], ["some_field": "12"]) + XCTAssertEqual(json2["inner_json"].rawValue as! [String : String], ["some_field": "12"]) } From d91b9ecb28bf962290061e0a3e94c9231c28a09d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E5=B8=85?= Date: Fri, 17 Feb 2017 15:08:56 +0800 Subject: [PATCH 345/470] Fix a spelling mistake and merge duplicate test files --- Source/SwiftyJSON.swift | 6 +-- SwiftyJSON.xcodeproj/project.pbxproj | 4 -- Tests/SwiftyJSONTests/NestedJSONTests.swift | 32 +++++++++++++ Tests/SwiftyJSONTests/NestedTests.swift | 53 --------------------- 4 files changed, 35 insertions(+), 60 deletions(-) delete mode 100644 Tests/SwiftyJSONTests/NestedTests.swift diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 72aeb717..43931cce 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -256,11 +256,11 @@ private func unwrap(_ object: Any) -> Any { case let array as [Any]: return array.map(unwrap) case let dictionary as [String : Any]: - var unwrapedDic = dictionary + var unwrappedDic = dictionary for (k, v) in dictionary { - unwrapedDic[k] = unwrap(v) + unwrappedDic[k] = unwrap(v) } - return unwrapedDic + return unwrappedDic default: return object } diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index dd7a4035..985b9fc5 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 170ECF711E45BFF500FD325C /* NestedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 170ECF701E45BFF500FD325C /* NestedTests.swift */; }; 1B587CC61DDE04770012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; 1B587CC71DDE04780012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; 1B587CC81DDE04790012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; @@ -95,7 +94,6 @@ /* Begin PBXFileReference section */ 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; - 170ECF701E45BFF500FD325C /* NestedTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedTests.swift; sourceTree = ""; }; 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MergeTests.swift; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; @@ -248,7 +246,6 @@ A863BE2719EED46F0092A41F /* RawTests.swift */, A8B66C8B19E51D6500540692 /* DictionaryTests.swift */, A8B66C8D19E52F4200540692 /* ArrayTests.swift */, - 170ECF701E45BFF500FD325C /* NestedTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); name = SwiftyJSONTests; @@ -566,7 +563,6 @@ A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A863BE2819EED46F0092A41F /* RawTests.swift in Sources */, - 170ECF711E45BFF500FD325C /* NestedTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */, diff --git a/Tests/SwiftyJSONTests/NestedJSONTests.swift b/Tests/SwiftyJSONTests/NestedJSONTests.swift index 5c75def7..17305384 100644 --- a/Tests/SwiftyJSONTests/NestedJSONTests.swift +++ b/Tests/SwiftyJSONTests/NestedJSONTests.swift @@ -39,4 +39,36 @@ class NestedJSONTests: XCTestCase { ] XCTAssertNotNil(try? nestedFamily.rawData()) } + + func testArrayJSON() { + let arr: [JSON] = ["a", 1, ["b", 2]] + let json = JSON(arr) + XCTAssertEqual(json[0].string, "a") + XCTAssertEqual(json[2,1].int, 2) + } + + func testDictionaryJSON() { + let json: JSON = ["a": JSON("1"), "b": JSON([1, 2, "3"]), "c": JSON(["aa": "11", "bb": 22])] + XCTAssertEqual(json["a"].string, "1") + XCTAssertEqual(json["b"].array!, [1, 2, "3"]) + XCTAssertEqual(json["c"]["aa"].string, "11") + } + + func testNextedJSON() { + let inner = JSON.init([ + "some_field": "1" + "2", + ]) + let json = JSON.init([ + "outer_field": "1" + "2", + "inner_json": inner + ]) + XCTAssertEqual(json["inner_json"], ["some_field": "12"]) + + let foo = "foo" + let json2 = JSON.init([ + "outer_field": foo, + "inner_json": inner + ]) + XCTAssertEqual(json2["inner_json"].rawValue as! [String : String], ["some_field": "12"]) + } } diff --git a/Tests/SwiftyJSONTests/NestedTests.swift b/Tests/SwiftyJSONTests/NestedTests.swift deleted file mode 100644 index 6a136043..00000000 --- a/Tests/SwiftyJSONTests/NestedTests.swift +++ /dev/null @@ -1,53 +0,0 @@ -// -// NestedTests.swift -// SwiftyJSON -// -// Created by 丁帅 on 2017/2/4. -// -// - -import XCTest -import SwiftyJSON - -class NestedTests: XCTestCase { - - func testArrayJSON() { - let arr: [JSON] = ["a", 1, ["b", 2]] - let json = JSON(arr) - XCTAssertEqual(json[0].string, "a") - XCTAssertEqual(json[2,1].int, 2) - } - - func testDictionaryJSON() { - let json: JSON = ["a": JSON("1"), "b": JSON([1, 2, "3"]), "c": JSON(["aa": "11", "bb": 22])] - XCTAssertEqual(json["a"].string, "1") - XCTAssertEqual(json["b"].array!, [1, 2, "3"]) - XCTAssertEqual(json["c"]["aa"].string, "11") - - print(json["b"].arrayObject!) - } - - func testNextedJSON() { - let inner = JSON.init([ - "some_field": "1" + "2", - ]) - - let json = JSON.init([ - "outer_field": "1" + "2", - "inner_json": inner - ]) - - XCTAssertEqual(json["inner_json"], ["some_field": "12"]) - - let foo = "foo" - - let json2 = JSON.init([ - "outer_field": foo, - "inner_json": inner - ]) - - XCTAssertEqual(json2["inner_json"].rawValue as! [String : String], ["some_field": "12"]) - - } - -} From 9d96db2a1627709c90ed144dcf2e60dfdd73c762 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 17 Feb 2017 22:46:42 +0800 Subject: [PATCH 346/470] [SwiftLint] Add SwiftLint target --- SwiftyJSON.xcodeproj/project.pbxproj | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 183662cd..cf25aa14 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -6,6 +6,20 @@ objectVersion = 46; objects = { +/* Begin PBXAggregateTarget section */ + A81D162B1E5743B000C62C5F /* SwiftLint */ = { + isa = PBXAggregateTarget; + buildConfigurationList = A81D162E1E5743B000C62C5F /* Build configuration list for PBXAggregateTarget "SwiftLint" */; + buildPhases = ( + A81D162F1E5743CE00C62C5F /* ShellScript */, + ); + dependencies = ( + ); + name = SwiftLint; + productName = SwiftLint; + }; +/* End PBXAggregateTarget section */ + /* Begin PBXBuildFile section */ 1B587CC61DDE04770012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; 1B587CC71DDE04780012D8DB /* MergeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B587CC41DDE04360012D8DB /* MergeTests.swift */; }; @@ -456,6 +470,10 @@ 9C7DFC641A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; }; + A81D162B1E5743B000C62C5F = { + CreatedOnToolsVersion = 8.2.1; + ProvisioningStyle = Automatic; + }; A8580F731BCF5C5B00DA927B = { CreatedOnToolsVersion = 7.1; }; @@ -483,6 +501,7 @@ E4D7CCDE1B9465A700EE7221 /* SwiftyJSON watchOS */, 7236B4EC1BAC14150020529B /* SwiftyJSON tvOS */, A8580F731BCF5C5B00DA927B /* SwiftyJSON tvOS Tests */, + A81D162B1E5743B000C62C5F /* SwiftLint */, ); }; /* End PBXProject section */ @@ -542,6 +561,22 @@ }; /* End PBXResourcesBuildPhase section */ +/* Begin PBXShellScriptBuildPhase section */ + A81D162F1E5743CE00C62C5F /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; +/* End PBXShellScriptBuildPhase section */ + /* Begin PBXSourcesBuildPhase section */ 2E4FEFD619575BE100351305 /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -991,6 +1026,20 @@ }; name = Release; }; + A81D162C1E5743B000C62C5F /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + A81D162D1E5743B000C62C5F /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; A8580F7D1BCF5C5B00DA927B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -1137,6 +1186,14 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + A81D162E1E5743B000C62C5F /* Build configuration list for PBXAggregateTarget "SwiftLint" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + A81D162C1E5743B000C62C5F /* Debug */, + A81D162D1E5743B000C62C5F /* Release */, + ); + defaultConfigurationIsVisible = 0; + }; A8580F7C1BCF5C5B00DA927B /* Build configuration list for PBXNativeTarget "SwiftyJSON tvOS Tests" */ = { isa = XCConfigurationList; buildConfigurations = ( From 5acb5d76655f5bf81dd258b18662f72fcd3964d0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 17 Feb 2017 22:47:29 +0800 Subject: [PATCH 347/470] [SwiftLint] add .swiftlint.yml --- .swiftlint.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .swiftlint.yml diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 00000000..e69de29b From 395124dcf6f220980bc065f3b94402f2119c7fe0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 17 Feb 2017 22:55:59 +0800 Subject: [PATCH 348/470] [SwiftLint] Autocorrect code style --- .swiftlint.yml | 13 + Example/Example/AppDelegate.swift | 7 +- Example/Example/ViewController.swift | 10 +- Example/Playground.playground/Contents.swift | 4 +- Source/SwiftyJSON.swift | 92 +++--- Tests/SwiftyJSONTests/ArrayTests.swift | 6 +- Tests/SwiftyJSONTests/BaseTests.swift | 147 +++++----- Tests/SwiftyJSONTests/ComparableTests.swift | 273 +++++++++--------- Tests/SwiftyJSONTests/DictionaryTests.swift | 12 +- .../LiteralConvertibleTests.swift | 34 +-- Tests/SwiftyJSONTests/MergeTests.swift | 24 +- Tests/SwiftyJSONTests/NestedJSONTests.swift | 16 +- Tests/SwiftyJSONTests/NumberTests.swift | 85 +++--- Tests/SwiftyJSONTests/PerformanceTests.swift | 36 +-- Tests/SwiftyJSONTests/PrintableTests.swift | 32 +- .../RawRepresentableTests.swift | 38 +-- Tests/SwiftyJSONTests/RawTests.swift | 28 +- Tests/SwiftyJSONTests/SequenceTypeTests.swift | 34 +-- Tests/SwiftyJSONTests/StringTests.swift | 2 +- Tests/SwiftyJSONTests/SubscriptTests.swift | 164 +++++------ 20 files changed, 524 insertions(+), 533 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index e69de29b..1a5ad564 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -0,0 +1,13 @@ +disabled_rules: + - force_cast + - force_try + - variable_name + - type_name + - file_length + - line_length + - type_body_length + - implicit_getter + - operator_whitespace + - cyclomatic_complexity + - function_body_length + - control_statement diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 6c0aead8..f0e91456 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -29,10 +29,10 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - + let navigationController = self.window?.rootViewController as! UINavigationController let viewController = navigationController.topViewController as! ViewController - + if let file = Bundle.main.path(forResource: "SwiftyJSONTests", ofType: "json") { do { let data = try Data(contentsOf: URL(fileURLWithPath: file)) @@ -44,8 +44,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } else { viewController.json = JSON.null } - + return true } } - diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index db1d1da1..b2145e7d 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -26,7 +26,7 @@ import SwiftyJSON class ViewController: UITableViewController { var json: JSON = JSON.null - + // MARK: - Table view data source override func numberOfSections(in tableView: UITableView) -> Int { @@ -44,9 +44,9 @@ class ViewController: UITableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "JSONCell", for: indexPath) as UITableViewCell - + let row = (indexPath as NSIndexPath).row - + switch self.json.type { case .array: cell.textLabel?.text = "\(row)" @@ -60,7 +60,7 @@ class ViewController: UITableViewController { cell.textLabel?.text = "" cell.detailTextLabel?.text = self.json.description } - + return cell } @@ -70,7 +70,7 @@ class ViewController: UITableViewController { var nextController: UIViewController? nextController = segue.destination - + if let indexPath = self.tableView.indexPathForSelectedRow { let row = (indexPath as NSIndexPath).row var nextJson: JSON = JSON.null diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index 90b99433..6c9f5361 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -85,7 +85,7 @@ jsonDictionary["country"].stringValue //Getting a string using a path to the element let path = ["users", 1, "info", "name"] as [JSONSubscriptType] -var name = jsonArray["users",1,"info","name"].string +var name = jsonArray["users", 1, "info", "name"].string //With a custom way let keys: [JSONSubscriptType] = ["users", 1, "info", "name"] @@ -95,4 +95,4 @@ name = jsonArray[keys].string name = jsonArray["users"][1]["info"]["name"].string //Alternatively -name = jsonArray["users",1,"info","name"].string \ No newline at end of file +name = jsonArray["users", 1, "info", "name"].string diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 14a1e60c..8cd2d86e 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -41,7 +41,7 @@ public let ErrorInvalidJSON: Int = 490 See http://www.json.org */ -public enum Type :Int{ +public enum Type: Int { case number case string @@ -117,7 +117,7 @@ public struct JSON { @available(*, deprecated: 3.2, message: "Use instead `init(parseJSON: )`") public static func parse(_ json: String) -> JSON { return json.data(using: String.Encoding.utf8) - .flatMap{ JSON(data: $0) } ?? JSON(NSNull()) + .flatMap { JSON(data: $0) } ?? JSON(NSNull()) } /** @@ -157,7 +157,7 @@ public struct JSON { self.init(newDictionary) } - + /** Merges another JSON into this JSON, whereas primitive values which are not present in this JSON are getting added, present values getting overwritten, array values getting appended and nested JSONs getting merged the same way. @@ -168,7 +168,7 @@ public struct JSON { public mutating func merge(with other: JSON) throws { try self.merge(with: other, typecheck: true) } - + /** Merges another JSON into this JSON and returns a new JSON, whereas primitive values which are not present in this JSON are getting added, present values getting overwritten, array values getting appended and nested JSONS getting merged the same way. @@ -182,7 +182,7 @@ public struct JSON { try merged.merge(with: other, typecheck: true) return merged } - + // Private woker function which does the actual merging // Typecheck is set to true for the first recursion level to prevent total override of the source JSON fileprivate mutating func merge(with other: JSON, typecheck: Bool) throws { @@ -216,7 +216,7 @@ public struct JSON { /// Private type fileprivate var _type: Type = .null /// prviate error - fileprivate var _error: NSError? = nil + fileprivate var _error: NSError? /// Object in JSON public var object: Any { @@ -281,8 +281,7 @@ public struct JSON { public static var null: JSON { get { return JSON(NSNull()) } } } -public enum Index: Comparable -{ +public enum Index: Comparable { case array(Int) case dictionary(DictionaryIndex) case null @@ -314,16 +313,12 @@ public enum Index: Comparable public typealias JSONIndex = Index public typealias JSONRawIndex = Index - -extension JSON: Collection -{ +extension JSON: Collection { public typealias Index = JSONRawIndex - public var startIndex: Index - { - switch type - { + public var startIndex: Index { + switch type { case .array: return .array(rawArray.startIndex) case .dictionary: @@ -333,10 +328,8 @@ extension JSON: Collection } } - public var endIndex: Index - { - switch type - { + public var endIndex: Index { + switch type { case .array: return .array(rawArray.endIndex) case .dictionary: @@ -346,10 +339,8 @@ extension JSON: Collection } } - public func index(after i: Index) -> Index - { - switch i - { + public func index(after i: Index) -> Index { + switch i { case .array(let idx): return .array(rawArray.index(after: idx)) case .dictionary(let idx): @@ -360,10 +351,8 @@ extension JSON: Collection } - public subscript (position: Index) -> (String, JSON) - { - switch position - { + public subscript (position: Index) -> (String, JSON) { + switch position { case .array(let idx): return (String(idx), JSON(self.rawArray[idx])) case .dictionary(let idx): @@ -374,7 +363,6 @@ extension JSON: Collection } } - } // MARK: - Subscript @@ -382,24 +370,23 @@ extension JSON: Collection /** * To mark both String and Int can be used in subscript. */ -public enum JSONKey -{ +public enum JSONKey { case index(Int) case key(String) } public protocol JSONSubscriptType { - var jsonKey:JSONKey { get } + var jsonKey: JSONKey { get } } extension Int: JSONSubscriptType { - public var jsonKey:JSONKey { + public var jsonKey: JSONKey { return JSONKey.index(self) } } extension String: JSONSubscriptType { - public var jsonKey:JSONKey { + public var jsonKey: JSONKey { return JSONKey.key(self) } } @@ -417,7 +404,7 @@ extension JSON { return JSON(self.rawArray[index]) } else { var r = JSON.null - r._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds , userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) + r._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) return r } } @@ -576,7 +563,7 @@ extension JSON: Swift.ExpressibleByDictionaryLiteral { return JSON(dictionaryLiteral: initializeElement) } - var dict = [String : Any](minimumCapacity: elements.count) + var dict = [String: Any](minimumCapacity: elements.count) for element in elements { let elementToSet: Any @@ -637,7 +624,7 @@ extension JSON: Swift.RawRepresentable { return try JSONSerialization.data(withJSONObject: self.object, options: opt) } - + public func rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? { do { return try _rawString(encoding, options: [.jsonSerialization: opt]) @@ -771,7 +758,7 @@ extension JSON { public var array: [JSON]? { get { if self.type == .array { - return self.rawArray.map{ JSON($0) } + return self.rawArray.map { JSON($0) } } else { return nil } @@ -812,7 +799,7 @@ extension JSON { //Optional [String : JSON] public var dictionary: [String : JSON]? { if self.type == .dictionary { - var d = [String : JSON](minimumCapacity: rawDictionary.count) + var d = [String: JSON](minimumCapacity: rawDictionary.count) for (key, value) in rawDictionary { d[key] = JSON(value) } @@ -880,7 +867,7 @@ extension JSON { // : Swift.Bool case .number: return self.rawNumber.boolValue case .string: - return ["true", "y", "t"].contains() { (truthyString) in + return ["true", "y", "t"].contains { (truthyString) in return self.rawString.caseInsensitiveCompare(truthyString) == .orderedSame } default: @@ -980,7 +967,7 @@ extension JSON { } } -//MARK: - Null +// MARK: - Null extension JSON { public var null: NSNull? { @@ -996,7 +983,7 @@ extension JSON { self.object = NSNull() } } - public func exists() -> Bool{ + public func exists() -> Bool { if let errorValue = error, errorValue.code == ErrorNotExist || errorValue.code == ErrorIndexOutOfBounds || errorValue.code == ErrorWrongType { @@ -1006,7 +993,7 @@ extension JSON { } } -//MARK: - URL +// MARK: - URL extension JSON { //Optional URL @@ -1081,19 +1068,14 @@ extension JSON { } } - public var int: Int? - { - get - { + public var int: Int? { + get { return self.number?.intValue } - set - { - if let newValue = newValue - { + set { + if let newValue = newValue { self.object = NSNumber(value: newValue) - } else - { + } else { self.object = NSNull() } } @@ -1307,7 +1289,7 @@ extension JSON { } } -//MARK: - Comparable +// MARK: - Comparable extension JSON : Swift.Comparable {} public func ==(lhs: JSON, rhs: JSON) -> Bool { @@ -1402,10 +1384,10 @@ private let falseObjCType = String(cString: falseNumber.objCType) // MARK: - NSNumber: Comparable extension NSNumber { - var isBool:Bool { + var isBool: Bool { get { let objCType = String(cString: self.objCType) - if (self.compare(trueNumber) == .orderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == .orderedSame && objCType == falseObjCType){ + if (self.compare(trueNumber) == .orderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == .orderedSame && objCType == falseObjCType) { return true } else { return false diff --git a/Tests/SwiftyJSONTests/ArrayTests.swift b/Tests/SwiftyJSONTests/ArrayTests.swift index c3c53de3..0c955e7d 100644 --- a/Tests/SwiftyJSONTests/ArrayTests.swift +++ b/Tests/SwiftyJSONTests/ArrayTests.swift @@ -26,7 +26,7 @@ import SwiftyJSON class ArrayTests: XCTestCase { func testSingleDimensionalArraysGetter() { - let array = ["1","2", "a", "B", "D"] + let array = ["1", "2", "a", "B", "D"] let json = JSON(array) XCTAssertEqual((json.array![0] as JSON).string!, "1") XCTAssertEqual((json.array![1] as JSON).string!, "2") @@ -34,9 +34,9 @@ class ArrayTests: XCTestCase { XCTAssertEqual((json.array![3] as JSON).string!, "B") XCTAssertEqual((json.array![4] as JSON).string!, "D") } - + func testSingleDimensionalArraysSetter() { - let array = ["1","2", "a", "B", "D"] + let array = ["1", "2", "a", "B", "D"] var json = JSON(array) json.arrayObject = ["111", "222"] XCTAssertEqual((json.array![0] as JSON).string!, "111") diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 0c0ff8e5..80bb9893 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -26,27 +26,27 @@ import XCTest class BaseTests: XCTestCase { var testData: Data! - + override func setUp() { - + super.setUp() - + if let file = Bundle(for:BaseTests.self).path(forResource: "Tests", ofType: "json") { self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { XCTFail("Can't find the test JSON file") } } - + override func tearDown() { super.tearDown() } - + func testInit() { let json0 = JSON(data:self.testData) XCTAssertEqual(json0.array!.count, 3) XCTAssertEqual(JSON("123").description, "123") - XCTAssertEqual(JSON(["1":"2"])["1"].string!, "2") + XCTAssertEqual(JSON(["1": "2"])["1"].string!, "2") let dictionary = NSMutableDictionary() dictionary.setObject(NSNumber(value: 1.0), forKey: "number" as NSString) dictionary.setObject(NSNull(), forKey: "null" as NSString) @@ -58,26 +58,26 @@ class BaseTests: XCTestCase { } catch _ { } } - + func testCompare() { XCTAssertNotEqual(JSON("32.1234567890"), JSON(32.1234567890)) - let veryLargeNumber:UInt64 = 9876543210987654321 - XCTAssertNotEqual(JSON("9876543210987654321"),JSON(NSNumber(value:veryLargeNumber))) + let veryLargeNumber: UInt64 = 9876543210987654321 + XCTAssertNotEqual(JSON("9876543210987654321"), JSON(NSNumber(value:veryLargeNumber))) XCTAssertNotEqual(JSON("9876543210987654321.12345678901234567890"), JSON(9876543210987654321.12345678901234567890)) XCTAssertEqual(JSON("😊"), JSON("😊")) XCTAssertNotEqual(JSON("😱"), JSON("😁")) - XCTAssertEqual(JSON([123,321,456]), JSON([123,321,456])) - XCTAssertNotEqual(JSON([123,321,456]), JSON(123456789)) - XCTAssertNotEqual(JSON([123,321,456]), JSON("string")) - XCTAssertNotEqual(JSON(["1":123,"2":321,"3":456]), JSON("string")) - XCTAssertEqual(JSON(["1":123,"2":321,"3":456]), JSON(["2":321,"1":123,"3":456])) - XCTAssertEqual(JSON(NSNull()),JSON(NSNull())) + XCTAssertEqual(JSON([123, 321, 456]), JSON([123, 321, 456])) + XCTAssertNotEqual(JSON([123, 321, 456]), JSON(123456789)) + XCTAssertNotEqual(JSON([123, 321, 456]), JSON("string")) + XCTAssertNotEqual(JSON(["1": 123, "2": 321, "3": 456]), JSON("string")) + XCTAssertEqual(JSON(["1": 123, "2": 321, "3": 456]), JSON(["2": 321, "1": 123, "3": 456])) + XCTAssertEqual(JSON(NSNull()), JSON(NSNull())) XCTAssertNotEqual(JSON(NSNull()), JSON(123)) } - + func testJSONDoesProduceValidWithCorrectKeyPath() { let json = JSON(data:self.testData) - + let tweets = json let tweets_array = json.array let tweets_1 = json[1] @@ -89,12 +89,12 @@ class BaseTests: XCTestCase { XCTAssertNotEqual(tweets_1.type, Type.null) XCTAssertEqual(tweets_1_user_name, JSON("Raffi Krikorian")) XCTAssertEqual(tweets_1_user_name_string!, "Raffi Krikorian") - + let tweets_1_coordinates = tweets_1["coordinates"] let tweets_1_coordinates_coordinates = tweets_1_coordinates["coordinates"] let tweets_1_coordinates_coordinates_point_0_double = tweets_1_coordinates_coordinates[0].double let tweets_1_coordinates_coordinates_point_1_float = tweets_1_coordinates_coordinates[1].float - let new_tweets_1_coordinates_coordinates = JSON([-122.25831,37.871609] as NSArray) + let new_tweets_1_coordinates_coordinates = JSON([-122.25831, 37.871609] as NSArray) XCTAssertEqual(tweets_1_coordinates_coordinates, new_tweets_1_coordinates_coordinates) XCTAssertEqual(tweets_1_coordinates_coordinates_point_0_double!, -122.25831) XCTAssertTrue(tweets_1_coordinates_coordinates_point_1_float! == 37.871609) @@ -106,16 +106,16 @@ class BaseTests: XCTestCase { let tweets_1_coordinates_coordinates_point_1 = tweets_1_coordinates_coordinates[1] XCTAssertEqual(tweets_1_coordinates_coordinates_point_0, JSON(-122.25831)) XCTAssertEqual(tweets_1_coordinates_coordinates_point_1, JSON(37.871609)) - + let created_at = json[0]["created_at"].string let id_str = json[0]["id_str"].string let favorited = json[0]["favorited"].bool let id = json[0]["id"].int64 let in_reply_to_user_id_str = json[0]["in_reply_to_user_id_str"] XCTAssertEqual(created_at!, "Tue Aug 28 21:16:23 +0000 2012") - XCTAssertEqual(id_str!,"240558470661799936") + XCTAssertEqual(id_str!, "240558470661799936") XCTAssertFalse(favorited!) - XCTAssertEqual(id!,240558470661799936) + XCTAssertEqual(id!, 240558470661799936) XCTAssertEqual(in_reply_to_user_id_str.type, Type.null) let user = json[0]["user"] @@ -130,7 +130,7 @@ class BaseTests: XCTestCase { XCTAssert(user_dictionary_name == "OAuth Dancer") XCTAssert(user_dictionary_name_profile_image_url == URL(string: "http://a0.twimg.com/profile_images/730275945/oauth-dancer_normal.jpg")) } - + func testJSONNumberCompare() { XCTAssertEqual(JSON(12376352.123321), JSON(12376352.123321)) XCTAssertGreaterThan(JSON(20.211), JSON(20.112)) @@ -139,7 +139,7 @@ class BaseTests: XCTestCase { XCTAssertLessThan(JSON(-82320.211), JSON(20.112)) XCTAssertLessThanOrEqual(JSON(-320.211), JSON(123.1)) XCTAssertLessThanOrEqual(JSON(-8763), JSON(-8763)) - + XCTAssertEqual(JSON(12376352.123321), JSON(12376352.123321)) XCTAssertGreaterThan(JSON(20.211), JSON(20.112)) XCTAssertGreaterThanOrEqual(JSON(30.211), JSON(20.112)) @@ -149,81 +149,81 @@ class BaseTests: XCTestCase { XCTAssertLessThanOrEqual(JSON(-8763), JSON(-8763)) } - func testNumberConvertToString(){ + func testNumberConvertToString() { XCTAssertEqual(JSON(true).stringValue, "true") XCTAssertEqual(JSON(999.9823).stringValue, "999.9823") XCTAssertEqual(JSON(true).number!.stringValue, "1") XCTAssertEqual(JSON(false).number!.stringValue, "0") XCTAssertEqual(JSON("hello").numberValue.stringValue, "0") XCTAssertEqual(JSON(NSNull()).numberValue.stringValue, "0") - XCTAssertEqual(JSON(["a","b","c","d"]).numberValue.stringValue, "0") - XCTAssertEqual(JSON(["a":"b","c":"d"]).numberValue.stringValue, "0") + XCTAssertEqual(JSON(["a", "b", "c", "d"]).numberValue.stringValue, "0") + XCTAssertEqual(JSON(["a": "b", "c": "d"]).numberValue.stringValue, "0") } - - func testNumberPrint(){ - XCTAssertEqual(JSON(false).description,"false") - XCTAssertEqual(JSON(true).description,"true") + func testNumberPrint() { - XCTAssertEqual(JSON(1).description,"1") - XCTAssertEqual(JSON(22).description,"22") + XCTAssertEqual(JSON(false).description, "false") + XCTAssertEqual(JSON(true).description, "true") + + XCTAssertEqual(JSON(1).description, "1") + XCTAssertEqual(JSON(22).description, "22") #if (arch(x86_64) || arch(arm64)) - XCTAssertEqual(JSON(9.22337203685478E18).description,"9.22337203685478e+18") + XCTAssertEqual(JSON(9.22337203685478E18).description, "9.22337203685478e+18") #elseif (arch(i386) || arch(arm)) - XCTAssertEqual(JSON(2147483647).description,"2147483647") + XCTAssertEqual(JSON(2147483647).description, "2147483647") #endif - XCTAssertEqual(JSON(-1).description,"-1") - XCTAssertEqual(JSON(-934834834).description,"-934834834") - XCTAssertEqual(JSON(-2147483648).description,"-2147483648") - - XCTAssertEqual(JSON(1.5555).description,"1.5555") - XCTAssertEqual(JSON(-9.123456789).description,"-9.123456789") - XCTAssertEqual(JSON(-0.00000000000000001).description,"-1e-17") - XCTAssertEqual(JSON(-999999999999999999999999.000000000000000000000001).description,"-1e+24") - XCTAssertEqual(JSON(-9999999991999999999999999.88888883433343439438493483483943948341).stringValue,"-9.999999991999999e+24") - - XCTAssertEqual(JSON(Int(Int.max)).description,"\(Int.max)") - XCTAssertEqual(JSON(NSNumber(value: Int.min)).description,"\(Int.min)") - XCTAssertEqual(JSON(NSNumber(value: UInt.max)).description,"\(UInt.max)") - XCTAssertEqual(JSON(NSNumber(value: UInt64.max)).description,"\(UInt64.max)") - XCTAssertEqual(JSON(NSNumber(value: Int64.max)).description,"\(Int64.max)") - XCTAssertEqual(JSON(NSNumber(value: UInt64.max)).description,"\(UInt64.max)") - - XCTAssertEqual(JSON(Double.infinity).description,"inf") - XCTAssertEqual(JSON(-Double.infinity).description,"-inf") - XCTAssertEqual(JSON(Double.nan).description,"nan") - - XCTAssertEqual(JSON(1.0/0.0).description,"inf") - XCTAssertEqual(JSON(-1.0/0.0).description,"-inf") - XCTAssertEqual(JSON(0.0/0.0).description,"nan") + XCTAssertEqual(JSON(-1).description, "-1") + XCTAssertEqual(JSON(-934834834).description, "-934834834") + XCTAssertEqual(JSON(-2147483648).description, "-2147483648") + + XCTAssertEqual(JSON(1.5555).description, "1.5555") + XCTAssertEqual(JSON(-9.123456789).description, "-9.123456789") + XCTAssertEqual(JSON(-0.00000000000000001).description, "-1e-17") + XCTAssertEqual(JSON(-999999999999999999999999.000000000000000000000001).description, "-1e+24") + XCTAssertEqual(JSON(-9999999991999999999999999.88888883433343439438493483483943948341).stringValue, "-9.999999991999999e+24") + + XCTAssertEqual(JSON(Int(Int.max)).description, "\(Int.max)") + XCTAssertEqual(JSON(NSNumber(value: Int.min)).description, "\(Int.min)") + XCTAssertEqual(JSON(NSNumber(value: UInt.max)).description, "\(UInt.max)") + XCTAssertEqual(JSON(NSNumber(value: UInt64.max)).description, "\(UInt64.max)") + XCTAssertEqual(JSON(NSNumber(value: Int64.max)).description, "\(Int64.max)") + XCTAssertEqual(JSON(NSNumber(value: UInt64.max)).description, "\(UInt64.max)") + + XCTAssertEqual(JSON(Double.infinity).description, "inf") + XCTAssertEqual(JSON(-Double.infinity).description, "-inf") + XCTAssertEqual(JSON(Double.nan).description, "nan") + + XCTAssertEqual(JSON(1.0/0.0).description, "inf") + XCTAssertEqual(JSON(-1.0/0.0).description, "-inf") + XCTAssertEqual(JSON(0.0/0.0).description, "nan") } - + func testNullJSON() { - XCTAssertEqual(JSON(NSNull()).debugDescription,"null") - - let json:JSON = JSON.null - XCTAssertEqual(json.debugDescription,"null") + XCTAssertEqual(JSON(NSNull()).debugDescription, "null") + + let json: JSON = JSON.null + XCTAssertEqual(json.debugDescription, "null") XCTAssertNil(json.error) - let json1:JSON = JSON(NSNull()) + let json1: JSON = JSON(NSNull()) if json1 != JSON.null { XCTFail("json1 should be nil") } } - + func testExistance() { - let dictionary = ["number":1111] + let dictionary = ["number": 1111] let json = JSON(dictionary) XCTAssertFalse(json["unspecifiedValue"].exists()) XCTAssertFalse(json[0].exists()) XCTAssertTrue(json["number"].exists()) - let array = [["number":1111]] + let array = [["number": 1111]] let jsonForArray = JSON(array) XCTAssertTrue(jsonForArray[0].exists()) XCTAssertFalse(jsonForArray[1].exists()) XCTAssertFalse(jsonForArray["someValue"].exists()) } - + func testErrorHandle() { let json = JSON(data:self.testData) if let _ = json["wrong-type"].string { @@ -237,19 +237,19 @@ class BaseTests: XCTestCase { } else { XCTAssertEqual(json[0]["not-exist"].error!.code, SwiftyJSON.ErrorNotExist) } - + let wrongJSON = JSON(NSObject()) if let error = wrongJSON.error { XCTAssertEqual(error.code, SwiftyJSON.ErrorUnsupportedType) } } - + func testReturnObject() { let json = JSON(data:self.testData) XCTAssertNotNil(json.object) } - - func testNumberCompare(){ + + func testNumberCompare() { XCTAssertEqual(NSNumber(value: 888332), NSNumber(value:888332)) XCTAssertNotEqual(NSNumber(value: 888332.1), NSNumber(value:888332)) XCTAssertLessThan(NSNumber(value: 888332).doubleValue, NSNumber(value:888332.1).doubleValue) @@ -259,6 +259,5 @@ class BaseTests: XCTestCase { XCTAssertEqual(NSNumber(value: false), NSNumber(value:false)) XCTAssertEqual(NSNumber(value: true), NSNumber(value:true)) } - } diff --git a/Tests/SwiftyJSONTests/ComparableTests.swift b/Tests/SwiftyJSONTests/ComparableTests.swift index f238012f..1f8343e9 100644 --- a/Tests/SwiftyJSONTests/ComparableTests.swift +++ b/Tests/SwiftyJSONTests/ComparableTests.swift @@ -26,279 +26,278 @@ import SwiftyJSON class ComparableTests: XCTestCase { func testNumberEqual() { - let jsonL1:JSON = 1234567890.876623 - let jsonR1:JSON = JSON(1234567890.876623) + let jsonL1: JSON = 1234567890.876623 + let jsonR1: JSON = JSON(1234567890.876623) XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 == 1234567890.876623) - let jsonL2:JSON = 987654321 - let jsonR2:JSON = JSON(987654321) + let jsonL2: JSON = 987654321 + let jsonR2: JSON = JSON(987654321) XCTAssertEqual(jsonL2, jsonR2) XCTAssertTrue(jsonR2 == 987654321) - - let jsonL3:JSON = JSON(NSNumber(value:87654321.12345678)) - let jsonR3:JSON = JSON(NSNumber(value:87654321.12345678)) + let jsonL3: JSON = JSON(NSNumber(value:87654321.12345678)) + let jsonR3: JSON = JSON(NSNumber(value:87654321.12345678)) XCTAssertEqual(jsonL3, jsonR3) XCTAssertTrue(jsonR3 == 87654321.12345678) } - + func testNumberNotEqual() { - let jsonL1:JSON = 1234567890.876623 - let jsonR1:JSON = JSON(123.123) + let jsonL1: JSON = 1234567890.876623 + let jsonR1: JSON = JSON(123.123) XCTAssertNotEqual(jsonL1, jsonR1) XCTAssertFalse(jsonL1 == 34343) - - let jsonL2:JSON = 8773 - let jsonR2:JSON = JSON(123.23) + + let jsonL2: JSON = 8773 + let jsonR2: JSON = JSON(123.23) XCTAssertNotEqual(jsonL2, jsonR2) XCTAssertFalse(jsonR1 == 454352) - - let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(value:87654321.45678)) + + let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value:87654321.45678)) XCTAssertNotEqual(jsonL3, jsonR3) XCTAssertFalse(jsonL3 == 4545.232) } - + func testNumberGreaterThanOrEqual() { - let jsonL1:JSON = 1234567890.876623 - let jsonR1:JSON = JSON(123.123) + let jsonL1: JSON = 1234567890.876623 + let jsonR1: JSON = JSON(123.123) XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 >= -37434) - - let jsonL2:JSON = 8773 - let jsonR2:JSON = JSON(-87343) + + let jsonL2: JSON = 8773 + let jsonR2: JSON = JSON(-87343) XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) XCTAssertTrue(jsonR2 >= -988343) - let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(value:87621.12345678)) + let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value:87621.12345678)) XCTAssertGreaterThanOrEqual(jsonL3, jsonR3) XCTAssertTrue(jsonR3 >= 0.3232) } - + func testNumberLessThanOrEqual() { - let jsonL1:JSON = 1234567890.876623 - let jsonR1:JSON = JSON(123.123) + let jsonL1: JSON = 1234567890.876623 + let jsonR1: JSON = JSON(123.123) XCTAssertLessThanOrEqual(jsonR1, jsonL1) XCTAssertFalse(83487343.3493 <= jsonR1) - - let jsonL2:JSON = 8773 - let jsonR2:JSON = JSON(-123.23) + + let jsonL2: JSON = 8773 + let jsonR2: JSON = JSON(-123.23) XCTAssertLessThanOrEqual(jsonR2, jsonL2) XCTAssertFalse(9348343 <= jsonR2) - - let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(value:87621.12345678)) + + let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value:87621.12345678)) XCTAssertLessThanOrEqual(jsonR3, jsonL3) XCTAssertTrue(87621.12345678 <= jsonR3) } func testNumberGreaterThan() { - let jsonL1:JSON = 1234567890.876623 - let jsonR1:JSON = JSON(123.123) + let jsonL1: JSON = 1234567890.876623 + let jsonR1: JSON = JSON(123.123) XCTAssertGreaterThan(jsonL1, jsonR1) XCTAssertFalse(jsonR1 > 192388843.0988) - let jsonL2:JSON = 8773 - let jsonR2:JSON = JSON(123.23) + let jsonL2: JSON = 8773 + let jsonR2: JSON = JSON(123.23) XCTAssertGreaterThan(jsonL2, jsonR2) XCTAssertFalse(jsonR2 > 877434) - let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(value:87621.1234567)) + let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value:87621.1234567)) XCTAssertGreaterThan(jsonL3, jsonR3) XCTAssertFalse(-7799 > jsonR3) } - + func testNumberLessThan() { - let jsonL1:JSON = 1234567890.876623 - let jsonR1:JSON = JSON(123.123) + let jsonL1: JSON = 1234567890.876623 + let jsonR1: JSON = JSON(123.123) XCTAssertLessThan(jsonR1, jsonL1) XCTAssertTrue(jsonR1 < 192388843.0988) - let jsonL2:JSON = 8773 - let jsonR2:JSON = JSON(123.23) + let jsonL2: JSON = 8773 + let jsonR2: JSON = JSON(123.23) XCTAssertLessThan(jsonR2, jsonL2) XCTAssertTrue(jsonR2 < 877434) - - let jsonL3:JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3:JSON = JSON(NSNumber(value:87621.1234567)) + + let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value:87621.1234567)) XCTAssertLessThan(jsonR3, jsonL3) XCTAssertTrue(-7799 < jsonR3) } func testBoolEqual() { - let jsonL1:JSON = true - let jsonR1:JSON = JSON(true) + let jsonL1: JSON = true + let jsonR1: JSON = JSON(true) XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 == true) - let jsonL2:JSON = false - let jsonR2:JSON = JSON(false) + let jsonL2: JSON = false + let jsonR2: JSON = JSON(false) XCTAssertEqual(jsonL2, jsonR2) XCTAssertTrue(jsonL2 == false) } - + func testBoolNotEqual() { - let jsonL1:JSON = true - let jsonR1:JSON = JSON(false) + let jsonL1: JSON = true + let jsonR1: JSON = JSON(false) XCTAssertNotEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 != false) - let jsonL2:JSON = false - let jsonR2:JSON = JSON(true) + let jsonL2: JSON = false + let jsonR2: JSON = JSON(true) XCTAssertNotEqual(jsonL2, jsonR2) XCTAssertTrue(jsonL2 != true) } - + func testBoolGreaterThanOrEqual() { - let jsonL1:JSON = true - let jsonR1:JSON = JSON(true) + let jsonL1: JSON = true + let jsonR1: JSON = JSON(true) XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 >= true) - - let jsonL2:JSON = false - let jsonR2:JSON = JSON(false) + + let jsonL2: JSON = false + let jsonR2: JSON = JSON(false) XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) XCTAssertFalse(jsonL2 >= true) } - + func testBoolLessThanOrEqual() { - let jsonL1:JSON = true - let jsonR1:JSON = JSON(true) + let jsonL1: JSON = true + let jsonR1: JSON = JSON(true) XCTAssertLessThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(true <= jsonR1) - - let jsonL2:JSON = false - let jsonR2:JSON = JSON(false) + + let jsonL2: JSON = false + let jsonR2: JSON = JSON(false) XCTAssertLessThanOrEqual(jsonL2, jsonR2) XCTAssertFalse(jsonL2 <= true) } - + func testBoolGreaterThan() { - let jsonL1:JSON = true - let jsonR1:JSON = JSON(true) + let jsonL1: JSON = true + let jsonR1: JSON = JSON(true) XCTAssertFalse(jsonL1 > jsonR1) XCTAssertFalse(jsonL1 > true) XCTAssertFalse(jsonR1 > false) - let jsonL2:JSON = false - let jsonR2:JSON = JSON(false) + let jsonL2: JSON = false + let jsonR2: JSON = JSON(false) XCTAssertFalse(jsonL2 > jsonR2) XCTAssertFalse(jsonL2 > false) XCTAssertFalse(jsonR2 > true) - let jsonL3:JSON = true - let jsonR3:JSON = JSON(false) + let jsonL3: JSON = true + let jsonR3: JSON = JSON(false) XCTAssertFalse(jsonL3 > jsonR3) XCTAssertFalse(jsonL3 > false) XCTAssertFalse(jsonR3 > true) - - let jsonL4:JSON = false - let jsonR4:JSON = JSON(true) + + let jsonL4: JSON = false + let jsonR4: JSON = JSON(true) XCTAssertFalse(jsonL4 > jsonR4) XCTAssertFalse(jsonL4 > false) XCTAssertFalse(jsonR4 > true) } - + func testBoolLessThan() { - let jsonL1:JSON = true - let jsonR1:JSON = JSON(true) + let jsonL1: JSON = true + let jsonR1: JSON = JSON(true) XCTAssertFalse(jsonL1 < jsonR1) XCTAssertFalse(jsonL1 < true) XCTAssertFalse(jsonR1 < false) - let jsonL2:JSON = false - let jsonR2:JSON = JSON(false) + let jsonL2: JSON = false + let jsonR2: JSON = JSON(false) XCTAssertFalse(jsonL2 < jsonR2) XCTAssertFalse(jsonL2 < false) XCTAssertFalse(jsonR2 < true) - - let jsonL3:JSON = true - let jsonR3:JSON = JSON(false) + + let jsonL3: JSON = true + let jsonR3: JSON = JSON(false) XCTAssertFalse(jsonL3 < jsonR3) XCTAssertFalse(jsonL3 < false) XCTAssertFalse(jsonR3 < true) - let jsonL4:JSON = false - let jsonR4:JSON = JSON(true) + let jsonL4: JSON = false + let jsonR4: JSON = JSON(true) XCTAssertFalse(jsonL4 < jsonR4) XCTAssertFalse(jsonL4 < false) XCTAssertFalse(true < jsonR4) } - + func testStringEqual() { - let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") + let jsonL1: JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1: JSON = JSON("abcdefg 123456789 !@#$%^&*()") XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 == "abcdefg 123456789 !@#$%^&*()") } - + func testStringNotEqual() { - let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - let jsonR1:JSON = JSON("-=[]\\\"987654321") - + let jsonL1: JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1: JSON = JSON("-=[]\\\"987654321") + XCTAssertNotEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 != "not equal") } - + func testStringGreaterThanOrEqual() { - let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") - + let jsonL1: JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1: JSON = JSON("abcdefg 123456789 !@#$%^&*()") + XCTAssertGreaterThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 >= "abcdefg 123456789 !@#$%^&*()") - let jsonL2:JSON = "z-+{}:" - let jsonR2:JSON = JSON("a<>?:") + let jsonL2: JSON = "z-+{}:" + let jsonR2: JSON = JSON("a<>?:") XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) XCTAssertTrue(jsonL2 >= "mnbvcxz") } - + func testStringLessThanOrEqual() { - let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") - + let jsonL1: JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1: JSON = JSON("abcdefg 123456789 !@#$%^&*()") + XCTAssertLessThanOrEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 <= "abcdefg 123456789 !@#$%^&*()") - - let jsonL2:JSON = "z-+{}:" - let jsonR2:JSON = JSON("a<>?:") + + let jsonL2: JSON = "z-+{}:" + let jsonR2: JSON = JSON("a<>?:") XCTAssertLessThanOrEqual(jsonR2, jsonL2) XCTAssertTrue("mnbvcxz" <= jsonL2) } - + func testStringGreaterThan() { - let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") - + let jsonL1: JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1: JSON = JSON("abcdefg 123456789 !@#$%^&*()") + XCTAssertFalse(jsonL1 > jsonR1) XCTAssertFalse(jsonL1 > "abcdefg 123456789 !@#$%^&*()") - - let jsonL2:JSON = "z-+{}:" - let jsonR2:JSON = JSON("a<>?:") + + let jsonL2: JSON = "z-+{}:" + let jsonR2: JSON = JSON("a<>?:") XCTAssertGreaterThan(jsonL2, jsonR2) XCTAssertFalse("87663434" > jsonL2) } func testStringLessThan() { - let jsonL1:JSON = "abcdefg 123456789 !@#$%^&*()" - let jsonR1:JSON = JSON("abcdefg 123456789 !@#$%^&*()") - + let jsonL1: JSON = "abcdefg 123456789 !@#$%^&*()" + let jsonR1: JSON = JSON("abcdefg 123456789 !@#$%^&*()") + XCTAssertFalse(jsonL1 < jsonR1) XCTAssertFalse(jsonL1 < "abcdefg 123456789 !@#$%^&*()") - - let jsonL2:JSON = "98774" - let jsonR2:JSON = JSON("123456") + + let jsonL2: JSON = "98774" + let jsonR2: JSON = JSON("123456") XCTAssertLessThan(jsonR2, jsonL2) XCTAssertFalse(jsonL2 < "09") } func testNil() { - let jsonL1:JSON = JSON.null - let jsonR1:JSON = JSON(NSNull()) + let jsonL1: JSON = JSON.null + let jsonR1: JSON = JSON(NSNull()) XCTAssertEqual(jsonL1, jsonR1) XCTAssertTrue(jsonL1 != "123") XCTAssertFalse(jsonL1 > "abcd") @@ -308,31 +307,31 @@ class ComparableTests: XCTestCase { XCTAssertTrue(jsonL1 >= jsonR1) XCTAssertTrue(jsonL1 <= jsonR1) } - + func testArray() { - let jsonL1:JSON = [1,2,"4",5,"6"] - let jsonR1:JSON = JSON([1,2,"4",5,"6"]) + let jsonL1: JSON = [1, 2, "4", 5, "6"] + let jsonR1: JSON = JSON([1, 2, "4", 5, "6"]) XCTAssertEqual(jsonL1, jsonR1) - XCTAssertTrue(jsonL1 == [1,2,"4",5,"6"]) - XCTAssertTrue(jsonL1 != ["abcd","efg"]) + XCTAssertTrue(jsonL1 == [1, 2, "4", 5, "6"]) + XCTAssertTrue(jsonL1 != ["abcd", "efg"]) XCTAssertTrue(jsonL1 >= jsonR1) XCTAssertTrue(jsonL1 <= jsonR1) - XCTAssertFalse(jsonL1 > ["abcd",""]) + XCTAssertFalse(jsonL1 > ["abcd", ""]) XCTAssertFalse(jsonR1 < []) XCTAssertFalse(jsonL1 >= [:]) } - + func testDictionary() { - let jsonL1:JSON = ["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]] - let jsonR1:JSON = JSON(["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]]) - + let jsonL1: JSON = ["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]] + let jsonR1: JSON = JSON(["2": 2, "name": "Jack", "List": ["a", 1.09, NSNull()]]) + XCTAssertEqual(jsonL1, jsonR1) - XCTAssertTrue(jsonL1 != ["1":2,"Hello":"World","Koo":"Foo"]) + XCTAssertTrue(jsonL1 != ["1": 2, "Hello": "World", "Koo": "Foo"]) XCTAssertTrue(jsonL1 >= jsonR1) XCTAssertTrue(jsonL1 <= jsonR1) XCTAssertFalse(jsonL1 >= [:]) - XCTAssertFalse(jsonR1 <= ["999":"aaaa"]) - XCTAssertFalse(jsonL1 > [")(*&^":1234567]) - XCTAssertFalse(jsonR1 < ["MNHH":"JUYTR"]) + XCTAssertFalse(jsonR1 <= ["999": "aaaa"]) + XCTAssertFalse(jsonL1 > [")(*&^": 1234567]) + XCTAssertFalse(jsonR1 < ["MNHH": "JUYTR"]) } } diff --git a/Tests/SwiftyJSONTests/DictionaryTests.swift b/Tests/SwiftyJSONTests/DictionaryTests.swift index 5f9c822f..5d73f23b 100644 --- a/Tests/SwiftyJSONTests/DictionaryTests.swift +++ b/Tests/SwiftyJSONTests/DictionaryTests.swift @@ -26,7 +26,7 @@ import SwiftyJSON class DictionaryTests: XCTestCase { func testGetter() { - let dictionary = ["number":9823.212, "name":"NAME", "list":[1234, 4.212], "object":["sub_number":877.2323, "sub_name":"sub_name"], "bool":true] as [String : Any] + let dictionary = ["number": 9823.212, "name": "NAME", "list": [1234, 4.212], "object": ["sub_number": 877.2323, "sub_name": "sub_name"], "bool": true] as [String : Any] let json = JSON(dictionary) //dictionary XCTAssertEqual((json.dictionary!["number"]! as JSON).double!, 9823.212) @@ -45,11 +45,11 @@ class DictionaryTests: XCTestCase { XCTAssertTrue(json.dictionaryObject!["null"] == nil) XCTAssertTrue(JSON.null.dictionaryObject == nil) } - + func testSetter() { - var json:JSON = ["test":"case"] - XCTAssertEqual(json.dictionaryObject! as! [String : String], ["test":"case"]) - json.dictionaryObject = ["name":"NAME"] - XCTAssertEqual(json.dictionaryObject! as! [String : String], ["name":"NAME"]) + var json: JSON = ["test": "case"] + XCTAssertEqual(json.dictionaryObject! as! [String : String], ["test": "case"]) + json.dictionaryObject = ["name": "NAME"] + XCTAssertEqual(json.dictionaryObject! as! [String : String], ["name": "NAME"]) } } diff --git a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift index fa88e231..9e478c7b 100644 --- a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift +++ b/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift @@ -26,7 +26,7 @@ import SwiftyJSON class LiteralConvertibleTests: XCTestCase { func testNumber() { - var json:JSON = 1234567890.876623 + var json: JSON = 1234567890.876623 XCTAssertEqual(json.int!, 1234567890) XCTAssertEqual(json.intValue, 1234567890) XCTAssertEqual(json.double!, 1234567890.876623) @@ -34,40 +34,40 @@ class LiteralConvertibleTests: XCTestCase { XCTAssertTrue(json.float! == 1234567890.876623) XCTAssertTrue(json.floatValue == 1234567890.876623) } - + func testBool() { - var jsonTrue:JSON = true + var jsonTrue: JSON = true XCTAssertEqual(jsonTrue.bool!, true) XCTAssertEqual(jsonTrue.boolValue, true) - var jsonFalse:JSON = false + var jsonFalse: JSON = false XCTAssertEqual(jsonFalse.bool!, false) XCTAssertEqual(jsonFalse.boolValue, false) } func testString() { - var json:JSON = "abcd efg, HIJK;LMn" + var json: JSON = "abcd efg, HIJK;LMn" XCTAssertEqual(json.string!, "abcd efg, HIJK;LMn") XCTAssertEqual(json.stringValue, "abcd efg, HIJK;LMn") } - + func testNil() { - let jsonNil_1:JSON = JSON.null + let jsonNil_1: JSON = JSON.null XCTAssert(jsonNil_1 == JSON.null) - let jsonNil_2:JSON = JSON(NSNull.self) + let jsonNil_2: JSON = JSON(NSNull.self) XCTAssert(jsonNil_2 != JSON.null) - let jsonNil_3:JSON = JSON([1:2]) + let jsonNil_3: JSON = JSON([1: 2]) XCTAssert(jsonNil_3 != JSON.null) } - + func testArray() { - let json:JSON = [1,2,"4",5,"6"] - XCTAssertEqual(json.array!, [1,2,"4",5,"6"]) - XCTAssertEqual(json.arrayValue, [1,2,"4",5,"6"]) + let json: JSON = [1, 2, "4", 5, "6"] + XCTAssertEqual(json.array!, [1, 2, "4", 5, "6"]) + XCTAssertEqual(json.arrayValue, [1, 2, "4", 5, "6"]) } - + func testDictionary() { - let json:JSON = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] - XCTAssertEqual(json.dictionary!, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) - XCTAssertEqual(json.dictionaryValue, ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]]) + let json: JSON = ["1": 2, "2": 2, "three": 3, "list": ["aa", "bb", "dd"]] + XCTAssertEqual(json.dictionary!, ["1": 2, "2": 2, "three": 3, "list": ["aa", "bb", "dd"]]) + XCTAssertEqual(json.dictionaryValue, ["1": 2, "2": 2, "three": 3, "list": ["aa", "bb", "dd"]]) } } diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift index ddc4a24f..dbee6a35 100644 --- a/Tests/SwiftyJSONTests/MergeTests.swift +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -25,11 +25,11 @@ import XCTest import SwiftyJSON class JSONTests: XCTestCase { - + func testDifferingTypes() { let A = JSON("a") let B = JSON(1) - + do { _ = try A.merged(with: B) XCTFail() @@ -41,61 +41,61 @@ class JSONTests: XCTestCase { "Couldn't merge, because the JSONs differ in type on top level.") } } - + func testPrimitiveType() { let A = JSON("a") let B = JSON("b") XCTAssertEqual(try! A.merged(with: B), B) } - + func testMergeEqual() { let json = JSON(["a": "A"]) XCTAssertEqual(try! json.merged(with: json), json) } - + func testMergeUnequalValues() { let A = JSON(["a": "A"]) let B = JSON(["a": "B"]) XCTAssertEqual(try! A.merged(with: B), B) } - + func testMergeUnequalKeysAndValues() { let A = JSON(["a": "A"]) let B = JSON(["b": "B"]) XCTAssertEqual(try! A.merged(with: B), JSON(["a": "A", "b": "B"])) } - + func testMergeFilledAndEmpty() { let A = JSON(["a": "A"]) let B = JSON([:]) XCTAssertEqual(try! A.merged(with: B), A) } - + func testMergeEmptyAndFilled() { let A = JSON([:]) let B = JSON(["a": "A"]) XCTAssertEqual(try! A.merged(with: B), B) } - + func testMergeArray() { let A = JSON(["a"]) let B = JSON(["b"]) XCTAssertEqual(try! A.merged(with: B), JSON(["a", "b"])) } - + func testMergeNestedJSONs() { let A = JSON([ "nested": [ "A": "a" ] ]) - + let B = JSON([ "nested": [ "A": "b" ] ]) - + XCTAssertEqual(try! A.merged(with: B), B) } } diff --git a/Tests/SwiftyJSONTests/NestedJSONTests.swift b/Tests/SwiftyJSONTests/NestedJSONTests.swift index 5c75def7..7134eeca 100644 --- a/Tests/SwiftyJSONTests/NestedJSONTests.swift +++ b/Tests/SwiftyJSONTests/NestedJSONTests.swift @@ -11,28 +11,28 @@ import SwiftyJSON class NestedJSONTests: XCTestCase { let family: JSON = [ - "names" : [ + "names": [ "Brooke Abigail Matos", "Rowan Danger Matos" ], - "motto" : "Hey, I don't know about you, but I'm feeling twenty-two! So, release the KrakenDev!" + "motto": "Hey, I don't know about you, but I'm feeling twenty-two! So, release the KrakenDev!" ] - + func testTopLevelNestedJSON() { let nestedJSON: JSON = [ - "family" : family + "family": family ] XCTAssertNotNil(try? nestedJSON.rawData()) } - + func testDeeplyNestedJSON() { let nestedFamily: JSON = [ "count": 1, "families": [ [ - "isACoolFamily" : true, - "family" : [ - "hello" : family + "isACoolFamily": true, + "family": [ + "hello": family ] ] ] diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index 0ae66b54..6b0c8aa9 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -31,68 +31,68 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.number!, 9876543210.123456789) XCTAssertEqual(json.numberValue, 9876543210.123456789) XCTAssertEqual(json.stringValue, "9876543210.123457") - + json.string = "1000000000000000000000000000.1" XCTAssertNil(json.number) XCTAssertEqual(json.numberValue.description, "1000000000000000000000000000.1") json.string = "1e+27" XCTAssertEqual(json.numberValue.description, "1000000000000000000000000000") - + //setter json.number = NSNumber(value: 123456789.0987654321) XCTAssertEqual(json.number!, 123456789.0987654321) XCTAssertEqual(json.numberValue, 123456789.0987654321) - + json.number = nil XCTAssertEqual(json.numberValue, 0) XCTAssertEqual(json.object as? NSNull, NSNull()) XCTAssertTrue(json.number == nil) - + json.numberValue = 2.9876 XCTAssertEqual(json.number!, 2.9876) } - + func testBool() { var json = JSON(true) XCTAssertEqual(json.bool!, true) XCTAssertEqual(json.boolValue, true) XCTAssertEqual(json.numberValue, true as NSNumber) XCTAssertEqual(json.stringValue, "true") - + json.bool = false XCTAssertEqual(json.bool!, false) XCTAssertEqual(json.boolValue, false) XCTAssertEqual(json.numberValue, false as NSNumber) - + json.bool = nil XCTAssertTrue(json.bool == nil) XCTAssertEqual(json.boolValue, false) XCTAssertEqual(json.numberValue, 0) - + json.boolValue = true XCTAssertEqual(json.bool!, true) XCTAssertEqual(json.boolValue, true) XCTAssertEqual(json.numberValue, true as NSNumber) } - + func testDouble() { var json = JSON(9876543210.123456789) XCTAssertEqual(json.double!, 9876543210.123456789) XCTAssertEqual(json.doubleValue, 9876543210.123456789) XCTAssertEqual(json.numberValue, 9876543210.123456789) XCTAssertEqual(json.stringValue, "9876543210.123457") - + json.double = 2.8765432 XCTAssertEqual(json.double!, 2.8765432) XCTAssertEqual(json.doubleValue, 2.8765432) XCTAssertEqual(json.numberValue, 2.8765432) - + json.doubleValue = 89.0987654 XCTAssertEqual(json.double!, 89.0987654) XCTAssertEqual(json.doubleValue, 89.0987654) XCTAssertEqual(json.numberValue, 89.0987654) - + json.double = nil XCTAssertEqual(json.boolValue, false) XCTAssertEqual(json.doubleValue, 0.0) @@ -106,68 +106,68 @@ class NumberTests: XCTestCase { print(json.numberValue.doubleValue) XCTAssertEqual(json.numberValue, 54321.12345) XCTAssertEqual(json.stringValue, "54321.12345") - + json.double = 23231.65 XCTAssertTrue(json.float! == 23231.65) XCTAssertTrue(json.floatValue == 23231.65) XCTAssertEqual(json.numberValue, NSNumber(value:23231.65)) - + json.double = -98766.23 XCTAssertEqual(json.float!, -98766.23) XCTAssertEqual(json.floatValue, -98766.23) XCTAssertEqual(json.numberValue, NSNumber(value:-98766.23)) } - + func testInt() { var json = JSON(123456789) XCTAssertEqual(json.int!, 123456789) XCTAssertEqual(json.intValue, 123456789) XCTAssertEqual(json.numberValue, NSNumber(value: 123456789)) XCTAssertEqual(json.stringValue, "123456789") - + json.int = nil XCTAssertTrue(json.boolValue == false) XCTAssertTrue(json.intValue == 0) XCTAssertEqual(json.numberValue, 0) XCTAssertEqual(json.object as? NSNull, NSNull()) XCTAssertTrue(json.int == nil) - + json.intValue = 76543 XCTAssertEqual(json.int!, 76543) XCTAssertEqual(json.intValue, 76543) XCTAssertEqual(json.numberValue, NSNumber(value: 76543)) - + json.intValue = 98765421 XCTAssertEqual(json.int!, 98765421) XCTAssertEqual(json.intValue, 98765421) XCTAssertEqual(json.numberValue, NSNumber(value: 98765421)) } - + func testUInt() { var json = JSON(123456789) XCTAssertTrue(json.uInt! == 123456789) XCTAssertTrue(json.uIntValue == 123456789) XCTAssertEqual(json.numberValue, NSNumber(value: 123456789)) XCTAssertEqual(json.stringValue, "123456789") - + json.uInt = nil XCTAssertTrue(json.boolValue == false) XCTAssertTrue(json.uIntValue == 0) XCTAssertEqual(json.numberValue, 0) XCTAssertEqual(json.object as? NSNull, NSNull()) XCTAssertTrue(json.uInt == nil) - + json.uIntValue = 76543 XCTAssertTrue(json.uInt! == 76543) XCTAssertTrue(json.uIntValue == 76543) XCTAssertEqual(json.numberValue, NSNumber(value: 76543)) - + json.uIntValue = 98765421 XCTAssertTrue(json.uInt! == 98765421) XCTAssertTrue(json.uIntValue == 98765421) XCTAssertEqual(json.numberValue, NSNumber(value: 98765421)) } - + func testInt8() { let n127 = NSNumber(value: 127) var json = JSON(n127) @@ -176,7 +176,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n127) XCTAssertEqual(json.numberValue, n127) XCTAssertEqual(json.stringValue, "127") - + let nm128 = NSNumber(value: -128) json.int8Value = nm128.int8Value XCTAssertTrue(json.int8! == nm128.int8Value) @@ -184,7 +184,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == nm128) XCTAssertEqual(json.numberValue, nm128) XCTAssertEqual(json.stringValue, "-128") - + let n0 = NSNumber(value: 0 as Int8) json.int8Value = n0.int8Value XCTAssertTrue(json.int8! == n0.int8Value) @@ -192,8 +192,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n0) XCTAssertEqual(json.numberValue, n0) XCTAssertEqual(json.stringValue, "0") - - + let n1 = NSNumber(value: 1 as Int8) json.int8Value = n1.int8Value XCTAssertTrue(json.int8! == n1.int8Value) @@ -202,7 +201,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, n1) XCTAssertEqual(json.stringValue, "1") } - + func testUInt8() { let n255 = NSNumber(value: 255) var json = JSON(n255) @@ -211,7 +210,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n255) XCTAssertEqual(json.numberValue, n255) XCTAssertEqual(json.stringValue, "255") - + let nm2 = NSNumber(value: 2) json.uInt8Value = nm2.uint8Value XCTAssertTrue(json.uInt8! == nm2.uint8Value) @@ -219,7 +218,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == nm2) XCTAssertEqual(json.numberValue, nm2) XCTAssertEqual(json.stringValue, "2") - + let nm0 = NSNumber(value: 0) json.uInt8Value = nm0.uint8Value XCTAssertTrue(json.uInt8! == nm0.uint8Value) @@ -238,7 +237,7 @@ class NumberTests: XCTestCase { } func testInt16() { - + let n32767 = NSNumber(value: 32767) var json = JSON(n32767) XCTAssertTrue(json.int16! == n32767.int16Value) @@ -246,7 +245,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - + let nm32768 = NSNumber(value: -32768) json.int16Value = nm32768.int16Value XCTAssertTrue(json.int16! == nm32768.int16Value) @@ -254,7 +253,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == nm32768) XCTAssertEqual(json.numberValue, nm32768) XCTAssertEqual(json.stringValue, "-32768") - + let n0 = NSNumber(value: 0) json.int16Value = n0.int16Value XCTAssertTrue(json.int16! == n0.int16Value) @@ -262,7 +261,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.number, n0) XCTAssertEqual(json.numberValue, n0) XCTAssertEqual(json.stringValue, "0") - + let n1 = NSNumber(value: 1) json.int16 = n1.int16Value XCTAssertTrue(json.int16! == n1.int16Value) @@ -299,7 +298,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n2147483647) XCTAssertEqual(json.numberValue, n2147483647) XCTAssertEqual(json.stringValue, "2147483647") - + let n32767 = NSNumber(value: 32767) json.int32 = n32767.int32Value XCTAssertTrue(json.int32! == n32767.int32Value) @@ -307,7 +306,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - + let nm2147483648 = NSNumber(value: -2147483648) json.int32Value = nm2147483648.int32Value XCTAssertTrue(json.int32! == nm2147483648.int32Value) @@ -316,7 +315,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, nm2147483648) XCTAssertEqual(json.stringValue, "-2147483648") } - + func testUInt32() { let n2147483648 = NSNumber(value: 2147483648 as UInt32) var json = JSON(n2147483648) @@ -325,7 +324,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n2147483648) XCTAssertEqual(json.numberValue, n2147483648) XCTAssertEqual(json.stringValue, "2147483648") - + let n32767 = NSNumber(value: 32767 as UInt32) json.uInt32 = n32767.uint32Value XCTAssertTrue(json.uInt32! == n32767.uint32Value) @@ -333,7 +332,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - + let n0 = NSNumber(value: 0 as UInt32) json.uInt32Value = n0.uint32Value XCTAssertTrue(json.uInt32! == n0.uint32Value) @@ -351,7 +350,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == int64Max) XCTAssertEqual(json.numberValue, int64Max) XCTAssertEqual(json.stringValue, int64Max.stringValue) - + let n32767 = NSNumber(value: 32767) json.int64 = n32767.int64Value XCTAssertTrue(json.int64! == n32767.int64Value) @@ -359,7 +358,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == n32767) XCTAssertEqual(json.numberValue, n32767) XCTAssertEqual(json.stringValue, "32767") - + let int64Min = NSNumber(value: (INT64_MAX-1) * -1) json.int64Value = int64Min.int64Value XCTAssertTrue(json.int64! == int64Min.int64Value) @@ -368,7 +367,7 @@ class NumberTests: XCTestCase { XCTAssertEqual(json.numberValue, int64Min) XCTAssertEqual(json.stringValue, int64Min.stringValue) } - + func testUInt64() { let uInt64Max = NSNumber(value: UINT64_MAX) var json = JSON(uInt64Max) @@ -377,7 +376,7 @@ class NumberTests: XCTestCase { XCTAssertTrue(json.number! == uInt64Max) XCTAssertEqual(json.numberValue, uInt64Max) XCTAssertEqual(json.stringValue, uInt64Max.stringValue) - + let n32767 = NSNumber(value: 32767) json.int64 = n32767.int64Value XCTAssertTrue(json.int64! == n32767.int64Value) diff --git a/Tests/SwiftyJSONTests/PerformanceTests.swift b/Tests/SwiftyJSONTests/PerformanceTests.swift index e3ed9760..850d3e90 100644 --- a/Tests/SwiftyJSONTests/PerformanceTests.swift +++ b/Tests/SwiftyJSONTests/PerformanceTests.swift @@ -26,34 +26,34 @@ import SwiftyJSON class PerformanceTests: XCTestCase { var testData: Data! - + override func setUp() { super.setUp() - + if let file = Bundle(for:PerformanceTests.self).path(forResource: "Tests", ofType: "json") { self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { XCTFail("Can't find the test JSON file") } } - + override func tearDown() { // Put teardown code here. This method is called after the invocation of each test method in the class. super.tearDown() } - + func testInitPerformance() { - self.measure() { + self.measure { for _ in 1...100 { let json = JSON(data:self.testData) XCTAssertTrue(json != JSON.null) } } } - + func testObjectMethodPerformance() { let json = JSON(data:self.testData) - self.measure() { + self.measure { for _ in 1...100 { let object:Any? = json.object XCTAssertTrue(object != nil) @@ -63,9 +63,9 @@ class PerformanceTests: XCTestCase { func testArrayMethodPerformance() { let json = JSON(data:self.testData) - self.measure() { + self.measure { for _ in 1...100 { - autoreleasepool{ + autoreleasepool { if let array = json.array { XCTAssertTrue(array.count > 0) } @@ -73,12 +73,12 @@ class PerformanceTests: XCTestCase { } } } - + func testDictionaryMethodPerformance() { let json = JSON(data:testData)[0] - self.measure() { + self.measure { for _ in 1...100 { - autoreleasepool{ + autoreleasepool { if let dictionary = json.dictionary { XCTAssertTrue(dictionary.count > 0) } @@ -86,12 +86,12 @@ class PerformanceTests: XCTestCase { } } } - + func testRawStringMethodPerformance() { let json = JSON(data:testData) - self.measure() { + self.measure { for _ in 1...100 { - autoreleasepool{ + autoreleasepool { let string = json.rawString() XCTAssertTrue(string != nil) } @@ -108,9 +108,9 @@ class PerformanceTests: XCTestCase { ]) } let json = JSON(data) - - self.measure() { - autoreleasepool{ + + self.measure { + autoreleasepool { if let dictionary = json.dictionary { XCTAssertTrue(dictionary.count > 0) } else { diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index f60fc8c1..ebecbe1a 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -25,37 +25,37 @@ import SwiftyJSON class PrintableTests: XCTestCase { func testNumber() { - let json:JSON = 1234567890.876623 + let json: JSON = 1234567890.876623 XCTAssertEqual(json.description, "1234567890.876623") XCTAssertEqual(json.debugDescription, "1234567890.876623") } - + func testBool() { - let jsonTrue:JSON = true + let jsonTrue: JSON = true XCTAssertEqual(jsonTrue.description, "true") XCTAssertEqual(jsonTrue.debugDescription, "true") - let jsonFalse:JSON = false + let jsonFalse: JSON = false XCTAssertEqual(jsonFalse.description, "false") XCTAssertEqual(jsonFalse.debugDescription, "false") } - + func testString() { - let json:JSON = "abcd efg, HIJK;LMn" + let json: JSON = "abcd efg, HIJK;LMn" XCTAssertEqual(json.description, "abcd efg, HIJK;LMn") XCTAssertEqual(json.debugDescription, "abcd efg, HIJK;LMn") } - + func testNil() { - let jsonNil_1:JSON = JSON.null + let jsonNil_1: JSON = JSON.null XCTAssertEqual(jsonNil_1.description, "null") XCTAssertEqual(jsonNil_1.debugDescription, "null") - let jsonNil_2:JSON = JSON(NSNull()) + let jsonNil_2: JSON = JSON(NSNull()) XCTAssertEqual(jsonNil_2.description, "null") XCTAssertEqual(jsonNil_2.debugDescription, "null") } - + func testArray() { - let json:JSON = [1,2,"4",5,"6"] + let json: JSON = [1, 2, "4", 5, "6"] var description = json.description.replacingOccurrences(of: "\n", with: "") description = description.replacingOccurrences(of: " ", with: "") XCTAssertEqual(description, "[1,2,\"4\",5,\"6\"]") @@ -74,7 +74,7 @@ class PrintableTests: XCTestCase { } func testArrayWithOptionals() { - let array = [1,2,"4",5,"6",nil] as [Any?] + let array = [1, 2, "4", 5, "6", nil] as [Any?] let json = JSON(array) guard var description = json.rawString([.castNilToNSNull: true]) else { XCTFail("could not represent array") @@ -86,9 +86,9 @@ class PrintableTests: XCTestCase { XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) XCTAssertTrue(json.debugDescription.lengthOfBytes(using: String.Encoding.utf8) > 0) } - + func testDictionary() { - let json:JSON = ["1":2,"2":"two", "3":3] + let json: JSON = ["1": 2, "2": "two", "3": 3] var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") XCTAssertTrue(json.description.lengthOfBytes(using: String.Encoding.utf8) > 0) @@ -98,7 +98,7 @@ class PrintableTests: XCTestCase { } func testDictionaryWithStrings() { - let dict = ["foo":"{\"bar\":123}"] as [String : Any] + let dict = ["foo": "{\"bar\":123}"] as [String : Any] let json = JSON(dict) var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") @@ -108,7 +108,7 @@ class PrintableTests: XCTestCase { } func testDictionaryWithOptionals() { - let dict = ["1":2, "2":"two", "3": nil] as [String: Any?] + let dict = ["1": 2, "2": "two", "3": nil] as [String: Any?] let json = JSON(dict) guard var description = json.rawString([.castNilToNSNull: true]) else { XCTFail("could not represent dictionary") diff --git a/Tests/SwiftyJSONTests/RawRepresentableTests.swift b/Tests/SwiftyJSONTests/RawRepresentableTests.swift index 9ebf9b2e..1482a05b 100644 --- a/Tests/SwiftyJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftyJSONTests/RawRepresentableTests.swift @@ -26,40 +26,40 @@ import SwiftyJSON class RawRepresentableTests: XCTestCase { func testNumber() { - var json:JSON = JSON(rawValue: 948394394.347384 as NSNumber)! + var json: JSON = JSON(rawValue: 948394394.347384 as NSNumber)! XCTAssertEqual(json.int!, 948394394) XCTAssertEqual(json.intValue, 948394394) XCTAssertEqual(json.double!, 948394394.347384) XCTAssertEqual(json.doubleValue, 948394394.347384) XCTAssertTrue(json.float! == 948394394.347384) XCTAssertTrue(json.floatValue == 948394394.347384) - + let object: Any = json.rawValue XCTAssertEqual(object as? Int, 948394394) XCTAssertEqual(object as? Double, 948394394.347384) XCTAssertTrue(object as! Float == 948394394.347384) XCTAssertEqual(object as? NSNumber, 948394394.347384) } - + func testBool() { - var jsonTrue:JSON = JSON(rawValue: true as NSNumber)! + var jsonTrue: JSON = JSON(rawValue: true as NSNumber)! XCTAssertEqual(jsonTrue.bool!, true) XCTAssertEqual(jsonTrue.boolValue, true) - - var jsonFalse:JSON = JSON(rawValue: false)! + + var jsonFalse: JSON = JSON(rawValue: false)! XCTAssertEqual(jsonFalse.bool!, false) XCTAssertEqual(jsonFalse.boolValue, false) - + let objectTrue = jsonTrue.rawValue XCTAssertEqual(objectTrue as? Bool, true) - + let objectFalse = jsonFalse.rawValue XCTAssertEqual(objectFalse as? Bool, false) } - + func testString() { let string = "The better way to deal with JSON data in Swift." - if let json:JSON = JSON(rawValue: string) { + if let json: JSON = JSON(rawValue: string) { XCTAssertEqual(json.string!, string) XCTAssertEqual(json.stringValue, string) XCTAssertTrue(json.array == nil) @@ -71,30 +71,30 @@ class RawRepresentableTests: XCTestCase { } else { XCTFail("Should not run into here") } - + let object: Any = JSON(rawValue: string)!.rawValue XCTAssertEqual(object as? String, string) } - + func testNil() { if let _ = JSON(rawValue: NSObject()) { XCTFail("Should not run into here") } } - + func testArray() { - let array = [1,2,"3",4102,"5632", "abocde", "!@# $%^&*()"] as NSArray - if let json:JSON = JSON(rawValue: array) { + let array = [1, 2, "3", 4102, "5632", "abocde", "!@# $%^&*()"] as NSArray + if let json: JSON = JSON(rawValue: array) { XCTAssertEqual(json, JSON(array)) } - + let object: Any = JSON(rawValue: array)!.rawValue XCTAssertTrue(array == object as! NSArray) } - + func testDictionary() { - let dictionary = ["1":2,"2":2,"three":3,"list":["aa","bb","dd"]] as NSDictionary - if let json:JSON = JSON(rawValue: dictionary) { + let dictionary = ["1": 2, "2": 2, "three": 3, "list": ["aa", "bb", "dd"]] as NSDictionary + if let json: JSON = JSON(rawValue: dictionary) { XCTAssertEqual(json, JSON(dictionary)) } diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift index 7693d8e3..faa043a1 100644 --- a/Tests/SwiftyJSONTests/RawTests.swift +++ b/Tests/SwiftyJSONTests/RawTests.swift @@ -26,7 +26,7 @@ import SwiftyJSON class RawTests: XCTestCase { func testRawData() { - let json: JSON = ["somekey" : "some string value"] + let json: JSON = ["somekey": "some string value"] let expectedRawData = "{\"somekey\":\"some string value\"}".data(using: String.Encoding.utf8) do { let data: Data = try json.rawData() @@ -35,7 +35,7 @@ class RawTests: XCTestCase { XCTFail() } } - + func testInvalidJSONForRawData() { let json: JSON = "...xyz" do { @@ -44,9 +44,9 @@ class RawTests: XCTestCase { XCTAssertEqual(error.code, ErrorInvalidJSON) } } - + func testArray() { - let json:JSON = [1, "2", 3.12, NSNull(), true, ["name": "Jack"]] + let json: JSON = [1, "2", 3.12, NSNull(), true, ["name": "Jack"]] let data: Data? do { data = try json.rawData() @@ -58,9 +58,9 @@ class RawTests: XCTestCase { XCTAssertTrue (string!.lengthOfBytes(using: String.Encoding.utf8) > 0) print(string!) } - + func testDictionary() { - let json:JSON = ["number":111111.23456789, "name":"Jack", "list":[1,2,3,4], "bool":false, "null":NSNull()] + let json: JSON = ["number": 111111.23456789, "name": "Jack", "list": [1, 2, 3, 4], "bool": false, "null": NSNull()] let data: Data? do { data = try json.rawData() @@ -72,24 +72,24 @@ class RawTests: XCTestCase { XCTAssertTrue (string!.lengthOfBytes(using: String.Encoding.utf8) > 0) print(string!) } - + func testString() { - let json:JSON = "I'm a json" + let json: JSON = "I'm a json" XCTAssertEqual(json.rawString(), "I'm a json") } - + func testNumber() { - let json:JSON = 123456789.123 + let json: JSON = 123456789.123 XCTAssertEqual(json.rawString(), "123456789.123") } - + func testBool() { - let json:JSON = true + let json: JSON = true XCTAssertEqual(json.rawString(), "true") } - + func testNull() { - let json:JSON = JSON.null + let json: JSON = JSON.null XCTAssertEqual(json.rawString(), "null") } } diff --git a/Tests/SwiftyJSONTests/SequenceTypeTests.swift b/Tests/SwiftyJSONTests/SequenceTypeTests.swift index 8f164c4c..3c388b7e 100644 --- a/Tests/SwiftyJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftyJSONTests/SequenceTypeTests.swift @@ -48,7 +48,7 @@ class SequenceTypeTests: XCTestCase { } func testArrayAllNumber() { - var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] + var json: JSON = [1, 2.0, 3.3, 123456789, 987654321.123456789] XCTAssertEqual(json.count, 5) var index = 0 @@ -60,11 +60,11 @@ class SequenceTypeTests: XCTestCase { index += 1 } XCTAssertEqual(index, 5) - XCTAssertEqual(array, [1,2.0,3.3,123456789,987654321.123456789]) + XCTAssertEqual(array, [1, 2.0, 3.3, 123456789, 987654321.123456789]) } func testArrayAllBool() { - var json:JSON = JSON([true, false, false, true, true]) + var json: JSON = JSON([true, false, false, true, true]) XCTAssertEqual(json.count, 5) var index = 0 @@ -80,7 +80,7 @@ class SequenceTypeTests: XCTestCase { } func testArrayAllString() { - var json:JSON = JSON(rawValue: ["aoo","bpp","zoo"] as NSArray)! + var json: JSON = JSON(rawValue: ["aoo", "bpp", "zoo"] as NSArray)! XCTAssertEqual(json.count, 3) var index = 0 @@ -92,11 +92,11 @@ class SequenceTypeTests: XCTestCase { index += 1 } XCTAssertEqual(index, 3) - XCTAssertEqual(array, ["aoo","bpp","zoo"]) + XCTAssertEqual(array, ["aoo", "bpp", "zoo"]) } func testArrayWithNull() { - var json:JSON = JSON(rawValue: ["aoo","bpp", NSNull() ,"zoo"] as NSArray)! + var json: JSON = JSON(rawValue: ["aoo", "bpp", NSNull(), "zoo"] as NSArray)! XCTAssertEqual(json.count, 4) var index = 0 @@ -113,7 +113,7 @@ class SequenceTypeTests: XCTestCase { } func testArrayAllDictionary() { - var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] + var json: JSON = [["1": 1, "2": 2], ["a": "A", "b": "B"], ["null": NSNull()]] XCTAssertEqual(json.count, 3) var index = 0 @@ -133,11 +133,11 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryAllNumber() { - var json:JSON = ["double":1.11111, "int":987654321] + var json: JSON = ["double": 1.11111, "int": 987654321] XCTAssertEqual(json.count, 2) var index = 0 - var dictionary = [String:NSNumber]() + var dictionary = [String: NSNumber]() for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.number! @@ -150,11 +150,11 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryAllBool() { - var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] + var json: JSON = ["t": true, "f": false, "false": false, "tr": true, "true": true] XCTAssertEqual(json.count, 5) var index = 0 - var dictionary = [String:Bool]() + var dictionary = [String: Bool]() for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.bool! @@ -167,11 +167,11 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryAllString() { - var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! + var json: JSON = JSON(rawValue: ["a": "aoo", "bb": "bpp", "z": "zoo"] as NSDictionary)! XCTAssertEqual(json.count, 3) var index = 0 - var dictionary = [String:String]() + var dictionary = [String: String]() for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.string! @@ -184,11 +184,11 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryWithNull() { - var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! + var json: JSON = JSON(rawValue: ["a": "aoo", "bb": "bpp", "null": NSNull(), "z": "zoo"] as NSDictionary)! XCTAssertEqual(json.count, 4) var index = 0 - var dictionary = [String:AnyObject]() + var dictionary = [String: AnyObject]() for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.object as AnyObject? @@ -202,12 +202,12 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryAllArray() { - var json:JSON = JSON (["Number":[NSNumber(value:1),NSNumber(value:2.123456),NSNumber(value:123456789)], "String":["aa","bbb","cccc"], "Mix":[true, "766", NSNull(), 655231.9823]]) + var json: JSON = JSON (["Number": [NSNumber(value:1), NSNumber(value:2.123456), NSNumber(value:123456789)], "String": ["aa", "bbb", "cccc"], "Mix": [true, "766", NSNull(), 655231.9823]]) XCTAssertEqual(json.count, 3) var index = 0 - var dictionary = [String:AnyObject]() + var dictionary = [String: AnyObject]() for (key, sub) in json { XCTAssertEqual(sub, json[key]) dictionary[key] = sub.object as AnyObject? diff --git a/Tests/SwiftyJSONTests/StringTests.swift b/Tests/SwiftyJSONTests/StringTests.swift index 8d8e6ebc..fb226fc5 100644 --- a/Tests/SwiftyJSONTests/StringTests.swift +++ b/Tests/SwiftyJSONTests/StringTests.swift @@ -35,7 +35,7 @@ class StringTests: XCTestCase { XCTAssertEqual(json.string!, "12345?67890.@#") XCTAssertEqual(json.stringValue, "12345?67890.@#") } - + func testUrl() { let json = JSON("http://github.com") XCTAssertEqual(json.url!, URL(string:"http://github.com")!) diff --git a/Tests/SwiftyJSONTests/SubscriptTests.swift b/Tests/SwiftyJSONTests/SubscriptTests.swift index 2a5cd97e..7c71a941 100644 --- a/Tests/SwiftyJSONTests/SubscriptTests.swift +++ b/Tests/SwiftyJSONTests/SubscriptTests.swift @@ -26,63 +26,63 @@ import SwiftyJSON class SubscriptTests: XCTestCase { func testArrayAllNumber() { - var json:JSON = [1,2.0,3.3,123456789,987654321.123456789] - XCTAssertTrue(json == [1,2.0,3.3,123456789,987654321.123456789]) + var json: JSON = [1, 2.0, 3.3, 123456789, 987654321.123456789] + XCTAssertTrue(json == [1, 2.0, 3.3, 123456789, 987654321.123456789]) XCTAssertTrue(json[0] == 1) XCTAssertEqual(json[1].double!, 2.0) XCTAssertTrue(json[2].floatValue == 3.3) XCTAssertEqual(json[3].int!, 123456789) XCTAssertEqual(json[4].doubleValue, 987654321.123456789) - + json[0] = 1.9 json[1] = 2.899 json[2] = 3.567 json[3] = 0.999 json[4] = 98732 - + XCTAssertTrue(json[0] == 1.9) XCTAssertEqual(json[1].doubleValue, 2.899) XCTAssertTrue(json[2] == 3.567) XCTAssertTrue(json[3].float! == 0.999) XCTAssertTrue(json[4].intValue == 98732) } - + func testArrayAllBool() { - var json:JSON = [true, false, false, true, true] + var json: JSON = [true, false, false, true, true] XCTAssertTrue(json == [true, false, false, true, true]) XCTAssertTrue(json[0] == true) XCTAssertTrue(json[1] == false) XCTAssertTrue(json[2] == false) XCTAssertTrue(json[3] == true) XCTAssertTrue(json[4] == true) - + json[0] = false json[4] = true XCTAssertTrue(json[0] == false) XCTAssertTrue(json[4] == true) } - + func testArrayAllString() { - var json:JSON = JSON(rawValue: ["aoo","bpp","zoo"] as NSArray)! - XCTAssertTrue(json == ["aoo","bpp","zoo"]) + var json: JSON = JSON(rawValue: ["aoo", "bpp", "zoo"] as NSArray)! + XCTAssertTrue(json == ["aoo", "bpp", "zoo"]) XCTAssertTrue(json[0] == "aoo") XCTAssertTrue(json[1] == "bpp") XCTAssertTrue(json[2] == "zoo") - + json[1] = "update" XCTAssertTrue(json[0] == "aoo") XCTAssertTrue(json[1] == "update") XCTAssertTrue(json[2] == "zoo") } - + func testArrayWithNull() { - var json:JSON = JSON(rawValue: ["aoo","bpp", NSNull() ,"zoo"] as NSArray)! + var json: JSON = JSON(rawValue: ["aoo", "bpp", NSNull(), "zoo"] as NSArray)! XCTAssertTrue(json[0] == "aoo") XCTAssertTrue(json[1] == "bpp") XCTAssertNil(json[2].string) XCTAssertNotNil(json[2].null) XCTAssertTrue(json[3] == "zoo") - + json[2] = "update" json[3] = JSON(NSNull()) XCTAssertTrue(json[0] == "aoo") @@ -91,27 +91,27 @@ class SubscriptTests: XCTestCase { XCTAssertNil(json[3].string) XCTAssertNotNil(json[3].null) } - + func testArrayAllDictionary() { - var json:JSON = [["1":1, "2":2], ["a":"A", "b":"B"], ["null":NSNull()]] - XCTAssertTrue(json[0] == ["1":1, "2":2]) - XCTAssertEqual(json[1].dictionary!, ["a":"A", "b":"B"]) - XCTAssertEqual(json[2], JSON(["null":NSNull()])) + var json: JSON = [["1": 1, "2": 2], ["a": "A", "b": "B"], ["null": NSNull()]] + XCTAssertTrue(json[0] == ["1": 1, "2": 2]) + XCTAssertEqual(json[1].dictionary!, ["a": "A", "b": "B"]) + XCTAssertEqual(json[2], JSON(["null": NSNull()])) XCTAssertTrue(json[0]["1"] == 1) XCTAssertTrue(json[0]["2"] == 2) XCTAssertEqual(json[1]["a"], JSON(rawValue: "A")!) XCTAssertEqual(json[1]["b"], JSON("B")) XCTAssertNotNil(json[2]["null"].null) - XCTAssertNotNil(json[2,"null"].null) - let keys:[JSONSubscriptType] = [1, "a"] + XCTAssertNotNil(json[2, "null"].null) + let keys: [JSONSubscriptType] = [1, "a"] XCTAssertEqual(json[keys], JSON(rawValue: "A")!) } - + func testDictionaryAllNumber() { - var json:JSON = ["double":1.11111, "int":987654321] + var json: JSON = ["double": 1.11111, "int": 987654321] XCTAssertEqual(json["double"].double!, 1.11111) XCTAssertTrue(json["int"] == 987654321) - + json["double"] = 2.2222 json["int"] = 123456789 json["add"] = 7890 @@ -119,9 +119,9 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json["int"].doubleValue, 123456789.0) XCTAssertEqual(json["add"].intValue, 7890) } - + func testDictionaryAllBool() { - var json:JSON = ["t":true, "f":false, "false":false, "tr":true, "true":true] + var json: JSON = ["t": true, "f": false, "false": false, "tr": true, "true": true] XCTAssertTrue(json["t"] == true) XCTAssertTrue(json["f"] == false) XCTAssertTrue(json["false"] == false) @@ -133,61 +133,61 @@ class SubscriptTests: XCTestCase { XCTAssertTrue(json["f"] == true) XCTAssertTrue(json["tr"] == JSON(false)) } - + func testDictionaryAllString() { - var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","z":"zoo"] as NSDictionary)! + var json: JSON = JSON(rawValue: ["a": "aoo", "bb": "bpp", "z": "zoo"] as NSDictionary)! XCTAssertTrue(json["a"] == "aoo") XCTAssertEqual(json["bb"], JSON("bpp")) XCTAssertTrue(json["z"] == "zoo") - + json["bb"] = "update" XCTAssertTrue(json["a"] == "aoo") XCTAssertTrue(json["bb"] == "update") XCTAssertTrue(json["z"] == "zoo") } - + func testDictionaryWithNull() { - var json:JSON = JSON(rawValue: ["a":"aoo","bb":"bpp","null":NSNull(), "z":"zoo"] as NSDictionary)! + var json: JSON = JSON(rawValue: ["a": "aoo", "bb": "bpp", "null": NSNull(), "z": "zoo"] as NSDictionary)! XCTAssertTrue(json["a"] == "aoo") XCTAssertEqual(json["bb"], JSON("bpp")) XCTAssertEqual(json["null"], JSON(NSNull())) XCTAssertTrue(json["z"] == "zoo") - + json["null"] = "update" XCTAssertTrue(json["a"] == "aoo") XCTAssertTrue(json["null"] == "update") XCTAssertTrue(json["z"] == "zoo") } - + func testDictionaryAllArray() { //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) - let json:JSON = JSON ([[NSNumber(value:1),NSNumber(value:2.123456),NSNumber(value:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) - XCTAssertTrue(json[0] == [1,2.123456,123456789]) + let json: JSON = JSON ([[NSNumber(value:1), NSNumber(value:2.123456), NSNumber(value:123456789)], ["aa", "bbb", "cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + XCTAssertTrue(json[0] == [1, 2.123456, 123456789]) XCTAssertEqual(json[0][1].double!, 2.123456) XCTAssertTrue(json[0][2] == 123456789) XCTAssertTrue(json[1][0] == "aa") - XCTAssertTrue(json[1] == ["aa","bbb","cccc"]) + XCTAssertTrue(json[1] == ["aa", "bbb", "cccc"]) XCTAssertTrue(json[2][0] == true) XCTAssertTrue(json[2][1] == "766") - XCTAssertTrue(json[[2,1]] == "766") + XCTAssertTrue(json[[2, 1]] == "766") XCTAssertEqual(json[2][2], JSON(NSNull())) - XCTAssertEqual(json[2,2], JSON(NSNull())) + XCTAssertEqual(json[2, 2], JSON(NSNull())) XCTAssertEqual(json[2][3], JSON(655231.9823)) - XCTAssertEqual(json[2,3], JSON(655231.9823)) - XCTAssertEqual(json[[2,3]], JSON(655231.9823)) + XCTAssertEqual(json[2, 3], JSON(655231.9823)) + XCTAssertEqual(json[[2, 3]], JSON(655231.9823)) } - + func testOutOfBounds() { - let json:JSON = JSON ([[NSNumber(value:1),NSNumber(value:2.123456),NSNumber(value:123456789)], ["aa","bbb","cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let json: JSON = JSON ([[NSNumber(value:1), NSNumber(value:2.123456), NSNumber(value:123456789)], ["aa", "bbb", "cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertEqual(json[9], JSON.null) XCTAssertEqual(json[-2].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[9][8], JSON.null) XCTAssertEqual(json[8][7].error!.code, ErrorIndexOutOfBounds) - XCTAssertEqual(json[8,7].error!.code, ErrorIndexOutOfBounds) + XCTAssertEqual(json[8, 7].error!.code, ErrorIndexOutOfBounds) XCTAssertEqual(json[999].error!.code, ErrorIndexOutOfBounds) } - + func testErrorWrongType() { let json = JSON(12345) XCTAssertEqual(json[9], JSON.null) @@ -198,68 +198,68 @@ class SubscriptTests: XCTestCase { XCTAssertEqual(json[0]["name"].error!.code, ErrorWrongType) XCTAssertEqual(json["type"]["name"].error!.code, ErrorWrongType) XCTAssertEqual(json["name"][99].error!.code, ErrorWrongType) - XCTAssertEqual(json[1,"Value"].error!.code, ErrorWrongType) - XCTAssertEqual(json[1, 2,"Value"].error!.code, ErrorWrongType) - XCTAssertEqual(json[[1, 2,"Value"]].error!.code, ErrorWrongType) + XCTAssertEqual(json[1, "Value"].error!.code, ErrorWrongType) + XCTAssertEqual(json[1, 2, "Value"].error!.code, ErrorWrongType) + XCTAssertEqual(json[[1, 2, "Value"]].error!.code, ErrorWrongType) } - + func testErrorNotExist() { - let json:JSON = ["name":"NAME", "age":15] + let json: JSON = ["name": "NAME", "age": 15] XCTAssertEqual(json["Type"], JSON.null) XCTAssertEqual(json["Type"].error!.code, ErrorNotExist) XCTAssertEqual(json["Type"][1].error!.code, ErrorNotExist) XCTAssertEqual(json["Type", 1].error!.code, ErrorNotExist) XCTAssertEqual(json["Type"]["Value"].error!.code, ErrorNotExist) - XCTAssertEqual(json["Type","Value"].error!.code, ErrorNotExist) + XCTAssertEqual(json["Type", "Value"].error!.code, ErrorNotExist) } - + func testMultilevelGetter() { - let json:JSON = [[[[["one":1]]]]] + let json: JSON = [[[[["one": 1]]]]] XCTAssertEqual(json[[0, 0, 0, 0, "one"]].int!, 1) XCTAssertEqual(json[0, 0, 0, 0, "one"].int!, 1) XCTAssertEqual(json[0][0][0][0]["one"].int!, 1) } - + func testMultilevelSetter1() { - var json:JSON = [[[[["num":1]]]]] + var json: JSON = [[[[["num": 1]]]]] json[0, 0, 0, 0, "num"] = 2 XCTAssertEqual(json[[0, 0, 0, 0, "num"]].intValue, 2) json[0, 0, 0, 0, "num"] = JSON.null XCTAssertEqual(json[0, 0, 0, 0, "num"].null!, NSNull()) json[0, 0, 0, 0, "num"] = 100.009 XCTAssertEqual(json[0][0][0][0]["num"].doubleValue, 100.009) - json[[0, 0, 0, 0]] = ["name":"Jack"] - XCTAssertEqual(json[0,0,0,0,"name"].stringValue, "Jack") + json[[0, 0, 0, 0]] = ["name": "Jack"] + XCTAssertEqual(json[0, 0, 0, 0, "name"].stringValue, "Jack") XCTAssertEqual(json[0][0][0][0]["name"].stringValue, "Jack") - XCTAssertEqual(json[[0,0,0,0,"name"]].stringValue, "Jack") - json[[0,0,0,0,"name"]].string = "Mike" - XCTAssertEqual(json[0,0,0,0,"name"].stringValue, "Mike") - let path:[JSONSubscriptType] = [0,0,0,0,"name"] + XCTAssertEqual(json[[0, 0, 0, 0, "name"]].stringValue, "Jack") + json[[0, 0, 0, 0, "name"]].string = "Mike" + XCTAssertEqual(json[0, 0, 0, 0, "name"].stringValue, "Mike") + let path: [JSONSubscriptType] = [0, 0, 0, 0, "name"] json[path].string = "Jim" XCTAssertEqual(json[path].stringValue, "Jim") } - + func testMultilevelSetter2() { - var json:JSON = ["user":["id":987654, "info":["name":"jack","email":"jack@gmail.com"], "feeds":[98833,23443,213239,23232]]] - json["user","info","name"] = "jim" - XCTAssertEqual(json["user","id"], 987654) - XCTAssertEqual(json["user","info","name"], "jim") - XCTAssertEqual(json["user","info","email"], "jack@gmail.com") - XCTAssertEqual(json["user","feeds"], [98833,23443,213239,23232]) - json["user","info","email"] = "jim@hotmail.com" - XCTAssertEqual(json["user","id"], 987654) - XCTAssertEqual(json["user","info","name"], "jim") - XCTAssertEqual(json["user","info","email"], "jim@hotmail.com") - XCTAssertEqual(json["user","feeds"], [98833,23443,213239,23232]) - json["user","info"] = ["name":"tom","email":"tom@qq.com"] - XCTAssertEqual(json["user","id"], 987654) - XCTAssertEqual(json["user","info","name"], "tom") - XCTAssertEqual(json["user","info","email"], "tom@qq.com") - XCTAssertEqual(json["user","feeds"], [98833,23443,213239,23232]) - json["user","feeds"] = [77323,2313,4545,323] - XCTAssertEqual(json["user","id"], 987654) - XCTAssertEqual(json["user","info","name"], "tom") - XCTAssertEqual(json["user","info","email"], "tom@qq.com") - XCTAssertEqual(json["user","feeds"], [77323,2313,4545,323]) + var json: JSON = ["user": ["id": 987654, "info": ["name": "jack", "email": "jack@gmail.com"], "feeds": [98833, 23443, 213239, 23232]]] + json["user", "info", "name"] = "jim" + XCTAssertEqual(json["user", "id"], 987654) + XCTAssertEqual(json["user", "info", "name"], "jim") + XCTAssertEqual(json["user", "info", "email"], "jack@gmail.com") + XCTAssertEqual(json["user", "feeds"], [98833, 23443, 213239, 23232]) + json["user", "info", "email"] = "jim@hotmail.com" + XCTAssertEqual(json["user", "id"], 987654) + XCTAssertEqual(json["user", "info", "name"], "jim") + XCTAssertEqual(json["user", "info", "email"], "jim@hotmail.com") + XCTAssertEqual(json["user", "feeds"], [98833, 23443, 213239, 23232]) + json["user", "info"] = ["name": "tom", "email": "tom@qq.com"] + XCTAssertEqual(json["user", "id"], 987654) + XCTAssertEqual(json["user", "info", "name"], "tom") + XCTAssertEqual(json["user", "info", "email"], "tom@qq.com") + XCTAssertEqual(json["user", "feeds"], [98833, 23443, 213239, 23232]) + json["user", "feeds"] = [77323, 2313, 4545, 323] + XCTAssertEqual(json["user", "id"], 987654) + XCTAssertEqual(json["user", "info", "name"], "tom") + XCTAssertEqual(json["user", "info", "email"], "tom@qq.com") + XCTAssertEqual(json["user", "feeds"], [77323, 2313, 4545, 323]) } } From d02ca810a338240bc10a67b8e471f0373d2be868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E5=B8=85?= Date: Mon, 20 Feb 2017 09:30:47 +0800 Subject: [PATCH 349/470] Fix a spelling mistake and simplify initialize methods invoking --- Tests/SwiftyJSONTests/NestedJSONTests.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/SwiftyJSONTests/NestedJSONTests.swift b/Tests/SwiftyJSONTests/NestedJSONTests.swift index 17305384..1e00903a 100644 --- a/Tests/SwiftyJSONTests/NestedJSONTests.swift +++ b/Tests/SwiftyJSONTests/NestedJSONTests.swift @@ -54,18 +54,18 @@ class NestedJSONTests: XCTestCase { XCTAssertEqual(json["c"]["aa"].string, "11") } - func testNextedJSON() { - let inner = JSON.init([ + func testNestedJSON() { + let inner = JSON([ "some_field": "1" + "2", ]) - let json = JSON.init([ + let json = JSON([ "outer_field": "1" + "2", "inner_json": inner ]) XCTAssertEqual(json["inner_json"], ["some_field": "12"]) let foo = "foo" - let json2 = JSON.init([ + let json2 = JSON([ "outer_field": foo, "inner_json": inner ]) From 3c1ab40abec704c1caf2484a4b288476c3add40a Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Mon, 20 Feb 2017 22:35:51 +0800 Subject: [PATCH 350/470] [Tests] Improve SwiftyJSON Mutability test cases --- SwiftyJSON.xcodeproj/project.pbxproj | 8 ++ Tests/SwiftyJSONTests/MutabilityTests.swift | 106 ++++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 Tests/SwiftyJSONTests/MutabilityTests.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 183662cd..0ca5df39 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -39,6 +39,9 @@ A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; A819C4A119E37FC600ADCC3D /* PrintableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C4A019E37FC600ADCC3D /* PrintableTests.swift */; }; A81CBA0B1BCF6B0200A649A2 /* Tests.json in Resources */ = {isa = PBXBuildFile; fileRef = A885D1DA19CFCFF0002FD4C3 /* Tests.json */; }; + A830A6951E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */; }; + A830A6961E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */; }; + A830A6971E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */; }; A8491E1E19CD6DAE00CCFAE6 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; A8580F791BCF5C5B00DA927B /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7236B4F61BAC14150020529B /* SwiftyJSON.framework */; }; A8580F801BCF69A000DA927B /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */; }; @@ -110,6 +113,7 @@ A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; + A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutabilityTests.swift; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; @@ -245,6 +249,7 @@ A87080E719E439DA00CDE086 /* NumberTests.swift */, A863BE2719EED46F0092A41F /* RawTests.swift */, A8B66C8B19E51D6500540692 /* DictionaryTests.swift */, + A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */, A8B66C8D19E52F4200540692 /* ArrayTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); @@ -562,6 +567,7 @@ A86BAA0E19EBC32B009EAAEB /* PerformanceTests.swift in Sources */, A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */, A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, + A830A6951E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */, A863BE2819EED46F0092A41F /* RawTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, @@ -600,6 +606,7 @@ 9C459F021A9103C1008C9A41 /* NumberTests.swift in Sources */, 9C459EFF1A9103C1008C9A41 /* RawRepresentableTests.swift in Sources */, 9C459EFA1A9103C1008C9A41 /* BaseTests.swift in Sources */, + A830A6961E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */, 9C459F041A9103C1008C9A41 /* DictionaryTests.swift in Sources */, 9C459EF91A9103C1008C9A41 /* PerformanceTests.swift in Sources */, 9C459EFE1A9103C1008C9A41 /* LiteralConvertibleTests.swift in Sources */, @@ -622,6 +629,7 @@ A8580F821BCF69A000DA927B /* SequenceTypeTests.swift in Sources */, A8580F831BCF69A000DA927B /* PrintableTests.swift in Sources */, A8580F841BCF69A000DA927B /* SubscriptTests.swift in Sources */, + A830A6971E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */, A8580F851BCF69A000DA927B /* LiteralConvertibleTests.swift in Sources */, A8580F861BCF69A000DA927B /* RawRepresentableTests.swift in Sources */, A8580F871BCF69A000DA927B /* ComparableTests.swift in Sources */, diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift new file mode 100644 index 00000000..a6a20310 --- /dev/null +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -0,0 +1,106 @@ +// DictionaryTests.swift +// +// Copyright (c) 2014 - 2017 Zigii Wong +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import XCTest +import SwiftyJSON + +class MutabilityTest: XCTestCase { + + func testDictionaryJSONMutability() { + let dictionary: [String: Any] = [ + "string": "STRING", + "number": 9823.212, + "bool": true, + "empty": ["nothing"] + ] + + var json = JSON(dictionary) + XCTAssertEqual(json["string"], "STRING") + XCTAssertEqual(json["number"], 9823.212) + XCTAssertEqual(json["bool"], true) + XCTAssertEqual(json["empty"], ["nothing"]) + + json["string"] = "muted" + XCTAssertEqual(json["string"], "muted") + + json["number"] = 9999.0 + XCTAssertEqual(json["number"], 9999.0) + + json["bool"] = false + XCTAssertEqual(json["bool"], false) + + json["empty"] = [] + XCTAssertEqual(json["empty"], []) + + json["new"] = JSON(["foo": "bar"]) + XCTAssertEqual(json["new"], ["foo": "bar"]) + } + + func testArrayJSONMutability() { + let array: [Any] = ["1", "2", 3, true, []] + + var json = JSON(array) + XCTAssertEqual(json[0], "1") + XCTAssertEqual(json[1], "2") + XCTAssertEqual(json[2], 3) + XCTAssertEqual(json[3], true) + XCTAssertEqual(json[4], []) + + json[0] = false + XCTAssertEqual(json[0], false) + + json[1] = 2 + XCTAssertEqual(json[1], 2) + + json[2] = "3" + XCTAssertEqual(json[2], "3") + + json[3] = [:] + XCTAssertEqual(json[3], [:]) + + json[4] = [1, 2] + XCTAssertEqual(json[4], [1, 2]) + } + + func testValueMutability() { + var intArray = JSON([0, 1, 2]) + intArray[0] = JSON(55) + XCTAssertEqual(intArray[0], 55) + XCTAssertEqual(intArray[0].intValue, 55) + + var dictionary = JSON(["foo": "bar"]) + dictionary["foo"] = JSON("foo") + XCTAssertEqual(dictionary["foo"], "foo") + XCTAssertEqual(dictionary["foo"].stringValue, "foo") + + var number = JSON(1) + number = JSON("111") + XCTAssertEqual(number, "111") + XCTAssertEqual(number.intValue, 111) + XCTAssertEqual(number.stringValue, "111") + + var boolean = JSON(true) + boolean = JSON(false) + XCTAssertEqual(boolean, false) + XCTAssertEqual(boolean.boolValue, false) + } +} From ddd18f423193aede05f0f2873b945695086d4d8e Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 21 Feb 2017 00:53:31 +0800 Subject: [PATCH 351/470] [SwiftLint] Satisfy operator_whitespace rule --- .swiftlint.yml | 1 - Source/SwiftyJSON.swift | 26 +++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 1a5ad564..689e2e3d 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -7,7 +7,6 @@ disabled_rules: - line_length - type_body_length - implicit_getter - - operator_whitespace - cyclomatic_complexity - function_body_length - control_statement diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 8cd2d86e..afecb213 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -286,7 +286,7 @@ public enum Index: Comparable { case dictionary(DictionaryIndex) case null - static public func ==(lhs: Index, rhs: Index) -> Bool { + static public func == (lhs: Index, rhs: Index) -> Bool { switch (lhs, rhs) { case (.array(let left), .array(let right)): return left == right @@ -298,7 +298,7 @@ public enum Index: Comparable { } } - static public func <(lhs: Index, rhs: Index) -> Bool { + static public func < (lhs: Index, rhs: Index) -> Bool { switch (lhs, rhs) { case (.array(let left), .array(let right)): return left < right @@ -1292,7 +1292,7 @@ extension JSON { // MARK: - Comparable extension JSON : Swift.Comparable {} -public func ==(lhs: JSON, rhs: JSON) -> Bool { +public func == (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.number, .number): @@ -1312,7 +1312,7 @@ public func ==(lhs: JSON, rhs: JSON) -> Bool { } } -public func <=(lhs: JSON, rhs: JSON) -> Bool { +public func <= (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.number, .number): @@ -1332,7 +1332,7 @@ public func <=(lhs: JSON, rhs: JSON) -> Bool { } } -public func >=(lhs: JSON, rhs: JSON) -> Bool { +public func >= (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.number, .number): @@ -1352,7 +1352,7 @@ public func >=(lhs: JSON, rhs: JSON) -> Bool { } } -public func >(lhs: JSON, rhs: JSON) -> Bool { +public func > (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.number, .number): @@ -1364,7 +1364,7 @@ public func >(lhs: JSON, rhs: JSON) -> Bool { } } -public func <(lhs: JSON, rhs: JSON) -> Bool { +public func < (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { case (.number, .number): @@ -1396,7 +1396,7 @@ extension NSNumber { } } -func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { +func == (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): return false @@ -1407,11 +1407,11 @@ func ==(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -func !=(lhs: NSNumber, rhs: NSNumber) -> Bool { +func != (lhs: NSNumber, rhs: NSNumber) -> Bool { return !(lhs == rhs) } -func <(lhs: NSNumber, rhs: NSNumber) -> Bool { +func < (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): @@ -1423,7 +1423,7 @@ func <(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -func >(lhs: NSNumber, rhs: NSNumber) -> Bool { +func > (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): @@ -1435,7 +1435,7 @@ func >(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { +func <= (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): @@ -1447,7 +1447,7 @@ func <=(lhs: NSNumber, rhs: NSNumber) -> Bool { } } -func >=(lhs: NSNumber, rhs: NSNumber) -> Bool { +func >= (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { case (false, true): From 831b47e0d50d7143a3db1e452be1572b4055b7b0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 21 Feb 2017 01:01:13 +0800 Subject: [PATCH 352/470] [SwiftLint] Satisfy implicit_getter rule --- .swiftlint.yml | 1 - Source/SwiftyJSON.swift | 34 ++++++++++++++-------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 689e2e3d..cfa450e5 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -6,7 +6,6 @@ disabled_rules: - file_length - line_length - type_body_length - - implicit_getter - cyclomatic_complexity - function_body_length - control_statement diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index afecb213..3155cc9a 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -270,15 +270,15 @@ public struct JSON { } /// JSON type - public var type: Type { get { return _type } } + public var type: Type { return _type } /// Error in JSON - public var error: NSError? { get { return self._error } } + public var error: NSError? { return self._error } /// The static null JSON @available(*, unavailable, renamed:"null") - public static var nullJSON: JSON { get { return null } } - public static var null: JSON { get { return JSON(NSNull()) } } + public static var nullJSON: JSON { return null } + public static var null: JSON { return JSON(NSNull()) } } public enum Index: Comparable { @@ -756,20 +756,16 @@ extension JSON { //Optional [JSON] public var array: [JSON]? { - get { - if self.type == .array { - return self.rawArray.map { JSON($0) } - } else { - return nil - } + if self.type == .array { + return self.rawArray.map { JSON($0) } + } else { + return nil } } //Non-optional [JSON] public var arrayValue: [JSON] { - get { - return self.array ?? [] - } + return self.array ?? [] } //Optional [Any] @@ -1385,13 +1381,11 @@ private let falseObjCType = String(cString: falseNumber.objCType) extension NSNumber { var isBool: Bool { - get { - let objCType = String(cString: self.objCType) - if (self.compare(trueNumber) == .orderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == .orderedSame && objCType == falseObjCType) { - return true - } else { - return false - } + let objCType = String(cString: self.objCType) + if (self.compare(trueNumber) == .orderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == .orderedSame && objCType == falseObjCType) { + return true + } else { + return false } } } From 024efa4e123d80d09e927c44eb51f8c34c5ef5b6 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 21 Feb 2017 01:03:34 +0800 Subject: [PATCH 353/470] [SwiftLint] Remove parentheses of conditional --- .swiftlint.yml | 1 - Source/SwiftyJSON.swift | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index cfa450e5..03003d1d 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -8,4 +8,3 @@ disabled_rules: - type_body_length - cyclomatic_complexity - function_body_length - - control_statement diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3155cc9a..b975501f 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -650,7 +650,7 @@ extension JSON: Swift.RawRepresentable { options: [writingOptionsKeys: Any], maxObjectDepth: Int = 10 ) throws -> String? { - if (maxObjectDepth < 0) { + if maxObjectDepth < 0 { throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Element too deep. Increase maxObjectDepth and make sure there is no reference loop"]) } switch self.type { From 8936353a9c17b64e37ee72ac088dc8139ab33a3d Mon Sep 17 00:00:00 2001 From: Jobins John Date: Wed, 22 Feb 2017 09:32:49 +0400 Subject: [PATCH 354/470] Updated Year in License File --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 916a0acd..68e3fd74 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Ruoyu Fu +Copyright (c) 2017 Ruoyu Fu Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 0e986772b1888181e54f60dae44090bb7947a0eb Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 22 Feb 2017 23:51:03 +0800 Subject: [PATCH 355/470] Add github ISSUE and PULL_REQUEST TEMPLATE --- ISSUE_TEMPLATE | 33 +++++++++++++++++++++++++++++++++ PULL_REQUEST_TEMPLATE | 13 +++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 ISSUE_TEMPLATE create mode 100644 PULL_REQUEST_TEMPLATE diff --git a/ISSUE_TEMPLATE b/ISSUE_TEMPLATE new file mode 100644 index 00000000..eb2ba192 --- /dev/null +++ b/ISSUE_TEMPLATE @@ -0,0 +1,33 @@ +### What did you do? + +Please replace this with what you did. + +### What did you expect to happen? + +Please replace this with what you expected to happen. + +### What actually happened instead? + +Please replace this with what happened instead. + +### Environment + +List the software versions you're using: + + - SwiftyJSON: *?.?.?* + - Xcode Version: *?.? (????)* (Open Xcode; In menubar: Xcode > About Xcode) + - Swift Version: *?.?* (Open Xcode Preferences; Components > Toolchains. If none, use `Xcode Default`.) + +Please also mention which package manager you used and its version. Delete the +other package managers in this list: + + - Cocoapods: *?.?.?* (Use `pod --version` in Terminal) + - Carthage: *?.?* (Use `carthage version` in Terminal) + - Swift Package Manager *?.?.? (swiftpm-???)* (Use `swift build --version` in Terminal) + +### Project that demonstrates the issue + +Please link to a project we can download that reproduces the issue. Feel free +to delete this section if it's not relevant to the issue (eg - feature request). + +The project should be [short, self-contained, and correct example](http://sscce.org/). \ No newline at end of file diff --git a/PULL_REQUEST_TEMPLATE b/PULL_REQUEST_TEMPLATE new file mode 100644 index 00000000..5efff141 --- /dev/null +++ b/PULL_REQUEST_TEMPLATE @@ -0,0 +1,13 @@ +The PR should summarize what was changed and why. Here are some questions to +help you if you're not sure: + + - What behavior was changed? + - What code was refactored / updated to support this change? + - What issues are related to this PR? Or why was this change introduced? + +Checklist - While not every PR needs it, new features should consider this list: + + - [ ] Does this have tests? + - [ ] Does this have documentation? + - [ ] Does this break the public API (Requires major version bump)? + - [ ] Is this a new feature (Requires minor version bump)? \ No newline at end of file From cc071b333729c06687277d51a469824c2ca785d9 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Thu, 23 Feb 2017 21:54:34 +0800 Subject: [PATCH 356/470] Move files into .github directory --- ISSUE_TEMPLATE => .github/ISSUE_TEMPLATE | 0 PULL_REQUEST_TEMPLATE => .github/PULL_REQUEST_TEMPLATE | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename ISSUE_TEMPLATE => .github/ISSUE_TEMPLATE (100%) rename PULL_REQUEST_TEMPLATE => .github/PULL_REQUEST_TEMPLATE (100%) diff --git a/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE similarity index 100% rename from ISSUE_TEMPLATE rename to .github/ISSUE_TEMPLATE diff --git a/PULL_REQUEST_TEMPLATE b/.github/PULL_REQUEST_TEMPLATE similarity index 100% rename from PULL_REQUEST_TEMPLATE rename to .github/PULL_REQUEST_TEMPLATE From 0417977cead785f51054da08dfca970a303623da Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Sat, 25 Feb 2017 02:01:57 +0800 Subject: [PATCH 357/470] [SwiftLint] Corrected Trailing Whitespace --- Example/Example/ViewController.swift | 2 +- Source/SwiftyJSON.swift | 2 +- Tests/SwiftyJSONTests/MutabilityTests.swift | 36 ++++++++++----------- Tests/SwiftyJSONTests/NestedJSONTests.swift | 12 +++---- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index ecca7acb..12a05290 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -32,7 +32,7 @@ class ViewController: UITableViewController { override func viewDidLoad() { self.title = "SwiftyJSON(\(json.type))" } - + override func numberOfSections(in tableView: UITableView) -> Int { return 1 } diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a17db1e3..f5e16e47 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -531,7 +531,7 @@ extension JSON: Swift.ExpressibleByFloatLiteral { extension JSON: Swift.ExpressibleByDictionaryLiteral { public init(dictionaryLiteral elements: (String, Any)...) { - var dictionary = [String : Any](minimumCapacity: elements.count) + var dictionary = [String: Any](minimumCapacity: elements.count) for (k, v) in elements { dictionary[k] = v } diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift index a6a20310..6a48cf79 100644 --- a/Tests/SwiftyJSONTests/MutabilityTests.swift +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -24,7 +24,7 @@ import XCTest import SwiftyJSON class MutabilityTest: XCTestCase { - + func testDictionaryJSONMutability() { let dictionary: [String: Any] = [ "string": "STRING", @@ -32,72 +32,72 @@ class MutabilityTest: XCTestCase { "bool": true, "empty": ["nothing"] ] - + var json = JSON(dictionary) XCTAssertEqual(json["string"], "STRING") XCTAssertEqual(json["number"], 9823.212) XCTAssertEqual(json["bool"], true) XCTAssertEqual(json["empty"], ["nothing"]) - + json["string"] = "muted" XCTAssertEqual(json["string"], "muted") - + json["number"] = 9999.0 XCTAssertEqual(json["number"], 9999.0) - + json["bool"] = false XCTAssertEqual(json["bool"], false) - + json["empty"] = [] XCTAssertEqual(json["empty"], []) - + json["new"] = JSON(["foo": "bar"]) XCTAssertEqual(json["new"], ["foo": "bar"]) } - + func testArrayJSONMutability() { let array: [Any] = ["1", "2", 3, true, []] - + var json = JSON(array) XCTAssertEqual(json[0], "1") XCTAssertEqual(json[1], "2") XCTAssertEqual(json[2], 3) XCTAssertEqual(json[3], true) XCTAssertEqual(json[4], []) - + json[0] = false XCTAssertEqual(json[0], false) - + json[1] = 2 XCTAssertEqual(json[1], 2) - + json[2] = "3" XCTAssertEqual(json[2], "3") - + json[3] = [:] XCTAssertEqual(json[3], [:]) - + json[4] = [1, 2] XCTAssertEqual(json[4], [1, 2]) } - + func testValueMutability() { var intArray = JSON([0, 1, 2]) intArray[0] = JSON(55) XCTAssertEqual(intArray[0], 55) XCTAssertEqual(intArray[0].intValue, 55) - + var dictionary = JSON(["foo": "bar"]) dictionary["foo"] = JSON("foo") XCTAssertEqual(dictionary["foo"], "foo") XCTAssertEqual(dictionary["foo"].stringValue, "foo") - + var number = JSON(1) number = JSON("111") XCTAssertEqual(number, "111") XCTAssertEqual(number.intValue, 111) XCTAssertEqual(number.stringValue, "111") - + var boolean = JSON(true) boolean = JSON(false) XCTAssertEqual(boolean, false) diff --git a/Tests/SwiftyJSONTests/NestedJSONTests.swift b/Tests/SwiftyJSONTests/NestedJSONTests.swift index b861c5a0..18bac5ef 100644 --- a/Tests/SwiftyJSONTests/NestedJSONTests.swift +++ b/Tests/SwiftyJSONTests/NestedJSONTests.swift @@ -39,31 +39,31 @@ class NestedJSONTests: XCTestCase { ] XCTAssertNotNil(try? nestedFamily.rawData()) } - + func testArrayJSON() { let arr: [JSON] = ["a", 1, ["b", 2]] let json = JSON(arr) XCTAssertEqual(json[0].string, "a") - XCTAssertEqual(json[2,1].int, 2) + XCTAssertEqual(json[2, 1].int, 2) } - + func testDictionaryJSON() { let json: JSON = ["a": JSON("1"), "b": JSON([1, 2, "3"]), "c": JSON(["aa": "11", "bb": 22])] XCTAssertEqual(json["a"].string, "1") XCTAssertEqual(json["b"].array!, [1, 2, "3"]) XCTAssertEqual(json["c"]["aa"].string, "11") } - + func testNestedJSON() { let inner = JSON([ - "some_field": "1" + "2", + "some_field": "1" + "2" ]) let json = JSON([ "outer_field": "1" + "2", "inner_json": inner ]) XCTAssertEqual(json["inner_json"], ["some_field": "12"]) - + let foo = "foo" let json2 = JSON([ "outer_field": foo, From 41f547272db2afef4def3d441d9670f49e23f637 Mon Sep 17 00:00:00 2001 From: Simon Strandgaard Date: Sun, 26 Feb 2017 13:26:33 +0000 Subject: [PATCH 358/470] RawTests.testNestedJSON() added --- Tests/SwiftyJSONTests/RawTests.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift index faa043a1..80068e38 100644 --- a/Tests/SwiftyJSONTests/RawTests.swift +++ b/Tests/SwiftyJSONTests/RawTests.swift @@ -92,4 +92,18 @@ class RawTests: XCTestCase { let json: JSON = JSON.null XCTAssertEqual(json.rawString(), "null") } + + func testNestedJSON() { + let inner: JSON = ["name": "john doe"] + let json: JSON = ["level": 1337, "user": inner] + let data: Data? + do { + data = try json.rawData() + } catch _ { + data = nil + } + let string = json.rawString() + XCTAssertNotNil(data) + XCTAssertNotNil(string) + } } From 71cae94f2ae3900369d0c760710bbc332614ac90 Mon Sep 17 00:00:00 2001 From: Simon Strandgaard Date: Sun, 26 Feb 2017 13:41:30 +0000 Subject: [PATCH 359/470] Converted tabs to spaces --- Tests/SwiftyJSONTests/RawTests.swift | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift index 80068e38..e30de39d 100644 --- a/Tests/SwiftyJSONTests/RawTests.swift +++ b/Tests/SwiftyJSONTests/RawTests.swift @@ -92,18 +92,18 @@ class RawTests: XCTestCase { let json: JSON = JSON.null XCTAssertEqual(json.rawString(), "null") } - - func testNestedJSON() { - let inner: JSON = ["name": "john doe"] - let json: JSON = ["level": 1337, "user": inner] - let data: Data? - do { - data = try json.rawData() - } catch _ { - data = nil - } - let string = json.rawString() - XCTAssertNotNil(data) - XCTAssertNotNil(string) - } + + func testNestedJSON() { + let inner: JSON = ["name": "john doe"] + let json: JSON = ["level": 1337, "user": inner] + let data: Data? + do { + data = try json.rawData() + } catch _ { + data = nil + } + let string = json.rawString() + XCTAssertNotNil(data) + XCTAssertNotNil(string) + } } From de70760ff5c065a4397e5429e162398a1ab2db66 Mon Sep 17 00:00:00 2001 From: Michel Tabari Date: Tue, 4 Apr 2017 15:45:53 +0200 Subject: [PATCH 360/470] Fix spelling mistake --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f5e16e47..fc6f6afd 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -184,7 +184,7 @@ public struct JSON { fileprivate var rawBool: Bool = false /// Private type fileprivate var _type: Type = .null - /// prviate error + /// Private error fileprivate var _error: NSError? /// Object in JSON From d106438eb21345a526c840340ec62594f64484e0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Sun, 16 Apr 2017 17:06:31 +0800 Subject: [PATCH 361/470] [SwiftLint] Prefer `!= nil` over `let _` --- Source/SwiftyJSON.swift | 2 +- Tests/SwiftyJSONTests/BaseTests.swift | 4 ++-- Tests/SwiftyJSONTests/RawRepresentableTests.swift | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index fc6f6afd..1cf847c5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -951,7 +951,7 @@ extension JSON { switch self.type { case .string: // Check for existing percent escapes first to prevent double-escaping of % character - if let _ = self.rawString.range(of: "%[0-9A-Fa-f]{2}", options: .regularExpression, range: nil, locale: nil) { + if self.rawString.range(of: "%[0-9A-Fa-f]{2}", options: .regularExpression, range: nil, locale: nil) != nil { return Foundation.URL(string: self.rawString) } else if let encodedString_ = self.rawString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { // We have to use `Foundation.URL` otherwise it conflicts with the variable name. diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 80bb9893..81e05697 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -226,13 +226,13 @@ class BaseTests: XCTestCase { func testErrorHandle() { let json = JSON(data:self.testData) - if let _ = json["wrong-type"].string { + if json["wrong-type"].string != nil { XCTFail("Should not run into here") } else { XCTAssertEqual(json["wrong-type"].error!.code, SwiftyJSON.ErrorWrongType) } - if let _ = json[0]["not-exist"].string { + if json[0]["not-exist"].string != nil { XCTFail("Should not run into here") } else { XCTAssertEqual(json[0]["not-exist"].error!.code, SwiftyJSON.ErrorNotExist) diff --git a/Tests/SwiftyJSONTests/RawRepresentableTests.swift b/Tests/SwiftyJSONTests/RawRepresentableTests.swift index 1482a05b..7a122990 100644 --- a/Tests/SwiftyJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftyJSONTests/RawRepresentableTests.swift @@ -77,7 +77,7 @@ class RawRepresentableTests: XCTestCase { } func testNil() { - if let _ = JSON(rawValue: NSObject()) { + if JSON(rawValue: NSObject()) != nil { XCTFail("Should not run into here") } } From 06477da6d9b302389f68ff3e35d6863fbdc3cc52 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Sun, 16 Apr 2017 20:00:07 +0800 Subject: [PATCH 362/470] [SwiftLint] Compress swiftlint violations --- Source/SwiftyJSON.swift | 2 +- Tests/SwiftyJSONTests/BaseTests.swift | 5 ++--- Tests/SwiftyJSONTests/PerformanceTests.swift | 9 ++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 01010b39..5f2b7527 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -110,7 +110,7 @@ public struct JSON { @available(*, deprecated: 3.2, message: "Use instead `init(parseJSON: )`") public static func parse(_ json: String) -> JSON { return json.data(using: String.Encoding.utf8) - .flatMap{ try? JSON(data: $0) } ?? JSON(NSNull()) + .flatMap { try? JSON(data: $0) } ?? JSON(NSNull()) } /** diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index aa2524c8..98f6c0c7 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -236,7 +236,7 @@ class BaseTests: XCTestCase { XCTFail("Unable to parse testData") return } - if let _ = json["wrong-type"].string { + if json["wrong-type"].string != nil { XCTFail("Should not run into here") } else { XCTAssertEqual(json["wrong-type"].error!.code, SwiftyJSON.ErrorWrongType) @@ -276,9 +276,8 @@ class BaseTests: XCTestCase { func testErrorThrowing() { let invalidJson = "{\"foo\": 300]" // deliberately incorrect JSON let invalidData = invalidJson.data(using: .utf8)! - do { - let _ = try JSON(data: invalidData) + _ = try JSON(data: invalidData) XCTFail("Should have thrown error; we should not have gotten here") } catch { // everything is OK diff --git a/Tests/SwiftyJSONTests/PerformanceTests.swift b/Tests/SwiftyJSONTests/PerformanceTests.swift index 500c1f6f..72140b54 100644 --- a/Tests/SwiftyJSONTests/PerformanceTests.swift +++ b/Tests/SwiftyJSONTests/PerformanceTests.swift @@ -59,7 +59,7 @@ class PerformanceTests: XCTestCase { XCTFail("Unable to parse testData") return } - self.measure() { + self.measure { for _ in 1...100 { let object:Any? = json.object XCTAssertTrue(object != nil) @@ -72,7 +72,7 @@ class PerformanceTests: XCTestCase { XCTFail("Unable to parse testData") return } - self.measure() { + self.measure { for _ in 1...100 { autoreleasepool { if let array = json.array { @@ -88,8 +88,7 @@ class PerformanceTests: XCTestCase { XCTFail("Unable to parse testData") return } - - self.measure() { + self.measure { for _ in 1...100 { autoreleasepool { if let dictionary = json.dictionary { @@ -105,7 +104,7 @@ class PerformanceTests: XCTestCase { XCTFail("Unable to parse testData") return } - self.measure() { + self.measure { for _ in 1...100 { autoreleasepool { let string = json.rawString() From acbe2412dc58f79fe49b13cdcffceeae49e3bd4f Mon Sep 17 00:00:00 2001 From: JackSteven Date: Thu, 20 Apr 2017 14:51:50 +0800 Subject: [PATCH 363/470] call can throw but is not marked with try Hello, I See JSON(data: data) has throws exception, so add 'try' in front, the error "call can throw but is not marked with try" can fixed. public init(data: Data, options opt: JSONSerialization.ReadingOptions = []) throws { } --- Example/Example/AppDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index f0e91456..4e1880b0 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { if let file = Bundle.main.path(forResource: "SwiftyJSONTests", ofType: "json") { do { let data = try Data(contentsOf: URL(fileURLWithPath: file)) - let json = JSON(data: data) + let json = try JSON(data: data) viewController.json = json } catch { viewController.json = JSON.null From 083c6d7c42222846348dd5322ba01186adabf431 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Sat, 22 Apr 2017 15:46:11 +0800 Subject: [PATCH 364/470] Moving from NSError to Swift.Error --- Source/SwiftyJSON.swift | 78 +++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 23 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5f2b7527..d79e1c73 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -25,15 +25,54 @@ import Foundation // MARK: - Error ///Error domain +@available(*, deprecated, message: "Use the `SwiftyJSONError.errorDomain` instead") public let ErrorDomain: String = "SwiftyJSONErrorDomain" ///Error code +@available(*, deprecated, message: "Use the `SwiftyJSONError.unsupportedType` instead") public let ErrorUnsupportedType: Int = 999 +@available(*, deprecated, message: "Use the `SwiftyJSONError.indexOutOfBounds` instead") public let ErrorIndexOutOfBounds: Int = 900 +@available(*, deprecated, message: "Use the `SwiftyJSONError.wrongType` instead") public let ErrorWrongType: Int = 901 +@available(*, deprecated, message: "Use the `SwiftyJSONError.notExist` instead") public let ErrorNotExist: Int = 500 +@available(*, deprecated, message: "Use the `SwiftyJSONError.invalidJSON` instead") public let ErrorInvalidJSON: Int = 490 +public enum SwiftyJSONError: Int, Swift.Error { + case unsupportedType = 999 + case indexOutOfBounds = 900 + case elementTooDeep = 902 + case wrongType = 901 + case notExist = 500 + case invalidJSON = 490 +} + +extension SwiftyJSONError: CustomNSError { + + public static var errorDomain: String { return "com.swiftyjson.SwiftyJSON" } + + public var errorCode: Int { return self.rawValue } + + public var errorUserInfo: [String : String] { + switch self { + case .unsupportedType: + return [NSLocalizedDescriptionKey: "It is a unsupported type."] + case .indexOutOfBounds: + return [NSLocalizedDescriptionKey: "Array Index is out of bounds."] + case .wrongType: + return [NSLocalizedDescriptionKey: "Couldn't merge, because the JSONs differ in type on top level."] + case .notExist: + return [NSLocalizedDescriptionKey: "Dictionary key does not exist."] + case .invalidJSON: + return [NSLocalizedDescriptionKey: "JSON is invalid."] + case .elementTooDeep: + return [NSLocalizedDescriptionKey: "Element too deep. Increase maxObjectDepth and make sure there is no reference loop."] + } + } +} + // MARK: - JSON Type /** @@ -60,7 +99,6 @@ public struct JSON { - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - parameter opt: The JSON serialization reading options. `[]` by default. - - parameter error: The NSErrorPointer used to return the error. `nil` by default. - returns: The created JSON */ @@ -107,7 +145,7 @@ public struct JSON { - returns: The created JSON */ - @available(*, deprecated: 3.2, message: "Use instead `init(parseJSON: )`") + @available(*, deprecated, message: "Use instead `init(parseJSON: )`") public static func parse(_ json: String) -> JSON { return json.data(using: String.Encoding.utf8) .flatMap { try? JSON(data: $0) } ?? JSON(NSNull()) @@ -165,7 +203,7 @@ public struct JSON { } } else { if typecheck { - throw NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Couldn't merge, because the JSONs differ in type on top level."]) + throw SwiftyJSONError.wrongType } else { self = other } @@ -182,7 +220,7 @@ public struct JSON { /// Private type fileprivate var _type: Type = .null /// Private error - fileprivate var _error: NSError? + fileprivate var _error: SwiftyJSONError? /// Object in JSON public var object: Any { @@ -228,7 +266,7 @@ public struct JSON { self.rawDictionary = dictionary default: _type = .unknown - _error = NSError(domain: ErrorDomain, code: ErrorUnsupportedType, userInfo: [NSLocalizedDescriptionKey: "It is a unsupported type"]) + _error = .unsupportedType } } } @@ -237,7 +275,7 @@ public struct JSON { public var type: Type { return _type } /// Error in JSON - public var error: NSError? { return self._error } + public var error: SwiftyJSONError? { return _error } /// The static null JSON @available(*, unavailable, renamed:"null") @@ -378,13 +416,13 @@ extension JSON { get { if self.type != .array { var r = JSON.null - r._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] failure, It is not an array"]) + r._error = self._error ?? SwiftyJSONError.wrongType return r } else if index >= 0 && index < self.rawArray.count { return JSON(self.rawArray[index]) } else { var r = JSON.null - r._error = NSError(domain: ErrorDomain, code:ErrorIndexOutOfBounds, userInfo: [NSLocalizedDescriptionKey: "Array[\(index)] is out of bounds"]) + r._error = SwiftyJSONError.indexOutOfBounds return r } } @@ -405,10 +443,10 @@ extension JSON { if let o = self.rawDictionary[key] { r = JSON(o) } else { - r._error = NSError(domain: ErrorDomain, code: ErrorNotExist, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] does not exist"]) + r._error = SwiftyJSONError.notExist } } else { - r._error = self._error ?? NSError(domain: ErrorDomain, code: ErrorWrongType, userInfo: [NSLocalizedDescriptionKey: "Dictionary[\"\(key)\"] failure, It is not an dictionary"]) + r._error = self._error ?? SwiftyJSONError.wrongType } return r } @@ -569,7 +607,7 @@ extension JSON: Swift.RawRepresentable { public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data { guard JSONSerialization.isValidJSONObject(self.object) else { - throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "JSON is invalid"]) + throw SwiftyJSONError.invalidJSON } return try JSONSerialization.data(withJSONObject: self.object, options: opt) @@ -595,13 +633,9 @@ extension JSON: Swift.RawRepresentable { } } - fileprivate func _rawString( - _ encoding: String.Encoding = .utf8, - options: [writingOptionsKeys: Any], - maxObjectDepth: Int = 10 - ) throws -> String? { + fileprivate func _rawString(_ encoding: String.Encoding = .utf8, options: [writingOptionsKeys: Any], maxObjectDepth: Int = 10) throws -> String? { if maxObjectDepth < 0 { - throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Element too deep. Increase maxObjectDepth and make sure there is no reference loop"]) + throw SwiftyJSONError.invalidJSON } switch self.type { case .dictionary: @@ -625,7 +659,7 @@ extension JSON: Swift.RawRepresentable { let nestedValue = JSON(unwrappedValue) guard let nestedString = try nestedValue._rawString(encoding, options: options, maxObjectDepth: maxObjectDepth - 1) else { - throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) + throw SwiftyJSONError.elementTooDeep } if nestedValue.type == .string { return "\"\(key)\": \"\(nestedString.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\""))\"" @@ -656,7 +690,7 @@ extension JSON: Swift.RawRepresentable { let nestedValue = JSON(unwrappedValue) guard let nestedString = try nestedValue._rawString(encoding, options: options, maxObjectDepth: maxObjectDepth - 1) else { - throw NSError(domain: ErrorDomain, code: ErrorInvalidJSON, userInfo: [NSLocalizedDescriptionKey: "Could not serialize nested JSON"]) + throw SwiftyJSONError.invalidJSON } if nestedValue.type == .string { return "\"\(nestedString.replacingOccurrences(of: "\\", with: "\\\\").replacingOccurrences(of: "\"", with: "\\\""))\"" @@ -930,10 +964,8 @@ extension JSON { } } public func exists() -> Bool { - if let errorValue = error, errorValue.code == ErrorNotExist || - errorValue.code == ErrorIndexOutOfBounds || - errorValue.code == ErrorWrongType { - return false + if let errorValue = error, (400...1000).contains(errorValue.errorCode) { + return false } return true } From d3ae7a1bd16bac12fb81c6ddb1503311335fe9eb Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Sat, 22 Apr 2017 15:47:26 +0800 Subject: [PATCH 365/470] Fix failure testcases --- Source/SwiftyJSON.swift | 2 +- Tests/SwiftyJSONTests/BaseTests.swift | 6 ++-- Tests/SwiftyJSONTests/MergeTests.swift | 12 +++---- Tests/SwiftyJSONTests/RawTests.swift | 6 ++-- Tests/SwiftyJSONTests/SubscriptTests.swift | 38 +++++++++++----------- 5 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index d79e1c73..3243cfd1 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -55,7 +55,7 @@ extension SwiftyJSONError: CustomNSError { public var errorCode: Int { return self.rawValue } - public var errorUserInfo: [String : String] { + public var errorUserInfo: [String : Any] { switch self { case .unsupportedType: return [NSLocalizedDescriptionKey: "It is a unsupported type."] diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 98f6c0c7..616ea020 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -239,18 +239,18 @@ class BaseTests: XCTestCase { if json["wrong-type"].string != nil { XCTFail("Should not run into here") } else { - XCTAssertEqual(json["wrong-type"].error!.code, SwiftyJSON.ErrorWrongType) + XCTAssertEqual(json["wrong-type"].error, SwiftyJSONError.wrongType) } if json[0]["not-exist"].string != nil { XCTFail("Should not run into here") } else { - XCTAssertEqual(json[0]["not-exist"].error!.code, SwiftyJSON.ErrorNotExist) + XCTAssertEqual(json[0]["not-exist"].error, SwiftyJSONError.notExist) } let wrongJSON = JSON(NSObject()) if let error = wrongJSON.error { - XCTAssertEqual(error.code, SwiftyJSON.ErrorUnsupportedType) + XCTAssertEqual(error, SwiftyJSONError.unsupportedType) } } diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift index dbee6a35..4d1d8c09 100644 --- a/Tests/SwiftyJSONTests/MergeTests.swift +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -33,13 +33,11 @@ class JSONTests: XCTestCase { do { _ = try A.merged(with: B) XCTFail() - } catch (let error) { - let error = error as NSError - XCTAssertEqual(error.code, ErrorWrongType) - XCTAssertEqual(error.domain, ErrorDomain) - XCTAssertEqual(error.userInfo[NSLocalizedDescriptionKey] as! String, - "Couldn't merge, because the JSONs differ in type on top level.") - } + } catch let error as SwiftyJSONError { + XCTAssertEqual(error.errorCode, SwiftyJSONError.wrongType.rawValue) + XCTAssertEqual(type(of: error).errorDomain, SwiftyJSONError.errorDomain) + XCTAssertEqual(error.errorUserInfo as! [String: String], [NSLocalizedDescriptionKey: "Couldn't merge, because the JSONs differ in type on top level."]) + } catch _ {} } func testPrimitiveType() { diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift index e30de39d..b104e1c5 100644 --- a/Tests/SwiftyJSONTests/RawTests.swift +++ b/Tests/SwiftyJSONTests/RawTests.swift @@ -40,9 +40,9 @@ class RawTests: XCTestCase { let json: JSON = "...xyz" do { _ = try json.rawData() - } catch let error as NSError { - XCTAssertEqual(error.code, ErrorInvalidJSON) - } + } catch let error as SwiftyJSONError { + XCTAssertEqual(error, SwiftyJSONError.invalidJSON) + } catch _ {} } func testArray() { diff --git a/Tests/SwiftyJSONTests/SubscriptTests.swift b/Tests/SwiftyJSONTests/SubscriptTests.swift index 7c71a941..78e6c075 100644 --- a/Tests/SwiftyJSONTests/SubscriptTests.swift +++ b/Tests/SwiftyJSONTests/SubscriptTests.swift @@ -180,37 +180,37 @@ class SubscriptTests: XCTestCase { func testOutOfBounds() { let json: JSON = JSON ([[NSNumber(value:1), NSNumber(value:2.123456), NSNumber(value:123456789)], ["aa", "bbb", "cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertEqual(json[9], JSON.null) - XCTAssertEqual(json[-2].error!.code, ErrorIndexOutOfBounds) - XCTAssertEqual(json[6].error!.code, ErrorIndexOutOfBounds) + XCTAssertEqual(json[-2].error, SwiftyJSONError.indexOutOfBounds) + XCTAssertEqual(json[6].error, SwiftyJSONError.indexOutOfBounds) XCTAssertEqual(json[9][8], JSON.null) - XCTAssertEqual(json[8][7].error!.code, ErrorIndexOutOfBounds) - XCTAssertEqual(json[8, 7].error!.code, ErrorIndexOutOfBounds) - XCTAssertEqual(json[999].error!.code, ErrorIndexOutOfBounds) + XCTAssertEqual(json[8][7].error, SwiftyJSONError.indexOutOfBounds) + XCTAssertEqual(json[8, 7].error, SwiftyJSONError.indexOutOfBounds) + XCTAssertEqual(json[999].error, SwiftyJSONError.indexOutOfBounds) } func testErrorWrongType() { let json = JSON(12345) XCTAssertEqual(json[9], JSON.null) - XCTAssertEqual(json[9].error!.code, ErrorWrongType) - XCTAssertEqual(json[8][7].error!.code, ErrorWrongType) + XCTAssertEqual(json[9].error, SwiftyJSONError.wrongType) + XCTAssertEqual(json[8][7].error, SwiftyJSONError.wrongType) XCTAssertEqual(json["name"], JSON.null) - XCTAssertEqual(json["name"].error!.code, ErrorWrongType) - XCTAssertEqual(json[0]["name"].error!.code, ErrorWrongType) - XCTAssertEqual(json["type"]["name"].error!.code, ErrorWrongType) - XCTAssertEqual(json["name"][99].error!.code, ErrorWrongType) - XCTAssertEqual(json[1, "Value"].error!.code, ErrorWrongType) - XCTAssertEqual(json[1, 2, "Value"].error!.code, ErrorWrongType) - XCTAssertEqual(json[[1, 2, "Value"]].error!.code, ErrorWrongType) + XCTAssertEqual(json["name"].error, SwiftyJSONError.wrongType) + XCTAssertEqual(json[0]["name"].error, SwiftyJSONError.wrongType) + XCTAssertEqual(json["type"]["name"].error, SwiftyJSONError.wrongType) + XCTAssertEqual(json["name"][99].error, SwiftyJSONError.wrongType) + XCTAssertEqual(json[1, "Value"].error, SwiftyJSONError.wrongType) + XCTAssertEqual(json[1, 2, "Value"].error, SwiftyJSONError.wrongType) + XCTAssertEqual(json[[1, 2, "Value"]].error, SwiftyJSONError.wrongType) } func testErrorNotExist() { let json: JSON = ["name": "NAME", "age": 15] XCTAssertEqual(json["Type"], JSON.null) - XCTAssertEqual(json["Type"].error!.code, ErrorNotExist) - XCTAssertEqual(json["Type"][1].error!.code, ErrorNotExist) - XCTAssertEqual(json["Type", 1].error!.code, ErrorNotExist) - XCTAssertEqual(json["Type"]["Value"].error!.code, ErrorNotExist) - XCTAssertEqual(json["Type", "Value"].error!.code, ErrorNotExist) + XCTAssertEqual(json["Type"].error, SwiftyJSONError.notExist) + XCTAssertEqual(json["Type"][1].error, SwiftyJSONError.notExist) + XCTAssertEqual(json["Type", 1].error, SwiftyJSONError.notExist) + XCTAssertEqual(json["Type"]["Value"].error, SwiftyJSONError.notExist) + XCTAssertEqual(json["Type", "Value"].error, SwiftyJSONError.notExist) } func testMultilevelGetter() { From 0bf454603f31554a66e0cabb28d1d03eb8fd754c Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 3 May 2017 22:15:59 +0800 Subject: [PATCH 366/470] Added SwiftyJSONError namespace --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3243cfd1..9e5e358d 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -266,7 +266,7 @@ public struct JSON { self.rawDictionary = dictionary default: _type = .unknown - _error = .unsupportedType + _error = SwiftyJSONError.unsupportedType } } } From 74c3f1c96aadaa597b42bfd108eb02d0af409434 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 3 May 2017 22:29:13 +0800 Subject: [PATCH 367/470] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c462346..3dd74189 100644 --- a/README.md +++ b/README.md @@ -213,11 +213,18 @@ for (index,subJson):(String, JSON) in json { #### Error +##### SwiftyJSON 4.x + +SwiftyJSON 4.x introduces an enum type called `SwiftyJSONError`, which includes `unsupportedType`, `indexOutOfBounds`, `elementTooDeep`, `wrongType`, `notExist` and `invalidJSON`, at the same time, `ErrorDomain` are being replaced by `SwiftyJSONError.errorDomain`. +Note: Those old error types are deprecated in SwiftyJSON 4.x and will be removed in the future release. + +##### SwiftyJSON 3.x + Use a subscript to get/set a value in an Array or Dictionary If the JSON is: * an array, the app may crash with "index out-of-bounds." -* a dictionary, it will be assigned `nil` without a reason. +* a dictionary, it will be assigned to `nil` without a reason. * not an array or a dictionary, the app may crash with an "unrecognised selector" exception. This will never happen in SwiftyJSON. From f261e70e942404ed6675f83b35799b884d42ad06 Mon Sep 17 00:00:00 2001 From: Nonchalant Date: Wed, 17 May 2017 20:34:47 +0900 Subject: [PATCH 368/470] Fix comma-spacing on version string. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3dd74189..814f68c9 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ let package = Package( name: "YOUR_PROJECT_NAME", targets: [], dependencies: [ - .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", versions: Version(1,0,0).. Date: Thu, 25 May 2017 15:26:46 +1200 Subject: [PATCH 369/470] =?UTF-8?q?Declare=20JSON=E2=80=99s=20type=20and?= =?UTF-8?q?=20error=20in=20a=20concise=20way.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SwiftyJSON.swift | 44 +++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 9e5e358d..a0121c99 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -217,10 +217,12 @@ public struct JSON { fileprivate var rawNumber: NSNumber = 0 fileprivate var rawNull: NSNull = NSNull() fileprivate var rawBool: Bool = false - /// Private type - fileprivate var _type: Type = .null - /// Private error - fileprivate var _error: SwiftyJSONError? + + /// JSON type, fileprivate setter + public fileprivate(set) var type: Type = .null + + /// Error in JSON, fileprivate setter + public fileprivate(set) var error: SwiftyJSONError? /// Object in JSON public var object: Any { @@ -241,42 +243,36 @@ public struct JSON { } } set { - _error = nil + error = nil switch unwrap(newValue) { case let number as NSNumber: if number.isBool { - _type = .bool + type = .bool self.rawBool = number.boolValue } else { - _type = .number + type = .number self.rawNumber = number } case let string as String: - _type = .string + type = .string self.rawString = string case _ as NSNull: - _type = .null + type = .null case nil: - _type = .null + type = .null case let array as [Any]: - _type = .array + type = .array self.rawArray = array case let dictionary as [String : Any]: - _type = .dictionary + type = .dictionary self.rawDictionary = dictionary default: - _type = .unknown - _error = SwiftyJSONError.unsupportedType + type = .unknown + error = SwiftyJSONError.unsupportedType } } } - /// JSON type - public var type: Type { return _type } - - /// Error in JSON - public var error: SwiftyJSONError? { return _error } - /// The static null JSON @available(*, unavailable, renamed:"null") public static var nullJSON: JSON { return null } @@ -416,13 +412,13 @@ extension JSON { get { if self.type != .array { var r = JSON.null - r._error = self._error ?? SwiftyJSONError.wrongType + r.error = self.error ?? SwiftyJSONError.wrongType return r } else if index >= 0 && index < self.rawArray.count { return JSON(self.rawArray[index]) } else { var r = JSON.null - r._error = SwiftyJSONError.indexOutOfBounds + r.error = SwiftyJSONError.indexOutOfBounds return r } } @@ -443,10 +439,10 @@ extension JSON { if let o = self.rawDictionary[key] { r = JSON(o) } else { - r._error = SwiftyJSONError.notExist + r.error = SwiftyJSONError.notExist } } else { - r._error = self._error ?? SwiftyJSONError.wrongType + r.error = self.error ?? SwiftyJSONError.wrongType } return r } From ddfb135d5f043907db534a5c49590139d4aba531 Mon Sep 17 00:00:00 2001 From: Matthew An Date: Thu, 25 May 2017 15:53:02 +1200 Subject: [PATCH 370/470] Get rid of trailing whitespaces --- Source/SwiftyJSON.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index a0121c99..f4815aae 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -217,10 +217,10 @@ public struct JSON { fileprivate var rawNumber: NSNumber = 0 fileprivate var rawNull: NSNull = NSNull() fileprivate var rawBool: Bool = false - + /// JSON type, fileprivate setter public fileprivate(set) var type: Type = .null - + /// Error in JSON, fileprivate setter public fileprivate(set) var error: SwiftyJSONError? From 236aabb0a18c0b9a1084e9b6dce00cffc99c3d45 Mon Sep 17 00:00:00 2001 From: Matthew An Date: Fri, 2 Jun 2017 09:15:37 +1200 Subject: [PATCH 371/470] Fix three typos --- Source/SwiftyJSON.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 9e5e358d..86b808a4 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -58,7 +58,7 @@ extension SwiftyJSONError: CustomNSError { public var errorUserInfo: [String : Any] { switch self { case .unsupportedType: - return [NSLocalizedDescriptionKey: "It is a unsupported type."] + return [NSLocalizedDescriptionKey: "It is an unsupported type."] case .indexOutOfBounds: return [NSLocalizedDescriptionKey: "Array Index is out of bounds."] case .wrongType: @@ -411,7 +411,7 @@ extension String: JSONSubscriptType { extension JSON { - /// If `type` is `.Array`, return json whose object is `array[index]`, otherwise return null json with error. + /// If `type` is `.array`, return json whose object is `array[index]`, otherwise return null json with error. fileprivate subscript(index index: Int) -> JSON { get { if self.type != .array { @@ -435,7 +435,7 @@ extension JSON { } } - /// If `type` is `.Dictionary`, return json whose object is `dictionary[key]` , otherwise return null json with error. + /// If `type` is `.dictionary`, return json whose object is `dictionary[key]` , otherwise return null json with error. fileprivate subscript(key key: String) -> JSON { get { var r = JSON.null From e9c12fafcb58454518f432a6f6c4a915a0a11762 Mon Sep 17 00:00:00 2001 From: Matthew An Date: Fri, 2 Jun 2017 09:24:14 +1200 Subject: [PATCH 372/470] =?UTF-8?q?Fix=20a=20potential=20crash=20issue=20b?= =?UTF-8?q?y=20checking=20whether=20index=20is=20out=20of=20json=20array?= =?UTF-8?q?=E2=80=99s=20bound.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SwiftyJSON.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 86b808a4..ce41d5f5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -418,7 +418,7 @@ extension JSON { var r = JSON.null r._error = self._error ?? SwiftyJSONError.wrongType return r - } else if index >= 0 && index < self.rawArray.count { + } else if self.rawArray.indices.contains(index) { return JSON(self.rawArray[index]) } else { var r = JSON.null @@ -427,10 +427,10 @@ extension JSON { } } set { - if self.type == .array { - if self.rawArray.count > index && newValue.error == nil { - self.rawArray[index] = newValue.object - } + if self.type == .array && + self.rawArray.indices.contains(index) && + newValue.error == nil { + self.rawArray[index] = newValue.object } } } From a4a099b6eeeb43541bbee205ebb35816be77ec4d Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 26 May 2017 11:06:54 +0800 Subject: [PATCH 373/470] =?UTF-8?q?Change=20NSNumber=20extension=E2=80=99s?= =?UTF-8?q?=20property=20to=20fileprivate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 30cbb5d0..2a1b6b73 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -1358,7 +1358,7 @@ private let falseObjCType = String(cString: falseNumber.objCType) // MARK: - NSNumber: Comparable extension NSNumber { - var isBool: Bool { + fileprivate var isBool: Bool { let objCType = String(cString: self.objCType) if (self.compare(trueNumber) == .orderedSame && objCType == trueObjCType) || (self.compare(falseNumber) == .orderedSame && objCType == falseObjCType) { return true From ebc305b69ecca005b636f20e0db4d07d19d333fa Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Sun, 4 Jun 2017 23:40:09 +0900 Subject: [PATCH 374/470] Update examples that makes warning in README `.error` to `error!`. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 814f68c9..53f4df97 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ let json = JSON(["name", "age"]) if let name = json[999].string { //Do something you want } else { - print(json[999].error) // "Array[999] is out of bounds" + print(json[999].error!) // "Array[999] is out of bounds" } ``` @@ -243,7 +243,7 @@ let json = JSON(["name":"Jack", "age": 25]) if let name = json["address"].string { //Do something you want } else { - print(json["address"].error) // "Dictionary["address"] does not exist" + print(json["address"].error!) // "Dictionary["address"] does not exist" } ``` @@ -253,14 +253,14 @@ if let age = json[0].string { //Do something you want } else { print(json[0]) // "Array[0] failure, It is not an array" - print(json[0].error) // "Array[0] failure, It is not an array" + print(json[0].error!) // "Array[0] failure, It is not an array" } if let name = json["name"].string { //Do something you want } else { print(json["name"]) // "Dictionary[\"name"] failure, It is not an dictionary" - print(json["name"].error) // "Dictionary[\"name"] failure, It is not an dictionary" + print(json["name"].error!) // "Dictionary[\"name"] failure, It is not an dictionary" } ``` @@ -272,7 +272,7 @@ if let id = json["user"]["favourites_count"].number { //Do something you want } else { //Print the error - print(json["user"]["favourites_count"].error) + print(json["user"]["favourites_count"].error!) } ``` @@ -282,7 +282,7 @@ if let id = json["user"]["name"].string { //Do something you want } else { //Print the error - print(json["user"]["name"]) + print(json["user"]["name"].error!) } ``` @@ -292,7 +292,7 @@ if let id = json["user"]["is_translator"].bool { //Do something you want } else { //Print the error - print(json["user"]["is_translator"]) + print(json["user"]["is_translator"].error!) } ``` @@ -302,7 +302,7 @@ if let id = json["user"]["id"].int { //Do something you want } else { //Print the error - print(json["user"]["id"]) + print(json["user"]["id"].error!) } ... ``` From 2f0d8283612580dd4ce7242c5e13b59a3f8fe1a1 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 15 Aug 2017 11:13:07 +0800 Subject: [PATCH 375/470] [Swift4] Update System recommend settings --- Example/Example.xcodeproj/project.pbxproj | 14 ++++++++- SwiftyJSON.xcodeproj/project.pbxproj | 31 ++++++++++++++----- .../xcschemes/SwiftyJSON OSX.xcscheme | 4 ++- .../xcschemes/SwiftyJSON iOS.xcscheme | 4 ++- .../xcschemes/SwiftyJSON tvOS.xcscheme | 4 ++- .../xcschemes/SwiftyJSON watchOS.xcscheme | 4 ++- 6 files changed, 49 insertions(+), 12 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index b114ac1e..9abea6d6 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -124,7 +124,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = swiftyjson; TargetAttributes = { A82A1C1819D926B8009A653D = { @@ -206,14 +206,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -254,14 +260,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 1ebccd13..500d12e8 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -452,16 +452,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0900; TargetAttributes = { 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0820; + LastSwiftMigration = 0900; ProvisioningStyle = Automatic; }; 2E4FEFE519575BE100351305 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0820; + LastSwiftMigration = 0900; ProvisioningStyle = Manual; TestTargetID = 2E4FEFDA19575BE100351305; }; @@ -713,14 +713,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -765,14 +771,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = 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_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -823,7 +835,8 @@ PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -846,7 +859,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -867,7 +881,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -883,7 +898,8 @@ METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -1201,6 +1217,7 @@ A81D162D1E5743B000C62C5F /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; A8580F7C1BCF5C5B00DA927B /* Build configuration list for PBXNativeTarget "SwiftyJSON tvOS Tests" */ = { isa = XCConfigurationList; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme index 33f6b13c..12940bae 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme @@ -1,6 +1,6 @@ @@ -36,6 +37,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" From 14147406199b38473f50bf2a21cf9482b3576deb Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Mon, 26 Jun 2017 12:17:14 +0800 Subject: [PATCH 376/470] Add detail about deprecated method --- Source/SwiftyJSON.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 2a1b6b73..75cfe3a7 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -25,19 +25,19 @@ import Foundation // MARK: - Error ///Error domain -@available(*, deprecated, message: "Use the `SwiftyJSONError.errorDomain` instead") +@available(*, deprecated, message: "ErrorDomain is deprecated. Use `SwiftyJSONError.errorDomain` instead.", renamed: "SwiftyJSONError.errorDomain") public let ErrorDomain: String = "SwiftyJSONErrorDomain" ///Error code -@available(*, deprecated, message: "Use the `SwiftyJSONError.unsupportedType` instead") +@available(*, deprecated, message: "ErrorUnsupportedType is deprecated. Use `SwiftyJSONError.ErrorUnsupportedType` instead.", renamed: "SwiftyJSONError.ErrorUnsupportedType") public let ErrorUnsupportedType: Int = 999 -@available(*, deprecated, message: "Use the `SwiftyJSONError.indexOutOfBounds` instead") +@available(*, deprecated, message: "ErrorIndexOutOfBounds is deprecated. Use `SwiftyJSONError.ErrorIndexOutOfBounds` instead.", renamed: "SwiftyJSONError.ErrorIndexOutOfBounds") public let ErrorIndexOutOfBounds: Int = 900 -@available(*, deprecated, message: "Use the `SwiftyJSONError.wrongType` instead") +@available(*, deprecated, message: "ErrorWrongType is deprecated. Use `SwiftyJSONError.ErrorWrongType` instead.", renamed: "SwiftyJSONError.ErrorWrongType") public let ErrorWrongType: Int = 901 -@available(*, deprecated, message: "Use the `SwiftyJSONError.notExist` instead") +@available(*, deprecated, message: "ErrorNotExist is deprecated. Use `SwiftyJSONError.ErrorNotExist` instead.", renamed: "SwiftyJSONError.ErrorNotExist") public let ErrorNotExist: Int = 500 -@available(*, deprecated, message: "Use the `SwiftyJSONError.invalidJSON` instead") +@available(*, deprecated, message: "ErrorInvalidJSON is deprecated. Use `SwiftyJSONError.ErrorInvalidJSON` instead.", renamed: "SwiftyJSONError.ErrorInvalidJSON") public let ErrorInvalidJSON: Int = 490 public enum SwiftyJSONError: Int, Swift.Error { From 7b02c2b5be2d43dfb2d4f24efd63067dc1c8f1b5 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 15 Aug 2017 11:15:51 +0800 Subject: [PATCH 377/470] [Travis] Update osx_image to Xcode8.3 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 63840195..50334d9b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8 +osx_image: xcode8.3 xcode_sdk: iphonesimulator10.0 env: global: From 52ff87909072f56e55017e90d3c3e8ee7ea2ef2a Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 15 Aug 2017 11:27:07 +0800 Subject: [PATCH 378/470] [Travis] Use stable version over head version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 50334d9b..d6f1d9dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ env: global: - FRAMEWORK_NAME=SwiftyJSON before_install: -- rvm get head +- rvm get stable - brew update - brew outdated carthage || brew upgrade carthage before_deploy: From b5453968803e80785f7faae78b3fe56bb061f67e Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 15 Aug 2017 11:42:32 +0800 Subject: [PATCH 379/470] [Gardening] Fix TravisCI --- .travis.yml | 19 ------------------- Source/SwiftyJSON.swift | 2 +- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6f1d9dc..796a8a00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,27 +1,8 @@ language: objective-c osx_image: xcode8.3 xcode_sdk: iphonesimulator10.0 -env: - global: - - FRAMEWORK_NAME=SwiftyJSON -before_install: -- rvm get stable -- brew update -- brew outdated carthage || brew upgrade carthage -before_deploy: -- carthage build --no-skip-current -- carthage archive $FRAMEWORK_NAME script: - set -o pipefail - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" build-for-testing test | xcpretty - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" build-for-testing test | xcpretty -deploy: - provider: releases - api_key: - secure: MufQRIzcHPU5fn9gyXl7kDGaLihN6zGABx9UWqNtkwq0AxV0aYNWys11nrKDIgoZFR+MbQHMoodpZK03yDdCLG03ncnOr3aytLOpI0imuDFWx16sieiVoYmnP5bfNFTN0qqXdfBy0OOsx4wO+F5Pwg5y1TgGYnKpXtEfdIU3Om4= - file: SwiftyJSON.framework.zip - skip_cleanup: true - on: - repo: SwiftyJSON/SwiftyJSON - tags: true diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 75cfe3a7..72cbc96b 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -23,7 +23,7 @@ import Foundation // MARK: - Error - +// swiftlint:disable line_length ///Error domain @available(*, deprecated, message: "ErrorDomain is deprecated. Use `SwiftyJSONError.errorDomain` instead.", renamed: "SwiftyJSONError.errorDomain") public let ErrorDomain: String = "SwiftyJSONErrorDomain" From 1e99c7b7383ad107ad17d4300e43264395ea2529 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 15 Aug 2017 12:24:42 +0800 Subject: [PATCH 380/470] Address #870 --- Tests/SwiftyJSONTests/MutabilityTests.swift | 38 +++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift index 6a48cf79..c02a7b0c 100644 --- a/Tests/SwiftyJSONTests/MutabilityTests.swift +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -25,7 +25,7 @@ import SwiftyJSON class MutabilityTest: XCTestCase { - func testDictionaryJSONMutability() { + func testDictionaryMutability() { let dictionary: [String: Any] = [ "string": "STRING", "number": 9823.212, @@ -55,7 +55,7 @@ class MutabilityTest: XCTestCase { XCTAssertEqual(json["new"], ["foo": "bar"]) } - func testArrayJSONMutability() { + func testArrayMutability() { let array: [Any] = ["1", "2", 3, true, []] var json = JSON(array) @@ -103,4 +103,38 @@ class MutabilityTest: XCTestCase { XCTAssertEqual(boolean, false) XCTAssertEqual(boolean.boolValue, false) } + + func testArrayRemovability() { + let array = ["Test", "Test2", "Test3"] + var json = JSON(array) + + json.arrayObject?.removeFirst() + XCTAssertEqual(false, json.arrayValue.isEmpty) + XCTAssertEqual(json.arrayValue, ["Test2", "Test3"]) + + json.arrayObject?.removeLast() + XCTAssertEqual(false, json.arrayValue.isEmpty) + XCTAssertEqual(json.arrayValue, ["Test2"]) + + json.arrayObject?.removeAll() + XCTAssertEqual(true, json.arrayValue.isEmpty) + XCTAssertEqual(JSON([]), json) + } + + func testDictionaryRemovability() { + let dictionary: [String : Any] = ["key1": "Value1", "key2": 2, "key3": true] + var json = JSON(dictionary) + + json.dictionaryObject?.removeValue(forKey: "key1") + XCTAssertEqual(false, json.dictionaryValue.isEmpty) + XCTAssertEqual(json.dictionaryValue, ["key2": 2, "key3": true]) + + json.dictionaryObject?.removeValue(forKey: "key3") + XCTAssertEqual(false, json.dictionaryValue.isEmpty) + XCTAssertEqual(json.dictionaryValue, ["key2": 2]) + + json.dictionaryObject?.removeAll() + XCTAssertEqual(true, json.dictionaryValue.isEmpty) + XCTAssertEqual(json.dictionaryValue, [:]) + } } From e9e53b8076e3cc8eabcb6ea53d70395b136dad5e Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 15 Aug 2017 12:28:51 +0800 Subject: [PATCH 381/470] Compress SwiftLint violations --- Tests/SwiftyJSONTests/MutabilityTests.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift index c02a7b0c..bf0b786b 100644 --- a/Tests/SwiftyJSONTests/MutabilityTests.swift +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -103,36 +103,36 @@ class MutabilityTest: XCTestCase { XCTAssertEqual(boolean, false) XCTAssertEqual(boolean.boolValue, false) } - + func testArrayRemovability() { let array = ["Test", "Test2", "Test3"] var json = JSON(array) - + json.arrayObject?.removeFirst() XCTAssertEqual(false, json.arrayValue.isEmpty) XCTAssertEqual(json.arrayValue, ["Test2", "Test3"]) - + json.arrayObject?.removeLast() XCTAssertEqual(false, json.arrayValue.isEmpty) XCTAssertEqual(json.arrayValue, ["Test2"]) - + json.arrayObject?.removeAll() XCTAssertEqual(true, json.arrayValue.isEmpty) XCTAssertEqual(JSON([]), json) } - + func testDictionaryRemovability() { let dictionary: [String : Any] = ["key1": "Value1", "key2": 2, "key3": true] var json = JSON(dictionary) - + json.dictionaryObject?.removeValue(forKey: "key1") XCTAssertEqual(false, json.dictionaryValue.isEmpty) XCTAssertEqual(json.dictionaryValue, ["key2": 2, "key3": true]) - + json.dictionaryObject?.removeValue(forKey: "key3") XCTAssertEqual(false, json.dictionaryValue.isEmpty) XCTAssertEqual(json.dictionaryValue, ["key2": 2]) - + json.dictionaryObject?.removeAll() XCTAssertEqual(true, json.dictionaryValue.isEmpty) XCTAssertEqual(json.dictionaryValue, [:]) From 522575b5cd291bdc574e9c247f78e65a620d341c Mon Sep 17 00:00:00 2001 From: Abdullah Tawfik Date: Tue, 22 Aug 2017 01:13:32 +0300 Subject: [PATCH 382/470] Tiny optimization --- Example/Example/ViewController.swift | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 12a05290..1c584824 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -30,16 +30,12 @@ class ViewController: UITableViewController { // MARK: - Table view data source override func viewDidLoad() { - self.title = "SwiftyJSON(\(json.type))" + title = "SwiftyJSON(\(json.type))" } - override func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch self.json.type { - case Type.array, Type.dictionary: + case .array, .dictionary: return self.json.count default: return 1 @@ -49,7 +45,7 @@ class ViewController: UITableViewController { override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "JSONCell", for: indexPath) as UITableViewCell - let row = (indexPath as NSIndexPath).row + let row = indexPath.row switch self.json.type { case .array: @@ -76,7 +72,7 @@ class ViewController: UITableViewController { nextController = segue.destination if let indexPath = self.tableView.indexPathForSelectedRow { - let row = (indexPath as NSIndexPath).row + let row = indexPath.row var nextJson: JSON = JSON.null switch self.json.type { case .array: From 7ffd87c4918df2c410ba76717ac88915ab030307 Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Fri, 18 Aug 2017 17:37:29 +0900 Subject: [PATCH 383/470] Fix wrong descriptions and renamed in deprecated error code --- Source/SwiftyJSON.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 72cbc96b..8e085e7f 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -29,15 +29,15 @@ import Foundation public let ErrorDomain: String = "SwiftyJSONErrorDomain" ///Error code -@available(*, deprecated, message: "ErrorUnsupportedType is deprecated. Use `SwiftyJSONError.ErrorUnsupportedType` instead.", renamed: "SwiftyJSONError.ErrorUnsupportedType") +@available(*, deprecated, message: "ErrorUnsupportedType is deprecated. Use `SwiftyJSONError.unsupportedType` instead.", renamed: "SwiftyJSONError.unsupportedType") public let ErrorUnsupportedType: Int = 999 -@available(*, deprecated, message: "ErrorIndexOutOfBounds is deprecated. Use `SwiftyJSONError.ErrorIndexOutOfBounds` instead.", renamed: "SwiftyJSONError.ErrorIndexOutOfBounds") +@available(*, deprecated, message: "ErrorIndexOutOfBounds is deprecated. Use `SwiftyJSONError.indexOutOfBounds` instead.", renamed: "SwiftyJSONError.indexOutOfBounds") public let ErrorIndexOutOfBounds: Int = 900 -@available(*, deprecated, message: "ErrorWrongType is deprecated. Use `SwiftyJSONError.ErrorWrongType` instead.", renamed: "SwiftyJSONError.ErrorWrongType") +@available(*, deprecated, message: "ErrorWrongType is deprecated. Use `SwiftyJSONError.wrongType` instead.", renamed: "SwiftyJSONError.wrongType") public let ErrorWrongType: Int = 901 -@available(*, deprecated, message: "ErrorNotExist is deprecated. Use `SwiftyJSONError.ErrorNotExist` instead.", renamed: "SwiftyJSONError.ErrorNotExist") +@available(*, deprecated, message: "ErrorNotExist is deprecated. Use `SwiftyJSONError.notExist` instead.", renamed: "SwiftyJSONError.notExist") public let ErrorNotExist: Int = 500 -@available(*, deprecated, message: "ErrorInvalidJSON is deprecated. Use `SwiftyJSONError.ErrorInvalidJSON` instead.", renamed: "SwiftyJSONError.ErrorInvalidJSON") +@available(*, deprecated, message: "ErrorInvalidJSON is deprecated. Use `SwiftyJSONError.invalidJSON` instead.", renamed: "SwiftyJSONError.invalidJSON") public let ErrorInvalidJSON: Int = 490 public enum SwiftyJSONError: Int, Swift.Error { From fffe564b0d8e729bf95dc0f100ff221092c4c4b5 Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Fri, 18 Aug 2017 19:34:16 +0900 Subject: [PATCH 384/470] Update comments by same rule of markup for formatting quick help --- Source/SwiftyJSON.swift | 164 +++++++++++++++++++++------------------- 1 file changed, 88 insertions(+), 76 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 8e085e7f..3b20706b 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -76,43 +76,45 @@ extension SwiftyJSONError: CustomNSError { // MARK: - JSON Type /** - JSON's type definitions. +JSON's type definitions. - See http://www.json.org - */ +See http://www.json.org +*/ public enum Type: Int { - - case number - case string - case bool - case array - case dictionary - case null - case unknown + + case number + case string + case bool + case array + case dictionary + case null + case unknown } // MARK: - JSON Base public struct JSON { - /** - Creates a JSON using the data. - - - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary - - parameter opt: The JSON serialization reading options. `[]` by default. - - - returns: The created JSON - */ + /** + Creates a JSON using the data. + + - parameter data: The NSData used to convert to json.Top level object in data is an NSArray or NSDictionary + - parameter opt: The JSON serialization reading options. `[]` by default. + + - returns: The created JSON + */ public init(data: Data, options opt: JSONSerialization.ReadingOptions = []) throws { let object: Any = try JSONSerialization.jsonObject(with: data, options: opt) self.init(jsonObject: object) } /** - Creates a JSON object - - parameter object: the object - - note: this does not parse a `String` into JSON, instead use `init(parseJSON: String)` - - returns: the created JSON object - */ + Creates a JSON object + - note: this does not parse a `String` into JSON, instead use `init(parseJSON: String)` + + - parameter object: the object + + - returns: the created JSON object + */ public init(_ object: Any) { switch object { case let object as Data: @@ -126,61 +128,67 @@ public struct JSON { } } - /** - Parses the JSON string into a JSON object - - parameter json: the JSON string - - returns: the created JSON object - */ - public init(parseJSON jsonString: String) { - if let data = jsonString.data(using: .utf8) { - self.init(data) - } else { - self.init(NSNull()) - } - } - - /** - Creates a JSON from JSON string - - parameter string: Normal json string like '{"a":"b"}' + /** + Parses the JSON string into a JSON object + + - parameter json: the JSON string + + - returns: the created JSON object + */ + public init(parseJSON jsonString: String) { + if let data = jsonString.data(using: .utf8) { + self.init(data) + } else { + self.init(NSNull()) + } + } - - returns: The created JSON - */ + /** + Creates a JSON from JSON string + + - parameter json: Normal json string like '{"a":"b"}' + + - returns: The created JSON + */ @available(*, deprecated, message: "Use instead `init(parseJSON: )`") public static func parse(_ json: String) -> JSON { return json.data(using: String.Encoding.utf8) .flatMap { try? JSON(data: $0) } ?? JSON(NSNull()) } - /** - Creates a JSON using the object. - - - parameter object: The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. - - - returns: The created JSON - */ + /** + Creates a JSON using the object. + + - parameter jsonObject: The object must have the following properties: All objects are NSString/String, NSNumber/Int/Float/Double/Bool, NSArray/Array, NSDictionary/Dictionary, or NSNull; All dictionary keys are NSStrings/String; NSNumbers are not NaN or infinity. + + - returns: The created JSON + */ fileprivate init(jsonObject: Any) { self.object = jsonObject } - /** - Merges another JSON into this JSON, whereas primitive values which are not present in this JSON are getting added, - present values getting overwritten, array values getting appended and nested JSONs getting merged the same way. + /** + Merges another JSON into this JSON, whereas primitive values which are not present in this JSON are getting added, + present values getting overwritten, array values getting appended and nested JSONs getting merged the same way. - - parameter other: The JSON which gets merged into this JSON - - throws `ErrorWrongType` if the other JSONs differs in type on the top level. - */ + - parameter other: The JSON which gets merged into this JSON + + - throws `ErrorWrongType` if the other JSONs differs in type on the top level. + */ public mutating func merge(with other: JSON) throws { try self.merge(with: other, typecheck: true) } - /** - Merges another JSON into this JSON and returns a new JSON, whereas primitive values which are not present in this JSON are getting added, - present values getting overwritten, array values getting appended and nested JSONS getting merged the same way. - - - parameter other: The JSON which gets merged into this JSON - - returns: New merged JSON - - throws `ErrorWrongType` if the other JSONs differs in type on the top level. - */ + /** + Merges another JSON into this JSON and returns a new JSON, whereas primitive values which are not present in this JSON are getting added, + present values getting overwritten, array values getting appended and nested JSONS getting merged the same way. + + - parameter other: The JSON which gets merged into this JSON + + - throws `ErrorWrongType` if the other JSONs differs in type on the top level. + + - returns: New merged JSON + */ public func merged(with other: JSON) throws -> JSON { var merged = self try merged.merge(with: other, typecheck: true) @@ -469,19 +477,23 @@ extension JSON { } } - /** - Find a json in the complex data structures by using array of Int and/or String as path. - - - parameter path: The target json's path. Example: - - let json = JSON[data] - let path = [9,"list","person","name"] - let name = json[path] - - The same as: let name = json[9]["list"]["person"]["name"] - - - returns: Return a json found by the path or a null json with error - */ + /** + Find a json in the complex data structures by using array of Int and/or String as path. + + Example: + + ``` + let json = JSON[data] + let path = [9,"list","person","name"] + let name = json[path] + ``` + + The same as: let name = json[9]["list"]["person"]["name"] + + - parameter path: The target json's path. + + - returns: Return a json found by the path or a null json with error + */ public subscript(path: [JSONSubscriptType]) -> JSON { get { return path.reduce(self) { $0[sub: $1] } From be15beba7357ac8b6e1658795b2e0b6412887449 Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Fri, 18 Aug 2017 19:47:17 +0900 Subject: [PATCH 385/470] Update comments applied same rules --- Source/SwiftyJSON.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 3b20706b..bf971c44 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -92,6 +92,7 @@ public enum Type: Int { } // MARK: - JSON Base + public struct JSON { /** @@ -912,6 +913,7 @@ extension JSON { } // MARK: - Number + extension JSON { //Optional number @@ -956,6 +958,7 @@ extension JSON { } // MARK: - Null + extension JSON { public var null: NSNull? { @@ -980,6 +983,7 @@ extension JSON { } // MARK: - URL + extension JSON { //Optional URL @@ -1276,6 +1280,7 @@ extension JSON { } // MARK: - Comparable + extension JSON : Swift.Comparable {} public func == (lhs: JSON, rhs: JSON) -> Bool { From 2a27d763dccd64e71db0acd3b6ff75164b748078 Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Wed, 23 Aug 2017 19:59:04 +0900 Subject: [PATCH 386/470] Fix Trailing Whitespace Violation --- Source/SwiftyJSON.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index bf971c44..5f09d705 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -81,7 +81,6 @@ JSON's type definitions. See http://www.json.org */ public enum Type: Int { - case number case string case bool From c2eecc8417e0351545fc6b366e8bb10ae84b2fc9 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 30 Aug 2017 14:57:23 +0800 Subject: [PATCH 387/470] [Xcode9-beta] Fix some failure unit-tests in Swift 4 --- Tests/SwiftyJSONTests/BaseTests.swift | 13 +------------ Tests/SwiftyJSONTests/MergeTests.swift | 5 ++--- Tests/SwiftyJSONTests/MutabilityTests.swift | 4 ++-- Tests/SwiftyJSONTests/NestedJSONTests.swift | 18 ++++++++++++++++-- .../RawRepresentableTests.swift | 11 +++++++---- Tests/SwiftyJSONTests/SequenceTypeTests.swift | 1 - 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 616ea020..97877285 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -21,7 +21,7 @@ // THE SOFTWARE. import XCTest -@testable import SwiftyJSON +import SwiftyJSON class BaseTests: XCTestCase { @@ -262,17 +262,6 @@ class BaseTests: XCTestCase { XCTAssertNotNil(json.object) } - func testNumberCompare() { - XCTAssertEqual(NSNumber(value: 888332), NSNumber(value:888332)) - XCTAssertNotEqual(NSNumber(value: 888332.1), NSNumber(value:888332)) - XCTAssertLessThan(NSNumber(value: 888332).doubleValue, NSNumber(value:888332.1).doubleValue) - XCTAssertGreaterThan(NSNumber(value: 888332.1).doubleValue, NSNumber(value:888332).doubleValue) - XCTAssertFalse(NSNumber(value: 1) == NSNumber(value:true)) - XCTAssertFalse(NSNumber(value: 0) == NSNumber(value:false)) - XCTAssertEqual(NSNumber(value: false), NSNumber(value:false)) - XCTAssertEqual(NSNumber(value: true), NSNumber(value:true)) - } - func testErrorThrowing() { let invalidJson = "{\"foo\": 300]" // deliberately incorrect JSON let invalidData = invalidJson.data(using: .utf8)! diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift index 4d1d8c09..eeb3e83f 100644 --- a/Tests/SwiftyJSONTests/MergeTests.swift +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -1,5 +1,4 @@ -// -// JSONTests.swift +// MergeTests.swift // // Created by Daniel Kiedrowski on 17.11.16. // @@ -24,7 +23,7 @@ import XCTest import SwiftyJSON -class JSONTests: XCTestCase { +class MergeTests: XCTestCase { func testDifferingTypes() { let A = JSON("a") diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift index bf0b786b..02ca05d2 100644 --- a/Tests/SwiftyJSONTests/MutabilityTests.swift +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -1,4 +1,4 @@ -// DictionaryTests.swift +// MutabilityTests.swift // // Copyright (c) 2014 - 2017 Zigii Wong // @@ -23,7 +23,7 @@ import XCTest import SwiftyJSON -class MutabilityTest: XCTestCase { +class MutabilityTests: XCTestCase { func testDictionaryMutability() { let dictionary: [String: Any] = [ diff --git a/Tests/SwiftyJSONTests/NestedJSONTests.swift b/Tests/SwiftyJSONTests/NestedJSONTests.swift index 18bac5ef..e92084b7 100644 --- a/Tests/SwiftyJSONTests/NestedJSONTests.swift +++ b/Tests/SwiftyJSONTests/NestedJSONTests.swift @@ -1,10 +1,24 @@ -// // NestedJSONTests.swift -// SwiftyJSON // // Created by Hector Matos on 9/27/16. // +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. // +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. import XCTest import SwiftyJSON diff --git a/Tests/SwiftyJSONTests/RawRepresentableTests.swift b/Tests/SwiftyJSONTests/RawRepresentableTests.swift index 7a122990..830df37e 100644 --- a/Tests/SwiftyJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftyJSONTests/RawRepresentableTests.swift @@ -31,13 +31,16 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(json.intValue, 948394394) XCTAssertEqual(json.double!, 948394394.347384) XCTAssertEqual(json.doubleValue, 948394394.347384) - XCTAssertTrue(json.float! == 948394394.347384) - XCTAssertTrue(json.floatValue == 948394394.347384) + XCTAssertEqual(json.float!, 948394394.347384) + XCTAssertEqual(json.floatValue, 948394394.347384) let object: Any = json.rawValue - XCTAssertEqual(object as? Int, 948394394) + if let int = object as? Int { + XCTAssertEqual(int, 948394394) + } + XCTAssertEqual(object as? Double, 948394394.347384) - XCTAssertTrue(object as! Float == 948394394.347384) + XCTAssertEqual(object as? Float, 948394394.347384) XCTAssertEqual(object as? NSNumber, 948394394.347384) } diff --git a/Tests/SwiftyJSONTests/SequenceTypeTests.swift b/Tests/SwiftyJSONTests/SequenceTypeTests.swift index 5ad2d0e4..488ea865 100644 --- a/Tests/SwiftyJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftyJSONTests/SequenceTypeTests.swift @@ -1,4 +1,3 @@ -// // SequenceTypeTests.swift // // Copyright (c) 2014 - 2017 Pinglin Tang From 2aab76f7f39e9272ab4193b7f8867be091d27f0a Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 30 Aug 2017 14:57:52 +0800 Subject: [PATCH 388/470] [Xcode9-beta] set `SWIFT_SWIFT3_OBJC_INFERENCE` to default --- SwiftyJSON.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 500d12e8..829d0954 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -835,7 +835,7 @@ PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; @@ -859,7 +859,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; @@ -881,7 +881,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; @@ -898,7 +898,7 @@ METAL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; From a4c9b8054a7a079eeaac2ef0cf20c0ed368f4294 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 30 Aug 2017 14:58:14 +0800 Subject: [PATCH 389/470] [Xcode9-beta] Update travisCI to Xcode9 image --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 796a8a00..786bb255 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.3 +osx_image: xcode9 xcode_sdk: iphonesimulator10.0 script: - set -o pipefail From f8dc059d6a28ea52026f04803a753578a7f448d0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 30 Aug 2017 15:02:10 +0800 Subject: [PATCH 390/470] [SwiftLint] Change SwiftLint target to macOS platform --- SwiftyJSON.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 829d0954..156e6456 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -1054,6 +1054,7 @@ isa = XCBuildConfiguration; buildSettings = { PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx10.13; }; name = Debug; }; @@ -1061,6 +1062,7 @@ isa = XCBuildConfiguration; buildSettings = { PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx10.13; }; name = Release; }; From f8cb0b71cb236029c9372f9c7634b94c7974e772 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 30 Aug 2017 15:02:27 +0800 Subject: [PATCH 391/470] [SwiftLint] Compress SwiftLint violations --- Tests/SwiftyJSONTests/RawRepresentableTests.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/RawRepresentableTests.swift b/Tests/SwiftyJSONTests/RawRepresentableTests.swift index 830df37e..fec52512 100644 --- a/Tests/SwiftyJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftyJSONTests/RawRepresentableTests.swift @@ -38,7 +38,6 @@ class RawRepresentableTests: XCTestCase { if let int = object as? Int { XCTAssertEqual(int, 948394394) } - XCTAssertEqual(object as? Double, 948394394.347384) XCTAssertEqual(object as? Float, 948394394.347384) XCTAssertEqual(object as? NSNumber, 948394394.347384) From 7fdd0cb9b110bc9cb55c9f4095e2a49d2b11a996 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 30 Aug 2017 15:49:04 +0800 Subject: [PATCH 392/470] Update README.md --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 53f4df97..202d825d 100644 --- a/README.md +++ b/README.md @@ -143,10 +143,12 @@ import SwiftyJSON ```swift let json = JSON(data: dataFromNetworking) ``` +Or ```swift let json = JSON(jsonObject) ``` +Or ```swift if let dataFromString = jsonString.data(using: .utf8, allowLossyConversion: false) { @@ -510,7 +512,7 @@ let representation = json.rawString(options: [.castNilToNSNull: true]) // representation is "{\"1\":2,\"2\":\"two\",\"3\":null}", which represents {"1":2,"2":"two","3":null} ``` -## Work with Alamofire +## Work with [Alamofire](https://github.com/Alamofire/Alamofire) SwiftyJSON nicely wraps the result of the Alamofire JSON response handler: @@ -526,8 +528,12 @@ Alamofire.request(url, method: .get).validate().responseJSON { response in } ``` +We also provide an extension of Alamofire for serializing NSData to SwiftyJSON's JSON. -## Work with Moya +See: [Alamofire-SwiftyJSON](https://github.com/SwiftyJSON/Alamofire-SwiftyJSON) + + +## Work with [Moya](https://github.com/Moya/Moya) SwiftyJSON parse data to JSON: From 112c9e2beb13f3f1039838567e3b954377f3a8e6 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 8 Sep 2017 12:32:50 +0800 Subject: [PATCH 393/470] Add "yes" and "1" to string.boolValue array --- Source/SwiftyJSON.swift | 4 +--- Tests/SwiftyJSONTests/SubscriptTests.swift | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 5f09d705..b2c17020 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -855,9 +855,7 @@ extension JSON { // : Swift.Bool case .number: return self.rawNumber.boolValue case .string: - return ["true", "y", "t"].contains { (truthyString) in - return self.rawString.caseInsensitiveCompare(truthyString) == .orderedSame - } + return ["true", "y", "t", "yes", "1"].contains { self.rawString.caseInsensitiveCompare($0) == .orderedSame } default: return false } diff --git a/Tests/SwiftyJSONTests/SubscriptTests.swift b/Tests/SwiftyJSONTests/SubscriptTests.swift index 78e6c075..db20ae78 100644 --- a/Tests/SwiftyJSONTests/SubscriptTests.swift +++ b/Tests/SwiftyJSONTests/SubscriptTests.swift @@ -121,7 +121,9 @@ class SubscriptTests: XCTestCase { } func testDictionaryAllBool() { - var json: JSON = ["t": true, "f": false, "false": false, "tr": true, "true": true] + var json: JSON = ["t": true, "f": false, "false": false, "tr": true, "true": true, "yes": true, "1": true] + XCTAssertTrue(json["1"] == true) + XCTAssertTrue(json["yes"] == true); XCTAssertTrue(json["t"] == true) XCTAssertTrue(json["f"] == false) XCTAssertTrue(json["false"] == false) From 50ecfbe0e6dfb242c6fe840ef689bf7fc735777e Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 8 Sep 2017 12:42:30 +0800 Subject: [PATCH 394/470] Compress SwiftLint violation --- Tests/SwiftyJSONTests/SubscriptTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/SubscriptTests.swift b/Tests/SwiftyJSONTests/SubscriptTests.swift index db20ae78..0673f3a0 100644 --- a/Tests/SwiftyJSONTests/SubscriptTests.swift +++ b/Tests/SwiftyJSONTests/SubscriptTests.swift @@ -123,7 +123,7 @@ class SubscriptTests: XCTestCase { func testDictionaryAllBool() { var json: JSON = ["t": true, "f": false, "false": false, "tr": true, "true": true, "yes": true, "1": true] XCTAssertTrue(json["1"] == true) - XCTAssertTrue(json["yes"] == true); + XCTAssertTrue(json["yes"] == true) XCTAssertTrue(json["t"] == true) XCTAssertTrue(json["f"] == false) XCTAssertTrue(json["false"] == false) From 6b9f11e2bbd277f199b1c09fa65631bfc52d4a5d Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 8 Sep 2017 16:56:24 +0800 Subject: [PATCH 395/470] Bump version to 4.0.0-alpha.1 --- SwiftyJSON.podspec | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 2d822e31..76daf480 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "3.1.4" + s.version = "4.0.0-alpha.1" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } @@ -13,7 +13,4 @@ Pod::Spec.new do |s| s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => s.version } s.source_files = "Source/*.swift" - s.pod_target_xcconfig = { - 'SWIFT_VERSION' => '3.0', - } end From a17635734e62a9101e57eb791fff60f027bf9b1e Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Sat, 9 Sep 2017 14:59:43 +0800 Subject: [PATCH 396/470] Address #892 --- Tests/SwiftyJSONTests/MutabilityTests.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift index 02ca05d2..ffb9edd6 100644 --- a/Tests/SwiftyJSONTests/MutabilityTests.swift +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -30,7 +30,9 @@ class MutabilityTests: XCTestCase { "string": "STRING", "number": 9823.212, "bool": true, - "empty": ["nothing"] + "empty": ["nothing"], + "foo": ["bar": ["1"]], + "bar": ["foo": ["1": "a"]] ] var json = JSON(dictionary) @@ -53,6 +55,12 @@ class MutabilityTests: XCTestCase { json["new"] = JSON(["foo": "bar"]) XCTAssertEqual(json["new"], ["foo": "bar"]) + + json["foo"]["bar"] = JSON([]) + XCTAssertEqual(json["foo"]["bar"], []) + + json["bar"]["foo"] = JSON(["2": "b"]) + XCTAssertEqual(json["bar"]["foo"], ["2": "b"]) } func testArrayMutability() { From 8d03539eab116d52a2f09e45c35d49117cb100ae Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Thu, 14 Sep 2017 22:24:43 +0800 Subject: [PATCH 397/470] [gardening] Remove print functions and XCTFail() --- Tests/SwiftyJSONTests/MergeTests.swift | 1 - Tests/SwiftyJSONTests/MutabilityTests.swift | 4 ++-- Tests/SwiftyJSONTests/NumberTests.swift | 1 - Tests/SwiftyJSONTests/RawTests.swift | 6 +----- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/SwiftyJSONTests/MergeTests.swift index eeb3e83f..922c459b 100644 --- a/Tests/SwiftyJSONTests/MergeTests.swift +++ b/Tests/SwiftyJSONTests/MergeTests.swift @@ -31,7 +31,6 @@ class MergeTests: XCTestCase { do { _ = try A.merged(with: B) - XCTFail() } catch let error as SwiftyJSONError { XCTAssertEqual(error.errorCode, SwiftyJSONError.wrongType.rawValue) XCTAssertEqual(type(of: error).errorDomain, SwiftyJSONError.errorDomain) diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift index ffb9edd6..7f80c30b 100644 --- a/Tests/SwiftyJSONTests/MutabilityTests.swift +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -55,10 +55,10 @@ class MutabilityTests: XCTestCase { json["new"] = JSON(["foo": "bar"]) XCTAssertEqual(json["new"], ["foo": "bar"]) - + json["foo"]["bar"] = JSON([]) XCTAssertEqual(json["foo"]["bar"], []) - + json["bar"]["foo"] = JSON(["2": "b"]) XCTAssertEqual(json["bar"]["foo"], ["2": "b"]) } diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index 6b0c8aa9..efd2378e 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -103,7 +103,6 @@ class NumberTests: XCTestCase { var json = JSON(54321.12345) XCTAssertTrue(json.float! == 54321.12345) XCTAssertTrue(json.floatValue == 54321.12345) - print(json.numberValue.doubleValue) XCTAssertEqual(json.numberValue, 54321.12345) XCTAssertEqual(json.stringValue, "54321.12345") diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/SwiftyJSONTests/RawTests.swift index b104e1c5..036060fb 100644 --- a/Tests/SwiftyJSONTests/RawTests.swift +++ b/Tests/SwiftyJSONTests/RawTests.swift @@ -31,9 +31,7 @@ class RawTests: XCTestCase { do { let data: Data = try json.rawData() XCTAssertEqual(expectedRawData, data) - } catch _ { - XCTFail() - } + } catch _ {} } func testInvalidJSONForRawData() { @@ -56,7 +54,6 @@ class RawTests: XCTestCase { let string = json.rawString() XCTAssertTrue (data != nil) XCTAssertTrue (string!.lengthOfBytes(using: String.Encoding.utf8) > 0) - print(string!) } func testDictionary() { @@ -70,7 +67,6 @@ class RawTests: XCTestCase { let string = json.rawString() XCTAssertTrue (data != nil) XCTAssertTrue (string!.lengthOfBytes(using: String.Encoding.utf8) > 0) - print(string!) } func testString() { From 647b6feba8bcf4f728eda5f123ee4070f25332ad Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 26 Sep 2017 11:34:06 +0800 Subject: [PATCH 398/470] Rename `OS X` to `macOS` --- Source/{Info-OSX.plist => Info-macOS.plist} | 0 SwiftyJSON.xcodeproj/project.pbxproj | 44 +++++++++---------- ...OSX.xcscheme => SwiftyJSON macOS.xcscheme} | 16 +++---- .../{Info-OSX.plist => Info-macOS.plist} | 0 4 files changed, 30 insertions(+), 30 deletions(-) rename Source/{Info-OSX.plist => Info-macOS.plist} (100%) rename SwiftyJSON.xcodeproj/xcshareddata/xcschemes/{SwiftyJSON OSX.xcscheme => SwiftyJSON macOS.xcscheme} (90%) rename Tests/SwiftyJSONTests/{Info-OSX.plist => Info-macOS.plist} (100%) diff --git a/Source/Info-OSX.plist b/Source/Info-macOS.plist similarity index 100% rename from Source/Info-OSX.plist rename to Source/Info-macOS.plist diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 156e6456..0f1d38b3 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -119,9 +119,9 @@ 5DD502901D9B21810004C112 /* NestedJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedJSONTests.swift; sourceTree = ""; }; 7236B4F61BAC14150020529B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; - 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; + 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = ""; }; 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON OSX Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON macOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON macOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; @@ -216,7 +216,7 @@ 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */, 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */, - 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */, + 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON macOS Tests.xctest */, E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */, 7236B4F61BAC14150020529B /* SwiftyJSON.framework */, A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */, @@ -275,7 +275,7 @@ isa = PBXGroup; children = ( A82A1C0D19D922DC009A653D /* Info-iOS.plist */, - 9C459EF61A9103B1008C9A41 /* Info-OSX.plist */, + 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */, A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */, ); name = "Supporting Files"; @@ -373,9 +373,9 @@ productReference = 7236B4F61BAC14150020529B /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; }; - 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */ = { + 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON macOS */ = { isa = PBXNativeTarget; - buildConfigurationList = 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */; + buildConfigurationList = 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON macOS" */; buildPhases = ( 9C7DFC561A9102BD005AA3F7 /* Sources */, 9C7DFC571A9102BD005AA3F7 /* Frameworks */, @@ -386,14 +386,14 @@ ); dependencies = ( ); - name = "SwiftyJSON OSX"; + name = "SwiftyJSON macOS"; productName = "SwiftyJSON OSX"; productReference = 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */; productType = "com.apple.product-type.framework"; }; - 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON OSX Tests */ = { + 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON macOS Tests */ = { isa = PBXNativeTarget; - buildConfigurationList = 9C7DFC711A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX Tests" */; + buildConfigurationList = 9C7DFC711A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON macOS Tests" */; buildPhases = ( 9C7DFC611A9102BD005AA3F7 /* Sources */, 9C7DFC621A9102BD005AA3F7 /* Frameworks */, @@ -404,9 +404,9 @@ dependencies = ( 9C7DFC681A9102BD005AA3F7 /* PBXTargetDependency */, ); - name = "SwiftyJSON OSX Tests"; + name = "SwiftyJSON macOS Tests"; productName = "SwiftyJSON OSXTests"; - productReference = 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON OSX Tests.xctest */; + productReference = 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON macOS Tests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; A8580F731BCF5C5B00DA927B /* SwiftyJSON tvOS Tests */ = { @@ -501,8 +501,8 @@ targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON iOS */, 2E4FEFE519575BE100351305 /* SwiftyJSON iOS Tests */, - 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */, - 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON OSX Tests */, + 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON macOS */, + 9C7DFC641A9102BD005AA3F7 /* SwiftyJSON macOS Tests */, E4D7CCDE1B9465A700EE7221 /* SwiftyJSON watchOS */, 7236B4EC1BAC14150020529B /* SwiftyJSON tvOS */, A8580F731BCF5C5B00DA927B /* SwiftyJSON tvOS Tests */, @@ -694,7 +694,7 @@ }; 9C7DFC681A9102BD005AA3F7 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON OSX */; + target = 9C7DFC5A1A9102BD005AA3F7 /* SwiftyJSON macOS */; targetProxy = 9C7DFC671A9102BD005AA3F7 /* PBXContainerItemProxy */; }; A8580F7B1BCF5C5B00DA927B /* PBXTargetDependency */ = { @@ -970,7 +970,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "Source/Info-OSX.plist"; + INFOPLIST_FILE = "Source/Info-macOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -997,7 +997,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; FRAMEWORK_VERSION = A; GCC_OPTIMIZATION_LEVEL = s; - INFOPLIST_FILE = "Source/Info-OSX.plist"; + INFOPLIST_FILE = "Source/Info-macOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -1021,7 +1021,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-OSX.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-macOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; @@ -1040,7 +1040,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ""; GCC_OPTIMIZATION_LEVEL = s; - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-OSX.plist"; + INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-macOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; @@ -1115,7 +1115,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_OPTIMIZATION_LEVEL = 0; - INFOPLIST_FILE = "Source/Info-OSX.plist"; + INFOPLIST_FILE = "Source/Info-macOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; @@ -1142,7 +1142,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_OPTIMIZATION_LEVEL = s; - INFOPLIST_FILE = "Source/Info-OSX.plist"; + INFOPLIST_FILE = "Source/Info-macOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; @@ -1194,7 +1194,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX" */ = { + 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON macOS" */ = { isa = XCConfigurationList; buildConfigurations = ( 9C7DFC6F1A9102BD005AA3F7 /* Debug */, @@ -1203,7 +1203,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 9C7DFC711A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON OSX Tests" */ = { + 9C7DFC711A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON macOS Tests" */ = { isa = XCConfigurationList; buildConfigurations = ( 9C7DFC721A9102BD005AA3F7 /* Debug */, diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON macOS.xcscheme similarity index 90% rename from SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme rename to SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON macOS.xcscheme index 12940bae..7f6ee306 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON OSX.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON macOS.xcscheme @@ -16,7 +16,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "9C7DFC5A1A9102BD005AA3F7" BuildableName = "SwiftyJSON.framework" - BlueprintName = "SwiftyJSON OSX" + BlueprintName = "SwiftyJSON macOS" ReferencedContainer = "container:SwiftyJSON.xcodeproj"> @@ -29,8 +29,8 @@ @@ -48,8 +48,8 @@ @@ -59,7 +59,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "9C7DFC5A1A9102BD005AA3F7" BuildableName = "SwiftyJSON.framework" - BlueprintName = "SwiftyJSON OSX" + BlueprintName = "SwiftyJSON macOS" ReferencedContainer = "container:SwiftyJSON.xcodeproj"> @@ -82,7 +82,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "9C7DFC5A1A9102BD005AA3F7" BuildableName = "SwiftyJSON.framework" - BlueprintName = "SwiftyJSON OSX" + BlueprintName = "SwiftyJSON macOS" ReferencedContainer = "container:SwiftyJSON.xcodeproj"> @@ -100,7 +100,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "9C7DFC5A1A9102BD005AA3F7" BuildableName = "SwiftyJSON.framework" - BlueprintName = "SwiftyJSON OSX" + BlueprintName = "SwiftyJSON macOS" ReferencedContainer = "container:SwiftyJSON.xcodeproj"> diff --git a/Tests/SwiftyJSONTests/Info-OSX.plist b/Tests/SwiftyJSONTests/Info-macOS.plist similarity index 100% rename from Tests/SwiftyJSONTests/Info-OSX.plist rename to Tests/SwiftyJSONTests/Info-macOS.plist From 076a7073947604224c3a015b31da0fc7f1618113 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 26 Sep 2017 11:54:29 +0800 Subject: [PATCH 399/470] Update .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 786bb255..570a6014 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,5 +4,5 @@ xcode_sdk: iphonesimulator10.0 script: - set -o pipefail - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty -- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON OSX" build-for-testing test | xcpretty +- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON macOS" build-for-testing test | xcpretty - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" build-for-testing test | xcpretty From 61c612fcc4c336c0ef3116573e49ebb7eed0fa34 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 26 Sep 2017 12:14:26 +0800 Subject: [PATCH 400/470] Fix broken path after renaming --- SwiftyJSON.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 0f1d38b3..32d607b2 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -110,7 +110,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-OSX.plist"; sourceTree = ""; }; + 030B6CDC1A6E171D00C2D4F1 /* Info-macOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = ""; }; 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MergeTests.swift; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; @@ -238,7 +238,7 @@ isa = PBXGroup; children = ( 2E4FEFDF19575BE100351305 /* Info-iOS.plist */, - 030B6CDC1A6E171D00C2D4F1 /* Info-OSX.plist */, + 030B6CDC1A6E171D00C2D4F1 /* Info-macOS.plist */, E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */, 7236B4F71BAC14150020529B /* Info-tvOS.plist */, ); From f70af920fa12eccea13330ea66a1033445ab97cd Mon Sep 17 00:00:00 2001 From: Anton Lindroth Date: Sun, 15 Oct 2017 17:47:11 +0200 Subject: [PATCH 401/470] Fixed name in licenses --- Example/Example/AppDelegate.swift | 2 +- Example/Example/ViewController.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index 4e1880b0..e2af9aa6 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -1,4 +1,4 @@ -// SwiftyJSON.h +// AppDelegate.swift // // Copyright (c) 2014 - 2016 Pinglin Tang // diff --git a/Example/Example/ViewController.swift b/Example/Example/ViewController.swift index 1c584824..8f297a7b 100644 --- a/Example/Example/ViewController.swift +++ b/Example/Example/ViewController.swift @@ -1,4 +1,4 @@ -// SwiftyJSON.h +// ViewController.swift // // Copyright (c) 2014 - 2016 Pinglin Tang // From 030c1a9aa9e80b25172eec5f03e33b513a127358 Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Sun, 22 Oct 2017 10:52:04 +0900 Subject: [PATCH 402/470] Update deprecated examples and comments to fit the style Fix wrong examples of Raw object section, NilLiteral. --- README.md | 116 +++++++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 202d825d..050fca1f 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ if let userName = json[999999]["wrong_key"]["wrong_name"].string { #### CocoaPods (iOS 8+, OS X 10.9+) -You can use [CocoaPods](http://cocoapods.org/) to install `SwiftyJSON`by adding it to your `Podfile`: +You can use [CocoaPods](http://cocoapods.org/) to install `SwiftyJSON` by adding it to your `Podfile`: ```ruby platform :ios, '8.0' @@ -159,37 +159,37 @@ if let dataFromString = jsonString.data(using: .utf8, allowLossyConversion: fals #### Subscript ```swift -//Getting a double from a JSON Array +// Getting a double from a JSON Array let name = json[0].double ``` ```swift -//Getting an array of string from a JSON Array +// Getting an array of string from a JSON Array let arrayNames = json["users"].arrayValue.map({$0["name"].stringValue}) ``` ```swift -//Getting a string from a JSON Dictionary +// Getting a string from a JSON Dictionary let name = json["name"].stringValue ``` ```swift -//Getting a string using a path to the element +// Getting a string using a path to the element let path: [JSONSubscriptType] = [1,"list",2,"name"] let name = json[path].string -//Just the same +// Just the same let name = json[1]["list"][2]["name"].string -//Alternatively +// Alternatively let name = json[1,"list",2,"name"].string ``` ```swift -//With a hard way +// With a hard way let name = json[].string ``` ```swift -//With a custom way +// With a custom way let keys:[SubscriptType] = [1,"list",2,"name"] let name = json[keys].string ``` @@ -197,19 +197,19 @@ let name = json[keys].string #### Loop ```swift -//If json is .Dictionary +// If json is .Dictionary for (key,subJson):(String, JSON) in json { - //Do something you want + // Do something you want } ``` *The first element is always a String, even if the JSON is an Array* ```swift -//If json is .Array -//The `index` is 0.. = json["list"].arrayValue ``` ```swift -//If not a Dictionary or nil, return [:] +// If not a Dictionary or nil, return [:] let user: Dictionary = json["user"].dictionaryValue ``` @@ -351,31 +351,36 @@ json.dictionaryObject = ["name":"Jack", "age":25] #### Raw object ```swift -let jsonObject: Any = json.object +let rawObject: Any = json.object ``` ```swift -if let jsonObject: Any = json.rawValue +let rawValue: Any = json.rawValue ``` ```swift //convert the JSON to raw NSData -if let data = json.rawData() { - //Do something you want +do { + let rawData = try json.rawData() + //Do something you want +} catch { + print("Error \(error)") } ``` ```swift //convert the JSON to a raw String -if let string = json.rawString() { - //Do something you want +if let rawString = json.rawString() { + //Do something you want +} else { + print("json.rawString is nil") } ``` #### Existence ```swift -//shows you whether value specified in JSON or not +// shows you whether value specified in JSON or not if json["name"].exists() ``` @@ -384,59 +389,54 @@ if json["name"].exists() For more info about literal convertibles: [Swift Literal Convertibles](http://nshipster.com/swift-literal-convertible/) ```swift -//StringLiteralConvertible +// StringLiteralConvertible let json: JSON = "I'm a json" ``` ```swift -//IntegerLiteralConvertible +/ /IntegerLiteralConvertible let json: JSON = 12345 ``` ```swift -//BooleanLiteralConvertible +// BooleanLiteralConvertible let json: JSON = true ``` ```swift -//FloatLiteralConvertible +// FloatLiteralConvertible let json: JSON = 2.8765 ``` ```swift -//DictionaryLiteralConvertible +// DictionaryLiteralConvertible let json: JSON = ["I":"am", "a":"json"] ``` ```swift -//ArrayLiteralConvertible +// ArrayLiteralConvertible let json: JSON = ["I", "am", "a", "json"] ``` ```swift -//NilLiteralConvertible -let json: JSON = nil -``` - -```swift -//With subscript in array +// With subscript in array var json: JSON = [1,2,3] json[0] = 100 json[1] = 200 json[2] = 300 -json[999] = 300 //Don't worry, nothing will happen +json[999] = 300 // Don't worry, nothing will happen ``` ```swift -//With subscript in dictionary +// With subscript in dictionary var json: JSON = ["name": "Jack", "age": 25] json["name"] = "Mike" -json["age"] = "25" //It's OK to set String +json["age"] = "25" // It's OK to set String json["address"] = "L.A." // Add the "address": "L.A." in json ``` ```swift -//Array & Dictionary +// Array & Dictionary var json: JSON = ["name": "Jack", "age": 25, "list": ["a", "b", "c", ["what": "this"]]] json["list"][3]["what"] = "that" json["list",3,"what"] = "that" @@ -445,7 +445,7 @@ json[path] = "that" ``` ```swift -//With other JSON objects +// With other JSON objects let user: JSON = ["username" : "Steve", "password": "supersecurepassword"] let auth: JSON = [ "user": user.object //use user.object instead of just user From 1c5e98704e10766f06c05aae8df18eaf4cfb3803 Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Tue, 24 Oct 2017 20:49:32 +0900 Subject: [PATCH 403/470] Update README.md Fix typos --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 050fca1f..4681ca9f 100644 --- a/README.md +++ b/README.md @@ -448,7 +448,7 @@ json[path] = "that" // With other JSON objects let user: JSON = ["username" : "Steve", "password": "supersecurepassword"] let auth: JSON = [ - "user": user.object //use user.object instead of just user + "user": user.object, // use user.object instead of just user "apikey": "supersecretapitoken" ] ``` From f730539ce4c30ed843b93f91a8140c486d283742 Mon Sep 17 00:00:00 2001 From: Jeff Gu Kang Date: Tue, 24 Oct 2017 21:46:42 +0900 Subject: [PATCH 404/470] Update the playground documentation Add all sections of usage. --- Example/Playground.playground/Contents.swift | 436 ++++++++++++++++--- 1 file changed, 377 insertions(+), 59 deletions(-) diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index e29d56ba..7069ef07 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -1,98 +1,416 @@ //: Playground - noun: a place where people can play /*: - # SwiftyJSON - SwiftyJSON makes it easy to deal with JSON data in Swift. - - You must have to build `SwiftyJSON iOS` package for import. - */ -/*: - ### Basic setting for playground - */ +# SwiftyJSON +SwiftyJSON makes it easy to deal with JSON data in Swift. + +You must have to build `SwiftyJSON iOS` package for import. +*/ +/*: +### Basic setting for playground +*/ import SwiftyJSON import Foundation var jsonData: Data? if let file = Bundle.main.path(forResource: "SwiftyJSONTests", ofType: "json") { - jsonData = try? Data(contentsOf: URL(fileURLWithPath: file)) + jsonData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { - print("Fail") + print("Fail") } -let jsonObject = try JSONSerialization.jsonObject(with: jsonData!, options: .allowFragments) as? [[String: AnyObject]] +let jsonObject = try JSONSerialization.jsonObject(with: jsonData!, options: .allowFragments) let jsonString = String(data: jsonData!, encoding: .utf8) /*: - ## Usage - - ### Initialization - - */ +## Usage + +### Initialization + +*/ import SwiftyJSON let json1 = try? JSON(data: jsonData!) /*: - or - */ +or +*/ let json2 = JSON(jsonObject) /*: - or - */ +or +*/ let dataFromString = jsonString?.data(using: .utf8) let json3 = try? JSON(data: dataFromString!) /*: - ### Subscript - */ +### Subscript +*/ // Example json -var jsonArray: JSON = [ - "array": [12.34, 56.78], - "users": [ - [ - "id": 987654, - "info": [ - "name": "jack", - "email": "jack@gmail.com" - ], - "feeds": [98833, 23443, 213239, 23232] - ], - [ - "id": 654321, - "info": [ - "name": "jeffgukang", - "email": "jeffgukang@gmail.com" - ], - "feeds": [12345, 56789, 12423, 12412] - ] - ] -] - -var jsonDictionary: JSON = [ - "name": "jeffgukang", - "country": "South Korea" -] +let json: JSON = JSON([ + "array": [12.34, 56.78], + "users": [ + [ + "id": 987654, + "info": [ + "name": "jack", + "email": "jack@gmail.com" + ], + "feeds": [98833, 23443, 213239, 23232] + ], + [ + "id": 654321, + "info": [ + "name": "jeffgukang", + "email": "jeffgukang@gmail.com" + ], + "feeds": [12345, 56789, 12423, 12412] + ] + ] + ]) // Getting a double from a JSON Array -jsonArray["array"][0].double +json["array"][0].double // Getting an array of string from a JSON Array -let arrayOfString = jsonArray["users"].arrayValue.map({$0["info"]["name"]}) +let arrayOfString = json["users"].arrayValue.map({$0["info"]["name"]}) print(arrayOfString) // Getting a string from a JSON Dictionary -jsonDictionary["country"].stringValue +json["users"][0]["info"]["name"].stringValue -//Getting a string using a path to the element +// Getting a string using a path to the element let path = ["users", 1, "info", "name"] as [JSONSubscriptType] -var name = jsonArray["users", 1, "info", "name"].string +var name = json["users", 1, "info", "name"].string -//With a custom way +// With a custom way let keys: [JSONSubscriptType] = ["users", 1, "info", "name"] -name = jsonArray[keys].string +name = json[keys].string + +// Just the same +name = json["users"][1]["info"]["name"].string + +// Alternatively +name = json["users", 1, "info", "name"].string + +/*: +### Loop +*/ +// If json is .Dictionary +for (key, subJson):(String, JSON) in json { + //Do something you want + print(key) + print(subJson) +} + +/*The first element is always a String, even if the JSON is an Array*/ +//If json is .Array +//The `index` is 0.. Date: Tue, 24 Oct 2017 21:55:35 +0900 Subject: [PATCH 405/470] Fix violations --- Example/Playground.playground/Contents.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index 7069ef07..134a640c 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -319,13 +319,13 @@ let jsonLiteralBool: JSON = true let jsonLiteralFloat: JSON = 2.8765 // DictionaryLiteralConvertible -let jsonLiteralDictionary: JSON = ["I":"am", "a":"json"] +let jsonLiteralDictionary: JSON = ["I": "am", "a": "json"] // ArrayLiteralConvertible let jsonLiteralArray: JSON = ["I", "am", "a", "json"] // With subscript in array -var jsonSubscriptArray: JSON = [1,2,3] +var jsonSubscriptArray: JSON = [1, 2, 3] jsonSubscriptArray[0] = 100 jsonSubscriptArray[1] = 200 jsonSubscriptArray[2] = 300 @@ -340,13 +340,13 @@ jsonSubscriptDictionary["address"] = "L.A" // Add the "address": "L.A." in json // Array & Dictionary var jsonArrayDictionary: JSON = ["name": "Jack", "age": 25, "list": ["a", "b", "c", ["what": "this"]]] jsonArrayDictionary["list"][3]["what"] = "that" -jsonArrayDictionary["list",3,"what"] = "that" +jsonArrayDictionary["list", 3, "what"] = "that" -let arrayDictionarypath: [JSONSubscriptType] = ["list",3,"what"] +let arrayDictionarypath: [JSONSubscriptType] = ["list", 3, "what"] jsonArrayDictionary[arrayDictionarypath] = "that" // With other JSON objects -let user: JSON = ["username" : "Steve", "password": "supersecurepassword"] +let user: JSON = ["username": "Steve", "password": "supersecurepassword"] let auth: JSON = [ "user": user.object, //use user.object instead of just user "apikey": "supersecretapitoken" @@ -372,7 +372,7 @@ var original: JSON = [ "skills": ["Coding", "Reading"], "address": [ "street": "Front St", - "zip": "12345", + "zip": "12345" ] ] @@ -408,7 +408,7 @@ There are two options available: - use a custom one that will handle optionals well and represent nil as "null": */ -let stringRepresentationDict = ["1":2, "2":"two", "3": nil] as [String: Any?] +let stringRepresentationDict = ["1": 2, "2": "two", "3": nil] as [String: Any?] let stringRepresentionJson: JSON = JSON(stringRepresentationDict) let representation = stringRepresentionJson.rawString([.castNilToNSNull: true]) print(representation!) From c108f95c6c3a385153c437e4ecdc6c136cc79fb0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 7 Nov 2017 19:03:43 +0800 Subject: [PATCH 406/470] Format code documentation --- Source/SwiftyJSON.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index b2c17020..bc2ed6f5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -24,11 +24,11 @@ import Foundation // MARK: - Error // swiftlint:disable line_length -///Error domain +/// Error domain @available(*, deprecated, message: "ErrorDomain is deprecated. Use `SwiftyJSONError.errorDomain` instead.", renamed: "SwiftyJSONError.errorDomain") public let ErrorDomain: String = "SwiftyJSONErrorDomain" -///Error code +/// Error code @available(*, deprecated, message: "ErrorUnsupportedType is deprecated. Use `SwiftyJSONError.unsupportedType` instead.", renamed: "SwiftyJSONError.unsupportedType") public let ErrorUnsupportedType: Int = 999 @available(*, deprecated, message: "ErrorIndexOutOfBounds is deprecated. Use `SwiftyJSONError.indexOutOfBounds` instead.", renamed: "SwiftyJSONError.indexOutOfBounds") @@ -51,10 +51,13 @@ public enum SwiftyJSONError: Int, Swift.Error { extension SwiftyJSONError: CustomNSError { + /// return the error domain of SwiftyJSONError public static var errorDomain: String { return "com.swiftyjson.SwiftyJSON" } + /// return the error code of SwiftyJSONError public var errorCode: Int { return self.rawValue } + /// return the userInfo of SwiftyJSONError public var errorUserInfo: [String : Any] { switch self { case .unsupportedType: @@ -195,9 +198,11 @@ public struct JSON { return merged } - // Private woker function which does the actual merging - // Typecheck is set to true for the first recursion level to prevent total override of the source JSON - fileprivate mutating func merge(with other: JSON, typecheck: Bool) throws { + /** + Private woker function which does the actual merging + Typecheck is set to true for the first recursion level to prevent total override of the source JSON + */ + fileprivate mutating func merge(with other: JSON, typecheck: Bool) throws { if self.type == other.type { switch self.type { case .dictionary: From 73966c08057721bdf0c05d741ebd3099f1b4269f Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 7 Nov 2017 22:10:44 +0800 Subject: [PATCH 407/470] Code base improvement --- Source/SwiftyJSON.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index bc2ed6f5..203bc72d 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -292,7 +292,7 @@ public struct JSON { public static var null: JSON { return JSON(NSNull()) } } -// unwrap nested JSON +/// Private method to unwarp an object recursively private func unwrap(_ object: Any) -> Any { switch object { case let json as JSON: @@ -510,7 +510,8 @@ extension JSON { case 1: self[sub:path[0]].object = newValue.object default: - var aPath = path; aPath.remove(at: 0) + var aPath = path + aPath.remove(at: 0) var nextJSON = self[sub: path[0]] nextJSON[aPath] = newValue self[sub: path[0]] = nextJSON @@ -647,9 +648,7 @@ extension JSON: Swift.RawRepresentable { } fileprivate func _rawString(_ encoding: String.Encoding = .utf8, options: [writingOptionsKeys: Any], maxObjectDepth: Int = 10) throws -> String? { - if maxObjectDepth < 0 { - throw SwiftyJSONError.invalidJSON - } + guard maxObjectDepth > 0 else { throw SwiftyJSONError.invalidJSON } switch self.type { case .dictionary: do { From 89361aec8b87bc5ae4f59b9943fce44f1b7e3d68 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 7 Nov 2017 22:27:11 +0800 Subject: [PATCH 408/470] Fix SwiftLint violations --- Source/SwiftyJSON.swift | 26 +++++++++---------- Tests/SwiftyJSONTests/BaseTests.swift | 4 +-- Tests/SwiftyJSONTests/ComparableTests.swift | 24 ++++++++--------- Tests/SwiftyJSONTests/DictionaryTests.swift | 6 ++--- Tests/SwiftyJSONTests/MutabilityTests.swift | 2 +- Tests/SwiftyJSONTests/NestedJSONTests.swift | 2 +- Tests/SwiftyJSONTests/NumberTests.swift | 4 +-- Tests/SwiftyJSONTests/PerformanceTests.swift | 4 +-- Tests/SwiftyJSONTests/PrintableTests.swift | 2 +- Tests/SwiftyJSONTests/SequenceTypeTests.swift | 14 +++++----- Tests/SwiftyJSONTests/StringTests.swift | 2 +- Tests/SwiftyJSONTests/SubscriptTests.swift | 4 +-- 12 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 203bc72d..312763e4 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -58,7 +58,7 @@ extension SwiftyJSONError: CustomNSError { public var errorCode: Int { return self.rawValue } /// return the userInfo of SwiftyJSONError - public var errorUserInfo: [String : Any] { + public var errorUserInfo: [String: Any] { switch self { case .unsupportedType: return [NSLocalizedDescriptionKey: "It is an unsupported type."] @@ -225,7 +225,7 @@ public struct JSON { /// Private object fileprivate var rawArray: [Any] = [] - fileprivate var rawDictionary: [String : Any] = [:] + fileprivate var rawDictionary: [String: Any] = [:] fileprivate var rawString: String = "" fileprivate var rawNumber: NSNumber = 0 fileprivate var rawNull: NSNull = NSNull() @@ -276,7 +276,7 @@ public struct JSON { case let array as [Any]: type = .array self.rawArray = array - case let dictionary as [String : Any]: + case let dictionary as [String: Any]: type = .dictionary self.rawDictionary = dictionary default: @@ -299,7 +299,7 @@ private func unwrap(_ object: Any) -> Any { return unwrap(json.object) case let array as [Any]: return array.map(unwrap) - case let dictionary as [String : Any]: + case let dictionary as [String: Any]: var unwrappedDic = dictionary for (k, v) in dictionary { unwrappedDic[k] = unwrap(v) @@ -650,7 +650,7 @@ extension JSON: Swift.RawRepresentable { fileprivate func _rawString(_ encoding: String.Encoding = .utf8, options: [writingOptionsKeys: Any], maxObjectDepth: Int = 10) throws -> String? { guard maxObjectDepth > 0 else { throw SwiftyJSONError.invalidJSON } switch self.type { - case .dictionary: + case .dictionary: do { if !(options[.castNilToNSNull] as? Bool ?? false) { let jsonOption = options[.jsonSerialization] as? JSONSerialization.WritingOptions ?? JSONSerialization.WritingOptions.prettyPrinted @@ -684,7 +684,7 @@ extension JSON: Swift.RawRepresentable { } catch _ { return nil } - case .array: + case .array: do { if !(options[.castNilToNSNull] as? Bool ?? false) { let jsonOption = options[.jsonSerialization] as? JSONSerialization.WritingOptions ?? JSONSerialization.WritingOptions.prettyPrinted @@ -734,7 +734,7 @@ extension JSON: Swift.RawRepresentable { extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertible { public var description: String { - if let string = self.rawString(options:.prettyPrinted) { + if let string = self.rawString(options: .prettyPrinted) { return string } else { return "unknown" @@ -789,7 +789,7 @@ extension JSON { extension JSON { //Optional [String : JSON] - public var dictionary: [String : JSON]? { + public var dictionary: [String: JSON]? { if self.type == .dictionary { var d = [String: JSON](minimumCapacity: rawDictionary.count) for (key, value) in rawDictionary { @@ -802,13 +802,13 @@ extension JSON { } //Non-optional [String : JSON] - public var dictionaryValue: [String : JSON] { + public var dictionaryValue: [String: JSON] { return self.dictionary ?? [:] } //Optional [String : Any] - public var dictionaryObject: [String : Any]? { + public var dictionaryObject: [String: Any]? { get { switch self.type { case .dictionary: @@ -886,7 +886,7 @@ extension JSON { } set { if let newValue = newValue { - self.object = NSString(string:newValue) + self.object = NSString(string: newValue) } else { self.object = NSNull() } @@ -908,7 +908,7 @@ extension JSON { } } set { - self.object = NSString(string:newValue) + self.object = NSString(string: newValue) } } } @@ -1282,7 +1282,7 @@ extension JSON { // MARK: - Comparable -extension JSON : Swift.Comparable {} +extension JSON: Swift.Comparable {} public func == (lhs: JSON, rhs: JSON) -> Bool { diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/SwiftyJSONTests/BaseTests.swift index 97877285..16dab02c 100644 --- a/Tests/SwiftyJSONTests/BaseTests.swift +++ b/Tests/SwiftyJSONTests/BaseTests.swift @@ -31,7 +31,7 @@ class BaseTests: XCTestCase { super.setUp() - if let file = Bundle(for:BaseTests.self).path(forResource: "Tests", ofType: "json") { + if let file = Bundle(for: BaseTests.self).path(forResource: "Tests", ofType: "json") { self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { XCTFail("Can't find the test JSON file") @@ -65,7 +65,7 @@ class BaseTests: XCTestCase { func testCompare() { XCTAssertNotEqual(JSON("32.1234567890"), JSON(32.1234567890)) let veryLargeNumber: UInt64 = 9876543210987654321 - XCTAssertNotEqual(JSON("9876543210987654321"), JSON(NSNumber(value:veryLargeNumber))) + XCTAssertNotEqual(JSON("9876543210987654321"), JSON(NSNumber(value: veryLargeNumber))) XCTAssertNotEqual(JSON("9876543210987654321.12345678901234567890"), JSON(9876543210987654321.12345678901234567890)) XCTAssertEqual(JSON("😊"), JSON("😊")) XCTAssertNotEqual(JSON("😱"), JSON("😁")) diff --git a/Tests/SwiftyJSONTests/ComparableTests.swift b/Tests/SwiftyJSONTests/ComparableTests.swift index 1f8343e9..a7b69086 100644 --- a/Tests/SwiftyJSONTests/ComparableTests.swift +++ b/Tests/SwiftyJSONTests/ComparableTests.swift @@ -36,8 +36,8 @@ class ComparableTests: XCTestCase { XCTAssertEqual(jsonL2, jsonR2) XCTAssertTrue(jsonR2 == 987654321) - let jsonL3: JSON = JSON(NSNumber(value:87654321.12345678)) - let jsonR3: JSON = JSON(NSNumber(value:87654321.12345678)) + let jsonL3: JSON = JSON(NSNumber(value: 87654321.12345678)) + let jsonR3: JSON = JSON(NSNumber(value: 87654321.12345678)) XCTAssertEqual(jsonL3, jsonR3) XCTAssertTrue(jsonR3 == 87654321.12345678) } @@ -53,8 +53,8 @@ class ComparableTests: XCTestCase { XCTAssertNotEqual(jsonL2, jsonR2) XCTAssertFalse(jsonR1 == 454352) - let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3: JSON = JSON(NSNumber(value:87654321.45678)) + let jsonL3: JSON = JSON(NSNumber(value: 87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value: 87654321.45678)) XCTAssertNotEqual(jsonL3, jsonR3) XCTAssertFalse(jsonL3 == 4545.232) } @@ -70,8 +70,8 @@ class ComparableTests: XCTestCase { XCTAssertGreaterThanOrEqual(jsonL2, jsonR2) XCTAssertTrue(jsonR2 >= -988343) - let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3: JSON = JSON(NSNumber(value:87621.12345678)) + let jsonL3: JSON = JSON(NSNumber(value: 87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value: 87621.12345678)) XCTAssertGreaterThanOrEqual(jsonL3, jsonR3) XCTAssertTrue(jsonR3 >= 0.3232) } @@ -87,8 +87,8 @@ class ComparableTests: XCTestCase { XCTAssertLessThanOrEqual(jsonR2, jsonL2) XCTAssertFalse(9348343 <= jsonR2) - let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3: JSON = JSON(NSNumber(value:87621.12345678)) + let jsonL3: JSON = JSON(NSNumber(value: 87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value: 87621.12345678)) XCTAssertLessThanOrEqual(jsonR3, jsonL3) XCTAssertTrue(87621.12345678 <= jsonR3) } @@ -104,8 +104,8 @@ class ComparableTests: XCTestCase { XCTAssertGreaterThan(jsonL2, jsonR2) XCTAssertFalse(jsonR2 > 877434) - let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3: JSON = JSON(NSNumber(value:87621.1234567)) + let jsonL3: JSON = JSON(NSNumber(value: 87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value: 87621.1234567)) XCTAssertGreaterThan(jsonL3, jsonR3) XCTAssertFalse(-7799 > jsonR3) } @@ -121,8 +121,8 @@ class ComparableTests: XCTestCase { XCTAssertLessThan(jsonR2, jsonL2) XCTAssertTrue(jsonR2 < 877434) - let jsonL3: JSON = JSON(NSNumber(value:87621.12345678)) - let jsonR3: JSON = JSON(NSNumber(value:87621.1234567)) + let jsonL3: JSON = JSON(NSNumber(value: 87621.12345678)) + let jsonR3: JSON = JSON(NSNumber(value: 87621.1234567)) XCTAssertLessThan(jsonR3, jsonL3) XCTAssertTrue(-7799 < jsonR3) } diff --git a/Tests/SwiftyJSONTests/DictionaryTests.swift b/Tests/SwiftyJSONTests/DictionaryTests.swift index 5d73f23b..dc89200e 100644 --- a/Tests/SwiftyJSONTests/DictionaryTests.swift +++ b/Tests/SwiftyJSONTests/DictionaryTests.swift @@ -26,7 +26,7 @@ import SwiftyJSON class DictionaryTests: XCTestCase { func testGetter() { - let dictionary = ["number": 9823.212, "name": "NAME", "list": [1234, 4.212], "object": ["sub_number": 877.2323, "sub_name": "sub_name"], "bool": true] as [String : Any] + let dictionary = ["number": 9823.212, "name": "NAME", "list": [1234, 4.212], "object": ["sub_number": 877.2323, "sub_name": "sub_name"], "bool": true] as [String: Any] let json = JSON(dictionary) //dictionary XCTAssertEqual((json.dictionary!["number"]! as JSON).double!, 9823.212) @@ -48,8 +48,8 @@ class DictionaryTests: XCTestCase { func testSetter() { var json: JSON = ["test": "case"] - XCTAssertEqual(json.dictionaryObject! as! [String : String], ["test": "case"]) + XCTAssertEqual(json.dictionaryObject! as! [String: String], ["test": "case"]) json.dictionaryObject = ["name": "NAME"] - XCTAssertEqual(json.dictionaryObject! as! [String : String], ["name": "NAME"]) + XCTAssertEqual(json.dictionaryObject! as! [String: String], ["name": "NAME"]) } } diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/SwiftyJSONTests/MutabilityTests.swift index 7f80c30b..cc1a5b2d 100644 --- a/Tests/SwiftyJSONTests/MutabilityTests.swift +++ b/Tests/SwiftyJSONTests/MutabilityTests.swift @@ -130,7 +130,7 @@ class MutabilityTests: XCTestCase { } func testDictionaryRemovability() { - let dictionary: [String : Any] = ["key1": "Value1", "key2": 2, "key3": true] + let dictionary: [String: Any] = ["key1": "Value1", "key2": 2, "key3": true] var json = JSON(dictionary) json.dictionaryObject?.removeValue(forKey: "key1") diff --git a/Tests/SwiftyJSONTests/NestedJSONTests.swift b/Tests/SwiftyJSONTests/NestedJSONTests.swift index e92084b7..167c6691 100644 --- a/Tests/SwiftyJSONTests/NestedJSONTests.swift +++ b/Tests/SwiftyJSONTests/NestedJSONTests.swift @@ -83,6 +83,6 @@ class NestedJSONTests: XCTestCase { "outer_field": foo, "inner_json": inner ]) - XCTAssertEqual(json2["inner_json"].rawValue as! [String : String], ["some_field": "12"]) + XCTAssertEqual(json2["inner_json"].rawValue as! [String: String], ["some_field": "12"]) } } diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/SwiftyJSONTests/NumberTests.swift index efd2378e..9f919ca3 100644 --- a/Tests/SwiftyJSONTests/NumberTests.swift +++ b/Tests/SwiftyJSONTests/NumberTests.swift @@ -109,12 +109,12 @@ class NumberTests: XCTestCase { json.double = 23231.65 XCTAssertTrue(json.float! == 23231.65) XCTAssertTrue(json.floatValue == 23231.65) - XCTAssertEqual(json.numberValue, NSNumber(value:23231.65)) + XCTAssertEqual(json.numberValue, NSNumber(value: 23231.65)) json.double = -98766.23 XCTAssertEqual(json.float!, -98766.23) XCTAssertEqual(json.floatValue, -98766.23) - XCTAssertEqual(json.numberValue, NSNumber(value:-98766.23)) + XCTAssertEqual(json.numberValue, NSNumber(value: -98766.23)) } func testInt() { diff --git a/Tests/SwiftyJSONTests/PerformanceTests.swift b/Tests/SwiftyJSONTests/PerformanceTests.swift index 72140b54..64de9e14 100644 --- a/Tests/SwiftyJSONTests/PerformanceTests.swift +++ b/Tests/SwiftyJSONTests/PerformanceTests.swift @@ -30,7 +30,7 @@ class PerformanceTests: XCTestCase { override func setUp() { super.setUp() - if let file = Bundle(for:PerformanceTests.self).path(forResource: "Tests", ofType: "json") { + if let file = Bundle(for: PerformanceTests.self).path(forResource: "Tests", ofType: "json") { self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { XCTFail("Can't find the test JSON file") @@ -61,7 +61,7 @@ class PerformanceTests: XCTestCase { } self.measure { for _ in 1...100 { - let object:Any? = json.object + let object: Any? = json.object XCTAssertTrue(object != nil) } } diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/SwiftyJSONTests/PrintableTests.swift index ebecbe1a..ba5863d1 100644 --- a/Tests/SwiftyJSONTests/PrintableTests.swift +++ b/Tests/SwiftyJSONTests/PrintableTests.swift @@ -98,7 +98,7 @@ class PrintableTests: XCTestCase { } func testDictionaryWithStrings() { - let dict = ["foo": "{\"bar\":123}"] as [String : Any] + let dict = ["foo": "{\"bar\":123}"] as [String: Any] let json = JSON(dict) var debugDescription = json.debugDescription.replacingOccurrences(of: "\n", with: "") debugDescription = debugDescription.replacingOccurrences(of: " ", with: "") diff --git a/Tests/SwiftyJSONTests/SequenceTypeTests.swift b/Tests/SwiftyJSONTests/SequenceTypeTests.swift index 488ea865..d0d8cadd 100644 --- a/Tests/SwiftyJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftyJSONTests/SequenceTypeTests.swift @@ -26,7 +26,7 @@ import SwiftyJSON class SequenceTypeTests: XCTestCase { func testJSONFile() { - if let file = Bundle(for:BaseTests.self).path(forResource: "Tests", ofType: "json") { + if let file = Bundle(for: BaseTests.self).path(forResource: "Tests", ofType: "json") { let testData = try? Data(contentsOf: URL(fileURLWithPath: file)) guard let json = try? JSON(data: testData!) else { XCTFail("Unable to parse the data") @@ -127,11 +127,11 @@ class SequenceTypeTests: XCTestCase { index += 1 } XCTAssertEqual(index, 3) - XCTAssertEqual((array[0] as! [String : Int])["1"]!, 1) - XCTAssertEqual((array[0] as! [String : Int])["2"]!, 2) - XCTAssertEqual((array[1] as! [String : String])["a"]!, "A") - XCTAssertEqual((array[1] as! [String : String])["b"]!, "B") - XCTAssertEqual((array[2] as! [String : NSNull])["null"]!, NSNull()) + XCTAssertEqual((array[0] as! [String: Int])["1"]!, 1) + XCTAssertEqual((array[0] as! [String: Int])["2"]!, 2) + XCTAssertEqual((array[1] as! [String: String])["a"]!, "A") + XCTAssertEqual((array[1] as! [String: String])["b"]!, "B") + XCTAssertEqual((array[2] as! [String: NSNull])["null"]!, NSNull()) } func testDictionaryAllNumber() { @@ -204,7 +204,7 @@ class SequenceTypeTests: XCTestCase { } func testDictionaryAllArray() { - var json: JSON = JSON (["Number": [NSNumber(value:1), NSNumber(value:2.123456), NSNumber(value:123456789)], "String": ["aa", "bbb", "cccc"], "Mix": [true, "766", NSNull(), 655231.9823]]) + var json: JSON = JSON (["Number": [NSNumber(value: 1), NSNumber(value: 2.123456), NSNumber(value: 123456789)], "String": ["aa", "bbb", "cccc"], "Mix": [true, "766", NSNull(), 655231.9823]]) XCTAssertEqual(json.count, 3) diff --git a/Tests/SwiftyJSONTests/StringTests.swift b/Tests/SwiftyJSONTests/StringTests.swift index fb226fc5..cde05672 100644 --- a/Tests/SwiftyJSONTests/StringTests.swift +++ b/Tests/SwiftyJSONTests/StringTests.swift @@ -38,7 +38,7 @@ class StringTests: XCTestCase { func testUrl() { let json = JSON("http://github.com") - XCTAssertEqual(json.url!, URL(string:"http://github.com")!) + XCTAssertEqual(json.url!, URL(string: "http://github.com")!) } func testBool() { diff --git a/Tests/SwiftyJSONTests/SubscriptTests.swift b/Tests/SwiftyJSONTests/SubscriptTests.swift index 0673f3a0..5b399f40 100644 --- a/Tests/SwiftyJSONTests/SubscriptTests.swift +++ b/Tests/SwiftyJSONTests/SubscriptTests.swift @@ -163,7 +163,7 @@ class SubscriptTests: XCTestCase { func testDictionaryAllArray() { //Swift bug: [1, 2.01,3.09] is convert to [1, 2, 3] (Array) - let json: JSON = JSON ([[NSNumber(value:1), NSNumber(value:2.123456), NSNumber(value:123456789)], ["aa", "bbb", "cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let json: JSON = JSON ([[NSNumber(value: 1), NSNumber(value: 2.123456), NSNumber(value: 123456789)], ["aa", "bbb", "cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertTrue(json[0] == [1, 2.123456, 123456789]) XCTAssertEqual(json[0][1].double!, 2.123456) XCTAssertTrue(json[0][2] == 123456789) @@ -180,7 +180,7 @@ class SubscriptTests: XCTestCase { } func testOutOfBounds() { - let json: JSON = JSON ([[NSNumber(value:1), NSNumber(value:2.123456), NSNumber(value:123456789)], ["aa", "bbb", "cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) + let json: JSON = JSON ([[NSNumber(value: 1), NSNumber(value: 2.123456), NSNumber(value: 123456789)], ["aa", "bbb", "cccc"], [true, "766", NSNull(), 655231.9823]] as NSArray) XCTAssertEqual(json[9], JSON.null) XCTAssertEqual(json[-2].error, SwiftyJSONError.indexOutOfBounds) XCTAssertEqual(json[6].error, SwiftyJSONError.indexOutOfBounds) From dd861383ba4f9b7859e378315c5d1b734dcbfe81 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 8 Nov 2017 13:32:30 +0800 Subject: [PATCH 409/470] Add .hound.yml --- .hound.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .hound.yml diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 00000000..b867fd9c --- /dev/null +++ b/.hound.yml @@ -0,0 +1,2 @@ +swift: + config_file: .swiftlint.yml From d9682fb9e722fc6aefe664ff7c87ee16a94df4fc Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 8 Nov 2017 17:11:34 +0800 Subject: [PATCH 410/470] Version bump to 4.0.0 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 76daf480..e5eba227 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "4.0.0-alpha.1" + s.version = "4.0.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From fb67763f27990ba76a42bf412f848af5aef5e5ea Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 8 Nov 2017 03:47:20 -0600 Subject: [PATCH 411/470] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 4681ca9f..3d3e75ef 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,6 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. 5. [Work with Alamofire](#work-with-alamofire) 6. [Work with Moya](#work-with-moya) -> For Legacy Swift support, take a look at the [swift2 branch](https://github.com/SwiftyJSON/SwiftyJSON/tree/swift2) - > [中文介绍](http://tangplin.github.io/swiftyjson/) @@ -92,7 +90,7 @@ platform :ios, '8.0' use_frameworks! target 'MyApp' do - pod 'SwiftyJSON' + pod 'SwiftyJSON' end ``` From da527cf88a1661ac369bf0df889353c10bee26ae Mon Sep 17 00:00:00 2001 From: Tom Duncalf Date: Tue, 16 Jan 2018 21:54:12 +0100 Subject: [PATCH 412/470] Update README to specify correct JSONSubscriptType --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3d3e75ef..35355ff8 100644 --- a/README.md +++ b/README.md @@ -188,7 +188,7 @@ let name = json[].string ```swift // With a custom way -let keys:[SubscriptType] = [1,"list",2,"name"] +let keys:[JSONSubscriptType] = [1,"list",2,"name"] let name = json[keys].string ``` From 38d9815729537f18fe09310b839edb622bfb8c08 Mon Sep 17 00:00:00 2001 From: Lei Wang Date: Tue, 9 Jan 2018 21:08:32 +0800 Subject: [PATCH 413/470] Support Codable --- Example/Playground.playground/Contents.swift | 1 - Source/SwiftyJSON.swift | 134 +++++++++++++++++-- SwiftyJSON.xcodeproj/project.pbxproj | 8 ++ Tests/SwiftyJSONTests/CodableTests.swift | 100 ++++++++++++++ 4 files changed, 228 insertions(+), 15 deletions(-) create mode 100644 Tests/SwiftyJSONTests/CodableTests.swift diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index 134a640c..9306d850 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -413,4 +413,3 @@ let stringRepresentionJson: JSON = JSON(stringRepresentationDict) let representation = stringRepresentionJson.rawString([.castNilToNSNull: true]) print(representation!) // representation is "{\"1\":2,\"2\":\"two\",\"3\":null}", which represents {"1":2,"2":"two","3":null} - diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index 312763e4..f3553fe5 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -545,53 +545,50 @@ extension JSON { extension JSON: Swift.ExpressibleByStringLiteral { public init(stringLiteral value: StringLiteralType) { - self.init(value as Any) + self.init(value) } public init(extendedGraphemeClusterLiteral value: StringLiteralType) { - self.init(value as Any) + self.init(value) } public init(unicodeScalarLiteral value: StringLiteralType) { - self.init(value as Any) + self.init(value) } } extension JSON: Swift.ExpressibleByIntegerLiteral { public init(integerLiteral value: IntegerLiteralType) { - self.init(value as Any) + self.init(value) } } extension JSON: Swift.ExpressibleByBooleanLiteral { public init(booleanLiteral value: BooleanLiteralType) { - self.init(value as Any) + self.init(value) } } extension JSON: Swift.ExpressibleByFloatLiteral { public init(floatLiteral value: FloatLiteralType) { - self.init(value as Any) + self.init(value) } } extension JSON: Swift.ExpressibleByDictionaryLiteral { public init(dictionaryLiteral elements: (String, Any)...) { - var dictionary = [String: Any](minimumCapacity: elements.count) - for (k, v) in elements { - dictionary[k] = v - } - self.init(dictionary as Any) + let dictionary = elements.reduce(into: [String: Any](), { $0[$1.0] = $1.1}) + self.init(dictionary) } } extension JSON: Swift.ExpressibleByArrayLiteral { public init(arrayLiteral elements: Any...) { - self.init(elements as Any) + self.init(elements) } } @@ -776,7 +773,7 @@ extension JSON { } set { if let array = newValue { - self.object = array as Any + self.object = array } else { self.object = NSNull() } @@ -819,7 +816,7 @@ extension JSON { } set { if let v = newValue { - self.object = v as Any + self.object = v } else { self.object = NSNull() } @@ -1455,3 +1452,112 @@ public enum writingOptionsKeys { case maxObjextDepth case encoding } + +// MARK: - JSON: Codable +extension JSON: Codable { + private static var codableTypes: [Codable.Type] { + return [ + Bool.self, + Int.self, + Int8.self, + Int16.self, + Int32.self, + Int64.self, + UInt.self, + UInt8.self, + UInt16.self, + UInt32.self, + UInt64.self, + Double.self, + String.self, + [JSON].self, + [String: JSON].self + ] + } + public init(from decoder: Decoder) throws { + var object: Any? + + if let container = try? decoder.singleValueContainer(), !container.decodeNil() { + for type in JSON.codableTypes { + if object != nil { + break + } + // try to decode value + switch type { + case let boolType as Bool.Type: + object = try? container.decode(boolType) + case let intType as Int.Type: + object = try? container.decode(intType) + case let int8Type as Int8.Type: + object = try? container.decode(int8Type) + case let int32Type as Int32.Type: + object = try? container.decode(int32Type) + case let int64Type as Int64.Type: + object = try? container.decode(int64Type) + case let uintType as UInt.Type: + object = try? container.decode(uintType) + case let uint8Type as UInt8.Type: + object = try? container.decode(uint8Type) + case let uint16Type as UInt16.Type: + object = try? container.decode(uint16Type) + case let uint32Type as UInt32.Type: + object = try? container.decode(uint32Type) + case let uint64Type as UInt64.Type: + object = try? container.decode(uint64Type) + case let doubleType as Double.Type: + object = try? container.decode(doubleType) + case let stringType as String.Type: + object = try? container.decode(stringType) + case let jsonValueArrayType as [JSON].Type: + object = try? container.decode(jsonValueArrayType) + case let jsonValueDictType as [String: JSON].Type: + object = try? container.decode(jsonValueDictType) + default: + break + } + } + } + self.init(object ?? NSNull()) + } + public func encode(to encoder: Encoder) throws { + var container = encoder.singleValueContainer() + if object is NSNull { + try container.encodeNil() + return + } + switch object { + case let intValue as Int: + try container.encode(intValue) + case let int8Value as Int8: + try container.encode(int8Value) + case let int32Value as Int32: + try container.encode(int32Value) + case let int64Value as Int64: + try container.encode(int64Value) + case let uintValue as UInt: + try container.encode(uintValue) + case let uint8Value as UInt8: + try container.encode(uint8Value) + case let uint16Value as UInt16: + try container.encode(uint16Value) + case let uint32Value as UInt32: + try container.encode(uint32Value) + case let uint64Value as UInt64: + try container.encode(uint64Value) + case let doubleValue as Double: + try container.encode(doubleValue) + case let boolValue as Bool: + try container.encode(boolValue) + case let stringValue as String: + try container.encode(stringValue) + case is [Any]: + let jsonValueArray = array ?? [] + try container.encode(jsonValueArray) + case is [String: Any]: + let jsonValueDictValue = dictionary ?? [:] + try container.encode(jsonValueDictValue) + default: + break + } + } +} diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 32d607b2..494fb964 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -29,6 +29,9 @@ 5DD502911D9B21810004C112 /* NestedJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD502901D9B21810004C112 /* NestedJSONTests.swift */; }; 5DD502921D9B21810004C112 /* NestedJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD502901D9B21810004C112 /* NestedJSONTests.swift */; }; 5DD502931D9B21810004C112 /* NestedJSONTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5DD502901D9B21810004C112 /* NestedJSONTests.swift */; }; + 712921EF2004E4EB00DA6340 /* CodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712921EE2004E4EB00DA6340 /* CodableTests.swift */; }; + 712921F02004E4EB00DA6340 /* CodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712921EE2004E4EB00DA6340 /* CodableTests.swift */; }; + 712921F12004E4EB00DA6340 /* CodableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 712921EE2004E4EB00DA6340 /* CodableTests.swift */; }; 7236B4EE1BAC14150020529B /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; 7236B4F11BAC14150020529B /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; 9C459EF41A910334008C9A41 /* SwiftyJSON.h in Headers */ = {isa = PBXBuildFile; fileRef = 2E4FEFE019575BE100351305 /* SwiftyJSON.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -117,6 +120,7 @@ 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 5DD502901D9B21810004C112 /* NestedJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedJSONTests.swift; sourceTree = ""; }; + 712921EE2004E4EB00DA6340 /* CodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableTests.swift; sourceTree = ""; }; 7236B4F61BAC14150020529B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = ""; }; @@ -265,6 +269,7 @@ A8B66C8B19E51D6500540692 /* DictionaryTests.swift */, A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */, A8B66C8D19E52F4200540692 /* ArrayTests.swift */, + 712921EE2004E4EB00DA6340 /* CodableTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); name = SwiftyJSONTests; @@ -604,6 +609,7 @@ A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */, A830A6951E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */, A863BE2819EED46F0092A41F /* RawTests.swift in Sources */, + 712921EF2004E4EB00DA6340 /* CodableTests.swift in Sources */, A885D1D219CF1EE6002FD4C3 /* BaseTests.swift in Sources */, A8B66C8E19E52F4200540692 /* ArrayTests.swift in Sources */, A8B66C8C19E51D6500540692 /* DictionaryTests.swift in Sources */, @@ -643,6 +649,7 @@ 9C459EFA1A9103C1008C9A41 /* BaseTests.swift in Sources */, A830A6961E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */, 9C459F041A9103C1008C9A41 /* DictionaryTests.swift in Sources */, + 712921F02004E4EB00DA6340 /* CodableTests.swift in Sources */, 9C459EF91A9103C1008C9A41 /* PerformanceTests.swift in Sources */, 9C459EFE1A9103C1008C9A41 /* LiteralConvertibleTests.swift in Sources */, 9C459EFC1A9103C1008C9A41 /* PrintableTests.swift in Sources */, @@ -666,6 +673,7 @@ A8580F841BCF69A000DA927B /* SubscriptTests.swift in Sources */, A830A6971E5B2DD8001D7F6D /* MutabilityTests.swift in Sources */, A8580F851BCF69A000DA927B /* LiteralConvertibleTests.swift in Sources */, + 712921F12004E4EB00DA6340 /* CodableTests.swift in Sources */, A8580F861BCF69A000DA927B /* RawRepresentableTests.swift in Sources */, A8580F871BCF69A000DA927B /* ComparableTests.swift in Sources */, A8580F881BCF69A000DA927B /* StringTests.swift in Sources */, diff --git a/Tests/SwiftyJSONTests/CodableTests.swift b/Tests/SwiftyJSONTests/CodableTests.swift new file mode 100644 index 00000000..9cc43eaa --- /dev/null +++ b/Tests/SwiftyJSONTests/CodableTests.swift @@ -0,0 +1,100 @@ +// CodableTests.swift +// +// Created by Lei Wang on 2018/1/9. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import XCTest +import SwiftyJSON + +class CodableTests: XCTestCase { + + func testEncodeNull() { + var json = JSON([NSNull()]) + _ = try! JSONEncoder().encode(json) + json = JSON([nil]) + _ = try! JSONEncoder().encode(json) + let dictionary: [String: Any?] = ["key": nil] + json = JSON(dictionary) + _ = try! JSONEncoder().encode(json) + } + func testArrayCodable() { + let jsonString = """ + [1,"false", ["A", 4.3231],"3",true] + """ + var data = jsonString.data(using: .utf8)! + let json = try! JSONDecoder().decode(JSON.self, from: data) + XCTAssertEqual(json.arrayValue.first?.int, 1) + XCTAssertEqual(json[1].bool, nil) + XCTAssertEqual(json[1].string, "false") + XCTAssertEqual(json[3].string, "3") + XCTAssertEqual(json[2][1].double!, 4.3231) + XCTAssertEqual(json.arrayValue[0].bool, nil) + XCTAssertEqual(json.array!.last!.bool, true) + let jsonList = try! JSONDecoder().decode([JSON].self, from: data) + XCTAssertEqual(jsonList.first?.int, 1) + XCTAssertEqual(jsonList.last!.bool, true) + data = try! JSONEncoder().encode(json) + let list = try! JSONSerialization.jsonObject(with: data, options: []) as! [Any] + XCTAssertEqual(list[0] as! Int, 1) + XCTAssertEqual((list[2] as! [Any])[1] as! Float, 4.3231) + } + func testDictionaryCodable() { + let dictionary: [String: Any] = ["number": 9823.212, "name": "NAME", "list": [1234, 4.21223256], "object": ["sub_number": 877.2323, "sub_name": "sub_name"], "bool": true] + var data = try! JSONSerialization.data(withJSONObject: dictionary, options: []) + let json = try! JSONDecoder().decode(JSON.self, from: data) + XCTAssertNotNil(json.dictionary) + XCTAssertEqual(json["number"].float, 9823.212) + XCTAssertEqual(json["list"].arrayObject is [Float], true) + XCTAssertEqual(json["object"]["sub_number"].float, 877.2323) + XCTAssertEqual(json["bool"].bool, true) + let jsonDict = try! JSONDecoder().decode([String: JSON].self, from: data) + XCTAssertEqual(jsonDict["number"]?.int, 9823) + XCTAssertEqual(jsonDict["object"]?["sub_name"], "sub_name") + data = try! JSONEncoder().encode(json) + var encoderDict = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any] + XCTAssertEqual(encoderDict["list"] as! [Float], [1234, 4.21223256]) + XCTAssertEqual(encoderDict["bool"] as! Bool, true) + data = try! JSONEncoder().encode(jsonDict) + encoderDict = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any] + XCTAssertEqual(encoderDict["name"] as! String, dictionary["name"] as! String) + XCTAssertEqual((encoderDict["object"] as! [String: Any])["sub_number"] as! Float, 877.2323) + } + func testCodableModel() { + struct CodableModel: Codable { + let name: String + let number: Double + let bool: Bool + let list: [Double] + private let object: JSON + var subName: String? { + return object["sub_name"].string + } + } + let dictionary: [String: Any] = [ + "number": 9823.212, + "name": "NAME", + "list": [1234, 4.21223256], + "object": ["sub_number": 877.2323, "sub_name": "sub_name"], + "bool": true] + let data = try! JSONSerialization.data(withJSONObject: dictionary, options: []) + let model = try! JSONDecoder().decode(CodableModel.self, from: data) + XCTAssertEqual(model.subName, "sub_name") + } +} From 481ba1eb19f2efdbf58b7f3daf2bf4ad9d1291dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ota=CC=81vio=20Lima?= Date: Wed, 28 Mar 2018 20:33:17 +0300 Subject: [PATCH 414/470] Add String to .boolValue tests for "Yes" and "1" --- Tests/SwiftyJSONTests/StringTests.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Tests/SwiftyJSONTests/StringTests.swift b/Tests/SwiftyJSONTests/StringTests.swift index cde05672..9ce10643 100644 --- a/Tests/SwiftyJSONTests/StringTests.swift +++ b/Tests/SwiftyJSONTests/StringTests.swift @@ -56,6 +56,16 @@ class StringTests: XCTestCase { XCTAssertTrue(json.boolValue) } + func testBoolWithYes() { + let json = JSON("Yes") + XCTAssertTrue(json.boolValue) + } + + func testBoolWith1() { + let json = JSON("1") + XCTAssertTrue(json.boolValue) + } + func testUrlPercentEscapes() { let emDash = "\\u2014" let urlString = "http://examble.com/unencoded" + emDash + "string" From bbd9abff2c86a65ea6d63eaf526eb7dc0cac0aa0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 11 Apr 2018 01:01:17 +0800 Subject: [PATCH 415/470] Improve broken testcases --- Tests/SwiftyJSONTests/CodableTests.swift | 34 +++++++++++-------- .../RawRepresentableTests.swift | 4 ++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Tests/SwiftyJSONTests/CodableTests.swift b/Tests/SwiftyJSONTests/CodableTests.swift index 9cc43eaa..a3608c1c 100644 --- a/Tests/SwiftyJSONTests/CodableTests.swift +++ b/Tests/SwiftyJSONTests/CodableTests.swift @@ -24,7 +24,7 @@ import XCTest import SwiftyJSON class CodableTests: XCTestCase { - + func testEncodeNull() { var json = JSON([NSNull()]) _ = try! JSONEncoder().encode(json) @@ -34,6 +34,7 @@ class CodableTests: XCTestCase { json = JSON(dictionary) _ = try! JSONEncoder().encode(json) } + func testArrayCodable() { let jsonString = """ [1,"false", ["A", 4.3231],"3",true] @@ -53,15 +54,16 @@ class CodableTests: XCTestCase { data = try! JSONEncoder().encode(json) let list = try! JSONSerialization.jsonObject(with: data, options: []) as! [Any] XCTAssertEqual(list[0] as! Int, 1) - XCTAssertEqual((list[2] as! [Any])[1] as! Float, 4.3231) + XCTAssertEqual((list[2] as! [Any])[1] as! NSNumber, 4.3231) } + func testDictionaryCodable() { let dictionary: [String: Any] = ["number": 9823.212, "name": "NAME", "list": [1234, 4.21223256], "object": ["sub_number": 877.2323, "sub_name": "sub_name"], "bool": true] var data = try! JSONSerialization.data(withJSONObject: dictionary, options: []) let json = try! JSONDecoder().decode(JSON.self, from: data) XCTAssertNotNil(json.dictionary) XCTAssertEqual(json["number"].float, 9823.212) - XCTAssertEqual(json["list"].arrayObject is [Float], true) + XCTAssertEqual(json["list"].arrayObject is [NSNumber], true) XCTAssertEqual(json["object"]["sub_number"].float, 877.2323) XCTAssertEqual(json["bool"].bool, true) let jsonDict = try! JSONDecoder().decode([String: JSON].self, from: data) @@ -69,24 +71,15 @@ class CodableTests: XCTestCase { XCTAssertEqual(jsonDict["object"]?["sub_name"], "sub_name") data = try! JSONEncoder().encode(json) var encoderDict = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any] - XCTAssertEqual(encoderDict["list"] as! [Float], [1234, 4.21223256]) + XCTAssertEqual(encoderDict["list"] as! [NSNumber], [1234, 4.21223256]) XCTAssertEqual(encoderDict["bool"] as! Bool, true) data = try! JSONEncoder().encode(jsonDict) encoderDict = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any] XCTAssertEqual(encoderDict["name"] as! String, dictionary["name"] as! String) - XCTAssertEqual((encoderDict["object"] as! [String: Any])["sub_number"] as! Float, 877.2323) + XCTAssertEqual((encoderDict["object"] as! [String: Any])["sub_number"] as! NSNumber, 877.2323) } + func testCodableModel() { - struct CodableModel: Codable { - let name: String - let number: Double - let bool: Bool - let list: [Double] - private let object: JSON - var subName: String? { - return object["sub_name"].string - } - } let dictionary: [String: Any] = [ "number": 9823.212, "name": "NAME", @@ -98,3 +91,14 @@ class CodableTests: XCTestCase { XCTAssertEqual(model.subName, "sub_name") } } + +private struct CodableModel: Codable { + let name: String + let number: Double + let bool: Bool + let list: [Double] + private let object: JSON + var subName: String? { + return object["sub_name"].string + } +} diff --git a/Tests/SwiftyJSONTests/RawRepresentableTests.swift b/Tests/SwiftyJSONTests/RawRepresentableTests.swift index fec52512..9c628a05 100644 --- a/Tests/SwiftyJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftyJSONTests/RawRepresentableTests.swift @@ -39,7 +39,9 @@ class RawRepresentableTests: XCTestCase { XCTAssertEqual(int, 948394394) } XCTAssertEqual(object as? Double, 948394394.347384) - XCTAssertEqual(object as? Float, 948394394.347384) + if let float = object as? Float { + XCTAssertEqual(float, 948394394.347384) + } XCTAssertEqual(object as? NSNumber, 948394394.347384) } From 42c3848afc684baf0f341ea9265ddddf8af3a5c0 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 11 Apr 2018 01:01:52 +0800 Subject: [PATCH 416/470] Update to Xcode 9.3 recommend settings --- Example/Example.xcodeproj/project.pbxproj | 6 +++++- SwiftyJSON.xcodeproj/project.pbxproj | 10 +++++++--- .../xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme | 4 +--- .../xcshareddata/xcschemes/SwiftyJSON macOS.xcscheme | 4 +--- .../xcshareddata/xcschemes/SwiftyJSON tvOS.xcscheme | 4 +--- .../xcshareddata/xcschemes/SwiftyJSON watchOS.xcscheme | 4 +--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 7 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 SwiftyJSON.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 9abea6d6..27cdfe91 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -124,7 +124,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = swiftyjson; TargetAttributes = { A82A1C1819D926B8009A653D = { @@ -210,12 +210,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; @@ -264,12 +266,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; diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 494fb964..2b3c99a5 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -457,7 +457,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 0930; TargetAttributes = { 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; @@ -725,12 +725,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; @@ -783,12 +785,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; @@ -1062,7 +1066,7 @@ isa = XCBuildConfiguration; buildSettings = { PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx10.13; + SDKROOT = macosx; }; name = Debug; }; @@ -1070,7 +1074,7 @@ isa = XCBuildConfiguration; buildSettings = { PRODUCT_NAME = "$(TARGET_NAME)"; - SDKROOT = macosx10.13; + SDKROOT = macosx; }; name = Release; }; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme index 61b7bfb3..98076542 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme @@ -1,6 +1,6 @@ @@ -37,7 +36,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/SwiftyJSON.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SwiftyJSON.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/SwiftyJSON.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 1284c0619d8d8cff3d0ea57beed0614a3980b960 Mon Sep 17 00:00:00 2001 From: Bojan Stefanovic Date: Tue, 10 Apr 2018 10:10:05 -0700 Subject: [PATCH 417/470] Updated broken Twitter API link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35355ff8..15758050 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. Swift is very strict about types. But although explicit typing is good for saving us from mistakes, it becomes painful when dealing with JSON and other areas that are, by nature, implicit about types. -Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline). +Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline). The code would look like this: From f2126db35c1142b9c9028a69d04dde67f17562e8 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 11 Apr 2018 10:30:57 +0800 Subject: [PATCH 418/470] Update README.md --- README.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 15758050..32749799 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. Swift is very strict about types. But although explicit typing is good for saving us from mistakes, it becomes painful when dealing with JSON and other areas that are, by nature, implicit about types. -Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to Twitter's API https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline). +Take the Twitter API for example. Say we want to retrieve a user's "name" value of some tweet in Swift (according to [Twitter's API](https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-home_timeline)). The code would look like this: @@ -90,38 +90,36 @@ platform :ios, '8.0' use_frameworks! target 'MyApp' do - pod 'SwiftyJSON' + pod 'SwiftyJSON', '~> 4.0' end ``` -Note that this requires CocoaPods version 36, and your iOS deployment target to be at least 8.0: - - #### Carthage (iOS 8+, OS X 10.9+) You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyJSON` by adding it to your `Cartfile`: ``` -github "SwiftyJSON/SwiftyJSON" +github "SwiftyJSON/SwiftyJSON" ~> 4.0 ``` +If you use Carthage to build your dependencies, make sure you have added `SwiftyJSON.framework` to the "Linked Frameworks and Libraries" section of your target, and have included them in your Carthage framework copying build phase. + #### Swift Package Manager You can use [The Swift Package Manager](https://swift.org/package-manager) to install `SwiftyJSON` by adding the proper description to your `Package.swift` file: ```swift +// swift-tools-version:4.0 import PackageDescription let package = Package( name: "YOUR_PROJECT_NAME", - targets: [], dependencies: [ - .Package(url: "https://github.com/SwiftyJSON/SwiftyJSON.git", versions: Version(1, 0, 0).. Date: Wed, 11 Apr 2018 10:48:01 +0800 Subject: [PATCH 419/470] Update osx image to 9.3 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 570a6014..cbc39370 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode9 +osx_image: xcode9.3 xcode_sdk: iphonesimulator10.0 script: - set -o pipefail From 1968e3bd1d64744099e21e4e774b3cdc5e926abd Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Fri, 13 Apr 2018 01:10:02 +0800 Subject: [PATCH 420/470] Xcode9.3 image no longer support Apple TV 1080p --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cbc39370..e94149f3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,4 @@ script: - set -o pipefail - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON macOS" build-for-testing test | xcpretty -- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV 1080p" build-for-testing test | xcpretty +- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV" build-for-testing test | xcpretty From ebfc0d7e314f15c1df02fcb198beb40624421839 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 18 Apr 2018 23:41:35 +0800 Subject: [PATCH 421/470] Version bump to 4.1.0 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index e5eba227..3b442264 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "4.0.0" + s.version = "4.1.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From 454458d12752b19dfe47d7b0a43870cc66e63b2a Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 9 May 2018 00:58:19 +0800 Subject: [PATCH 422/470] Update Xcode Settings --- Example/Example.xcodeproj/project.pbxproj | 8 +++++--- SwiftyJSON.xcodeproj/project.pbxproj | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 27cdfe91..95a703b4 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -129,7 +129,7 @@ TargetAttributes = { A82A1C1819D926B8009A653D = { CreatedOnToolsVersion = 6.0.1; - LastSwiftMigration = 0820; + LastSwiftMigration = 0930; ProvisioningStyle = Manual; }; }; @@ -313,7 +313,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -328,7 +329,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 2b3c99a5..e290e728 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -479,6 +479,7 @@ }; 9C7DFC641A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; + LastSwiftMigration = 0930; }; A81D162B1E5743B000C62C5F = { CreatedOnToolsVersion = 8.2.1; @@ -486,6 +487,7 @@ }; A8580F731BCF5C5B00DA927B = { CreatedOnToolsVersion = 7.1; + LastSwiftMigration = 0930; }; E4D7CCDE1B9465A700EE7221 = { ProvisioningStyle = Automatic; @@ -936,6 +938,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -961,6 +964,7 @@ PRODUCT_NAME = SwiftyJSON; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -993,6 +997,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -1019,6 +1024,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -1041,6 +1047,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -1059,6 +1067,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -1092,6 +1102,8 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -1110,6 +1122,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; @@ -1136,6 +1150,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1162,6 +1177,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; + SWIFT_VERSION = 4.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; From 05e40f8b1240e44f2357086cc69185f1692a1d3d Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 18 Sep 2018 13:11:05 +0800 Subject: [PATCH 423/470] Update build settings to Xcode 10.0 --- Example/Example.xcodeproj/project.pbxproj | 4 +-- SwiftyJSON.xcodeproj/project.pbxproj | 31 +++++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 95a703b4..54e81356 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -313,7 +313,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Debug; @@ -329,7 +329,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; }; name = Release; diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index e290e728..16ccac87 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -471,15 +471,17 @@ TestTargetID = 2E4FEFDA19575BE100351305; }; 7236B4EC1BAC14150020529B = { + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; 9C7DFC5A1A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; 9C7DFC641A9102BD005AA3F7 = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 0930; + LastSwiftMigration = 1000; }; A81D162B1E5743B000C62C5F = { CreatedOnToolsVersion = 8.2.1; @@ -487,9 +489,10 @@ }; A8580F731BCF5C5B00DA927B = { CreatedOnToolsVersion = 7.1; - LastSwiftMigration = 0930; + LastSwiftMigration = 1000; }; E4D7CCDE1B9465A700EE7221 = { + LastSwiftMigration = 1000; ProvisioningStyle = Automatic; }; }; @@ -938,7 +941,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -964,7 +967,7 @@ PRODUCT_NAME = SwiftyJSON; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -997,7 +1000,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1024,7 +1027,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -1047,8 +1050,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -1067,8 +1069,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -1102,8 +1103,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -1122,8 +1122,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; - SWIFT_SWIFT3_OBJC_INFERENCE = On; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; @@ -1150,7 +1149,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; @@ -1177,7 +1176,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.0; }; From 1f37a67c6163be2561aaa1854cb921c54d1ad73c Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 18 Sep 2018 13:13:56 +0800 Subject: [PATCH 424/470] Update CI to Xcode 10.0/iOS 12.0 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index e94149f3..831af979 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: objective-c -osx_image: xcode9.3 -xcode_sdk: iphonesimulator10.0 +osx_image: xcode10.0 +xcode_sdk: iphonesimulator12.0 script: - set -o pipefail - travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty From 44dc2dc7f28b0485876c9280b0dfda93ff6fcbeb Mon Sep 17 00:00:00 2001 From: Quentin Dreyer Date: Tue, 21 Aug 2018 16:06:51 +0200 Subject: [PATCH 425/470] Added swift_version to podspec --- SwiftyJSON.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 3b442264..00434ddb 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -7,6 +7,7 @@ Pod::Spec.new do |s| s.authors = { "lingoer" => "lingoerer@gmail.com", "tangplin" => "tangplin@gmail.com" } s.requires_arc = true + s.swift_version = "4.2" s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" s.watchos.deployment_target = "2.0" From cd8ea07d5b44673fbf882e535bc3102e05858d34 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 25 Sep 2018 23:14:26 +0800 Subject: [PATCH 426/470] Fix version --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 831af979..34acdea7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode10.0 +osx_image: xcode10 xcode_sdk: iphonesimulator12.0 script: - set -o pipefail From 747a29f8d9e85448b231d8f34d5eac29e664774c Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 25 Sep 2018 23:22:01 +0800 Subject: [PATCH 427/470] Update min requirement of watchOS to 3.0 --- SwiftyJSON.podspec | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 3b442264..b1cdf26f 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.requires_arc = true s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" - s.watchos.deployment_target = "2.0" + s.watchos.deployment_target = "3.0" s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => s.version } s.source_files = "Source/*.swift" diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 16ccac87..1ec04ff6 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -1151,7 +1151,7 @@ SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 4; - WATCHOS_DEPLOYMENT_TARGET = 2.0; + WATCHOS_DEPLOYMENT_TARGET = 3.0; }; name = Debug; }; @@ -1178,7 +1178,7 @@ SUPPORTED_PLATFORMS = "watchsimulator watchos"; SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = 4; - WATCHOS_DEPLOYMENT_TARGET = 2.0; + WATCHOS_DEPLOYMENT_TARGET = 3.0; }; name = Release; }; From 3451da4ea3f835bb9e0113afdabc4a69605cf44b Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 25 Sep 2018 23:39:29 +0800 Subject: [PATCH 428/470] Version bump to 4.2.0 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 4d7e6ccf..d5fbc3d1 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "4.1.0" + s.version = "4.2.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From b51eb540e5b4351628f91a50d34385fe73e2c659 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 25 Sep 2018 23:48:52 +0800 Subject: [PATCH 429/470] Remove .swift-version file --- .swift-version | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .swift-version diff --git a/.swift-version b/.swift-version deleted file mode 100644 index 9f55b2cc..00000000 --- a/.swift-version +++ /dev/null @@ -1 +0,0 @@ -3.0 From 184c6884998c41f71a73c459f9b525b7121be846 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 26 Sep 2018 00:20:01 +0800 Subject: [PATCH 430/470] Remove deprecated API in 4.2.0 --- Source/SwiftyJSON.swift | 37 -------------------- Tests/SwiftyJSONTests/PerformanceTests.swift | 2 +- 2 files changed, 1 insertion(+), 38 deletions(-) diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON.swift index f3553fe5..a6c1f3a6 100644 --- a/Source/SwiftyJSON.swift +++ b/Source/SwiftyJSON.swift @@ -24,22 +24,6 @@ import Foundation // MARK: - Error // swiftlint:disable line_length -/// Error domain -@available(*, deprecated, message: "ErrorDomain is deprecated. Use `SwiftyJSONError.errorDomain` instead.", renamed: "SwiftyJSONError.errorDomain") -public let ErrorDomain: String = "SwiftyJSONErrorDomain" - -/// Error code -@available(*, deprecated, message: "ErrorUnsupportedType is deprecated. Use `SwiftyJSONError.unsupportedType` instead.", renamed: "SwiftyJSONError.unsupportedType") -public let ErrorUnsupportedType: Int = 999 -@available(*, deprecated, message: "ErrorIndexOutOfBounds is deprecated. Use `SwiftyJSONError.indexOutOfBounds` instead.", renamed: "SwiftyJSONError.indexOutOfBounds") -public let ErrorIndexOutOfBounds: Int = 900 -@available(*, deprecated, message: "ErrorWrongType is deprecated. Use `SwiftyJSONError.wrongType` instead.", renamed: "SwiftyJSONError.wrongType") -public let ErrorWrongType: Int = 901 -@available(*, deprecated, message: "ErrorNotExist is deprecated. Use `SwiftyJSONError.notExist` instead.", renamed: "SwiftyJSONError.notExist") -public let ErrorNotExist: Int = 500 -@available(*, deprecated, message: "ErrorInvalidJSON is deprecated. Use `SwiftyJSONError.invalidJSON` instead.", renamed: "SwiftyJSONError.invalidJSON") -public let ErrorInvalidJSON: Int = 490 - public enum SwiftyJSONError: Int, Swift.Error { case unsupportedType = 999 case indexOutOfBounds = 900 @@ -146,19 +130,6 @@ public struct JSON { } } - /** - Creates a JSON from JSON string - - - parameter json: Normal json string like '{"a":"b"}' - - - returns: The created JSON - */ - @available(*, deprecated, message: "Use instead `init(parseJSON: )`") - public static func parse(_ json: String) -> JSON { - return json.data(using: String.Encoding.utf8) - .flatMap { try? JSON(data: $0) } ?? JSON(NSNull()) - } - /** Creates a JSON using the object. @@ -592,14 +563,6 @@ extension JSON: Swift.ExpressibleByArrayLiteral { } } -extension JSON: Swift.ExpressibleByNilLiteral { - - @available(*, deprecated, message: "use JSON.null instead. Will be removed in future versions") - public init(nilLiteral: ()) { - self.init(NSNull() as Any) - } -} - // MARK: - Raw extension JSON: Swift.RawRepresentable { diff --git a/Tests/SwiftyJSONTests/PerformanceTests.swift b/Tests/SwiftyJSONTests/PerformanceTests.swift index 64de9e14..7535f7d8 100644 --- a/Tests/SwiftyJSONTests/PerformanceTests.swift +++ b/Tests/SwiftyJSONTests/PerformanceTests.swift @@ -127,7 +127,7 @@ class PerformanceTests: XCTestCase { self.measure { autoreleasepool { if let dictionary = json.dictionary { - XCTAssertTrue(dictionary.count > 0) + XCTAssertTrue(dictionary.count == 100001) } else { XCTFail("dictionary should not be nil") } From 32413d7055cf8f5dce334dd687e9b4323dc21437 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 26 Sep 2018 12:20:00 +0800 Subject: [PATCH 431/470] Re-organize directories --- SwiftyJSON.xcodeproj/project.pbxproj | 62 +++++++++---------- Tests/{SwiftyJSONTests => }/ArrayTests.swift | 0 Tests/{SwiftyJSONTests => }/BaseTests.swift | 0 .../{SwiftyJSONTests => }/CodableTests.swift | 0 .../ComparableTests.swift | 0 .../DictionaryTests.swift | 0 Tests/{SwiftyJSONTests => }/Info-iOS.plist | 0 Tests/{SwiftyJSONTests => }/Info-macOS.plist | 0 Tests/{SwiftyJSONTests => }/Info-tvOS.plist | 0 .../LiteralConvertibleTests.swift | 0 Tests/{SwiftyJSONTests => }/MergeTests.swift | 0 .../MutabilityTests.swift | 0 .../NestedJSONTests.swift | 0 Tests/{SwiftyJSONTests => }/NumberTests.swift | 0 .../PerformanceTests.swift | 0 .../PrintableTests.swift | 0 .../RawRepresentableTests.swift | 0 Tests/{SwiftyJSONTests => }/RawTests.swift | 0 .../SequenceTypeTests.swift | 0 Tests/{SwiftyJSONTests => }/StringTests.swift | 0 .../SubscriptTests.swift | 0 Tests/{SwiftyJSONTests => Tes}/Tests.json | 0 22 files changed, 31 insertions(+), 31 deletions(-) rename Tests/{SwiftyJSONTests => }/ArrayTests.swift (100%) rename Tests/{SwiftyJSONTests => }/BaseTests.swift (100%) rename Tests/{SwiftyJSONTests => }/CodableTests.swift (100%) rename Tests/{SwiftyJSONTests => }/ComparableTests.swift (100%) rename Tests/{SwiftyJSONTests => }/DictionaryTests.swift (100%) rename Tests/{SwiftyJSONTests => }/Info-iOS.plist (100%) rename Tests/{SwiftyJSONTests => }/Info-macOS.plist (100%) rename Tests/{SwiftyJSONTests => }/Info-tvOS.plist (100%) rename Tests/{SwiftyJSONTests => }/LiteralConvertibleTests.swift (100%) rename Tests/{SwiftyJSONTests => }/MergeTests.swift (100%) rename Tests/{SwiftyJSONTests => }/MutabilityTests.swift (100%) rename Tests/{SwiftyJSONTests => }/NestedJSONTests.swift (100%) rename Tests/{SwiftyJSONTests => }/NumberTests.swift (100%) rename Tests/{SwiftyJSONTests => }/PerformanceTests.swift (100%) rename Tests/{SwiftyJSONTests => }/PrintableTests.swift (100%) rename Tests/{SwiftyJSONTests => }/RawRepresentableTests.swift (100%) rename Tests/{SwiftyJSONTests => }/RawTests.swift (100%) rename Tests/{SwiftyJSONTests => }/SequenceTypeTests.swift (100%) rename Tests/{SwiftyJSONTests => }/StringTests.swift (100%) rename Tests/{SwiftyJSONTests => }/SubscriptTests.swift (100%) rename Tests/{SwiftyJSONTests => Tes}/Tests.json (100%) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 1ec04ff6..be176003 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -114,37 +114,37 @@ /* Begin PBXFileReference section */ 030B6CDC1A6E171D00C2D4F1 /* Info-macOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = ""; }; - 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MergeTests.swift; sourceTree = ""; }; + 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MergeTests.swift; path = ../MergeTests.swift; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 5DD502901D9B21810004C112 /* NestedJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NestedJSONTests.swift; sourceTree = ""; }; - 712921EE2004E4EB00DA6340 /* CodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableTests.swift; sourceTree = ""; }; + 5DD502901D9B21810004C112 /* NestedJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NestedJSONTests.swift; path = ../NestedJSONTests.swift; sourceTree = ""; }; + 712921EE2004E4EB00DA6340 /* CodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CodableTests.swift; path = ../CodableTests.swift; sourceTree = ""; }; 7236B4F61BAC14150020529B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; - 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = ""; }; + 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Info-macOS.plist"; path = "../Info-macOS.plist"; sourceTree = ""; }; 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON macOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON macOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LiteralConvertibleTests.swift; sourceTree = ""; }; - A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentableTests.swift; sourceTree = ""; }; - A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SubscriptTests.swift; sourceTree = ""; }; - A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PrintableTests.swift; sourceTree = ""; }; - A82A1C0D19D922DC009A653D /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; - A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MutabilityTests.swift; sourceTree = ""; }; + A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LiteralConvertibleTests.swift; path = ../LiteralConvertibleTests.swift; sourceTree = ""; }; + A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RawRepresentableTests.swift; path = ../RawRepresentableTests.swift; sourceTree = ""; }; + A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SubscriptTests.swift; path = ../SubscriptTests.swift; sourceTree = ""; }; + A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PrintableTests.swift; path = ../PrintableTests.swift; sourceTree = ""; }; + A82A1C0D19D922DC009A653D /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Info-iOS.plist"; path = "../Info-iOS.plist"; sourceTree = ""; }; + A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MutabilityTests.swift; path = ../MutabilityTests.swift; sourceTree = ""; }; A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; - A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawTests.swift; sourceTree = ""; }; - A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PerformanceTests.swift; sourceTree = ""; }; - A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SequenceTypeTests.swift; sourceTree = ""; }; - A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComparableTests.swift; sourceTree = ""; }; - A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberTests.swift; sourceTree = ""; }; - A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = ""; }; - A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BaseTests.swift; sourceTree = ""; }; + A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-tvOS.plist"; path = "../Info-tvOS.plist"; sourceTree = ""; }; + A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RawTests.swift; path = ../RawTests.swift; sourceTree = ""; }; + A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PerformanceTests.swift; path = ../PerformanceTests.swift; sourceTree = ""; }; + A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SequenceTypeTests.swift; path = ../SequenceTypeTests.swift; sourceTree = ""; }; + A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ComparableTests.swift; path = ../ComparableTests.swift; sourceTree = ""; }; + A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberTests.swift; path = ../NumberTests.swift; sourceTree = ""; }; + A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StringTests.swift; path = ../StringTests.swift; sourceTree = ""; }; + A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BaseTests.swift; path = ../BaseTests.swift; sourceTree = ""; }; A885D1DA19CFCFF0002FD4C3 /* Tests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Tests.json; sourceTree = ""; }; - A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DictionaryTests.swift; sourceTree = ""; }; - A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArrayTests.swift; sourceTree = ""; }; + A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DictionaryTests.swift; path = ../DictionaryTests.swift; sourceTree = ""; }; + A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArrayTests.swift; path = ../ArrayTests.swift; sourceTree = ""; }; E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-watchOS.plist"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -209,7 +209,7 @@ isa = PBXGroup; children = ( 2E4FEFDD19575BE100351305 /* Source */, - 2E4FEFEA19575BE100351305 /* SwiftyJSONTests */, + 2E4FEFEA19575BE100351305 /* Tests */, 2E4FEFDC19575BE100351305 /* Products */, ); sourceTree = ""; @@ -249,11 +249,10 @@ name = "Supporting Files"; sourceTree = ""; }; - 2E4FEFEA19575BE100351305 /* SwiftyJSONTests */ = { + 2E4FEFEA19575BE100351305 /* Tests */ = { isa = PBXGroup; children = ( 1B587CC41DDE04360012D8DB /* MergeTests.swift */, - A885D1DA19CFCFF0002FD4C3 /* Tests.json */, A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */, A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */, 5DD502901D9B21810004C112 /* NestedJSONTests.swift */, @@ -272,13 +271,14 @@ 712921EE2004E4EB00DA6340 /* CodableTests.swift */, 2E4FEFEB19575BE100351305 /* Supporting Files */, ); - name = SwiftyJSONTests; - path = Tests/SwiftyJSONTests; + name = Tests; + path = Tests/Tes; sourceTree = ""; }; 2E4FEFEB19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( + A885D1DA19CFCFF0002FD4C3 /* Tests.json */, A82A1C0D19D922DC009A653D /* Info-iOS.plist */, 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */, A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */, @@ -891,7 +891,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-iOS.plist"; + INFOPLIST_FILE = "Tests/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = YES; @@ -909,7 +909,7 @@ CODE_SIGN_IDENTITY = ""; DEVELOPMENT_TEAM = ""; GCC_OPTIMIZATION_LEVEL = s; - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-iOS.plist"; + INFOPLIST_FILE = "Tests/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; METAL_ENABLE_DEBUG_INFO = NO; @@ -1042,7 +1042,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-macOS.plist"; + INFOPLIST_FILE = "Tests/Info-macOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = YES; @@ -1062,7 +1062,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; FRAMEWORK_SEARCH_PATHS = ""; GCC_OPTIMIZATION_LEVEL = s; - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-macOS.plist"; + INFOPLIST_FILE = "Tests/Info-macOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks"; MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; @@ -1096,7 +1096,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-tvOS.plist"; + INFOPLIST_FILE = "Tests/Info-tvOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = YES; PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; @@ -1116,7 +1116,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = s; - INFOPLIST_FILE = "Tests/SwiftyJSONTests/Info-tvOS.plist"; + INFOPLIST_FILE = "Tests/Info-tvOS.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; MTL_ENABLE_DEBUG_INFO = NO; PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; diff --git a/Tests/SwiftyJSONTests/ArrayTests.swift b/Tests/ArrayTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/ArrayTests.swift rename to Tests/ArrayTests.swift diff --git a/Tests/SwiftyJSONTests/BaseTests.swift b/Tests/BaseTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/BaseTests.swift rename to Tests/BaseTests.swift diff --git a/Tests/SwiftyJSONTests/CodableTests.swift b/Tests/CodableTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/CodableTests.swift rename to Tests/CodableTests.swift diff --git a/Tests/SwiftyJSONTests/ComparableTests.swift b/Tests/ComparableTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/ComparableTests.swift rename to Tests/ComparableTests.swift diff --git a/Tests/SwiftyJSONTests/DictionaryTests.swift b/Tests/DictionaryTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/DictionaryTests.swift rename to Tests/DictionaryTests.swift diff --git a/Tests/SwiftyJSONTests/Info-iOS.plist b/Tests/Info-iOS.plist similarity index 100% rename from Tests/SwiftyJSONTests/Info-iOS.plist rename to Tests/Info-iOS.plist diff --git a/Tests/SwiftyJSONTests/Info-macOS.plist b/Tests/Info-macOS.plist similarity index 100% rename from Tests/SwiftyJSONTests/Info-macOS.plist rename to Tests/Info-macOS.plist diff --git a/Tests/SwiftyJSONTests/Info-tvOS.plist b/Tests/Info-tvOS.plist similarity index 100% rename from Tests/SwiftyJSONTests/Info-tvOS.plist rename to Tests/Info-tvOS.plist diff --git a/Tests/SwiftyJSONTests/LiteralConvertibleTests.swift b/Tests/LiteralConvertibleTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/LiteralConvertibleTests.swift rename to Tests/LiteralConvertibleTests.swift diff --git a/Tests/SwiftyJSONTests/MergeTests.swift b/Tests/MergeTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/MergeTests.swift rename to Tests/MergeTests.swift diff --git a/Tests/SwiftyJSONTests/MutabilityTests.swift b/Tests/MutabilityTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/MutabilityTests.swift rename to Tests/MutabilityTests.swift diff --git a/Tests/SwiftyJSONTests/NestedJSONTests.swift b/Tests/NestedJSONTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/NestedJSONTests.swift rename to Tests/NestedJSONTests.swift diff --git a/Tests/SwiftyJSONTests/NumberTests.swift b/Tests/NumberTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/NumberTests.swift rename to Tests/NumberTests.swift diff --git a/Tests/SwiftyJSONTests/PerformanceTests.swift b/Tests/PerformanceTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/PerformanceTests.swift rename to Tests/PerformanceTests.swift diff --git a/Tests/SwiftyJSONTests/PrintableTests.swift b/Tests/PrintableTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/PrintableTests.swift rename to Tests/PrintableTests.swift diff --git a/Tests/SwiftyJSONTests/RawRepresentableTests.swift b/Tests/RawRepresentableTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/RawRepresentableTests.swift rename to Tests/RawRepresentableTests.swift diff --git a/Tests/SwiftyJSONTests/RawTests.swift b/Tests/RawTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/RawTests.swift rename to Tests/RawTests.swift diff --git a/Tests/SwiftyJSONTests/SequenceTypeTests.swift b/Tests/SequenceTypeTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/SequenceTypeTests.swift rename to Tests/SequenceTypeTests.swift diff --git a/Tests/SwiftyJSONTests/StringTests.swift b/Tests/StringTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/StringTests.swift rename to Tests/StringTests.swift diff --git a/Tests/SwiftyJSONTests/SubscriptTests.swift b/Tests/SubscriptTests.swift similarity index 100% rename from Tests/SwiftyJSONTests/SubscriptTests.swift rename to Tests/SubscriptTests.swift diff --git a/Tests/SwiftyJSONTests/Tests.json b/Tests/Tes/Tests.json similarity index 100% rename from Tests/SwiftyJSONTests/Tests.json rename to Tests/Tes/Tests.json From 027f1bc1c0b8c5f7f5fad7a26a6730f7d6458ee8 Mon Sep 17 00:00:00 2001 From: Meghdoot Dhameliya Date: Wed, 26 Sep 2018 12:54:28 +0530 Subject: [PATCH 432/470] SwiftyJSON Model Generator Tools Reference added (#976) SwiftyJSON Model Generator tool reference added --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 32749799..ca69ca6b 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ SwiftyJSON makes it easy to deal with JSON data in Swift. - [Merging](#merging) 5. [Work with Alamofire](#work-with-alamofire) 6. [Work with Moya](#work-with-moya) +7. [SwiftyJSON Model Generator](#swiftyjson-model-generator) > [中文介绍](http://tangplin.github.io/swiftyjson/) @@ -547,3 +548,8 @@ provider.request(.showProducts) { result in } ``` + +## SwiftyJSON Model Generator +Tools to generate SwiftyJSON Models +* [JSON Cafe](http://www.jsoncafe.com/) +* [JSON Export](https://github.com/Ahmed-Ali/JSONExport) From cf762e63d2f4062b755c92d47bb4ef4b76d6edde Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 26 Sep 2018 17:22:43 +0800 Subject: [PATCH 433/470] Remove unused script --- scripts/carthage.sh | 2 -- 1 file changed, 2 deletions(-) delete mode 100755 scripts/carthage.sh diff --git a/scripts/carthage.sh b/scripts/carthage.sh deleted file mode 100755 index aeee56ae..00000000 --- a/scripts/carthage.sh +++ /dev/null @@ -1,2 +0,0 @@ -carthage build --no-skip-current -carthage archive SwiftyJSON From 3f6f1d32df6e5f334593682b20bb829e48bffbee Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 26 Sep 2018 18:03:28 +0800 Subject: [PATCH 434/470] Update README.md --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ca69ca6b..9cf5a68d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,15 @@ # SwiftyJSON -[![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg) ![Platform](https://img.shields.io/badge/platforms-iOS%208.0+%20%7C%20macOS%2010.10+%20%7C%20tvOS%209.0+%20%7C%20watchOS%202.0+-333333.svg) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg) ![Platform](https://img.shields.io/badge/platforms-iOS%208.0%20%7C%20macOS%2010.10%20%7C%20tvOS%209.0%20%7C%20watchOS%203.0-F28D00.svg) SwiftyJSON makes it easy to deal with JSON data in Swift. +Platform | Build Status +---------| --------------| +*OS | [![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) | +[Linux](https://github.com/IBM-Swift/SwiftyJSON) | [![Build Status](https://travis-ci.org/IBM-Swift/SwiftyJSON.svg?branch=master)](https://travis-ci.org/IBM-Swift/SwiftyJSON) | + + 1. [Why is the typical JSON handling in Swift NOT good](#why-is-the-typical-json-handling-in-swift-not-good) 2. [Requirements](#requirements) 3. [Integration](#integration) From 53559ee35727703bfef031af74babf07ead15f7d Mon Sep 17 00:00:00 2001 From: Happy HumanPointer <45888860+SafelySwift@users.noreply.github.com> Date: Sun, 31 Mar 2019 08:15:21 -0400 Subject: [PATCH 435/470] Update README.md (#1010) * Update README.md * Update README.md --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9cf5a68d..0aedb469 100644 --- a/README.md +++ b/README.md @@ -73,11 +73,12 @@ And don't worry about the Optional Wrapping thing. It's done for you automatical ```swift let json = JSON(data: dataFromNetworking) -if let userName = json[999999]["wrong_key"]["wrong_name"].string { +let result = json[999999]["wrong_key"]["wrong_name"] +if let userName = result.string { //Calm down, take it easy, the ".string" property still produces the correct Optional String type with safety } else { //Print the error - print(json[999999]["wrong_key"]["wrong_name"]) + print(result.error) } ``` @@ -168,7 +169,7 @@ let name = json[0].double ```swift // Getting an array of string from a JSON Array -let arrayNames = json["users"].arrayValue.map({$0["name"].stringValue}) +let arrayNames = json["users"].arrayValue.map {$0["name"].stringValue} ``` ```swift From 645f1e39bd53dd07fb2a1b7cc8d8be043b701bcc Mon Sep 17 00:00:00 2001 From: Scott Albertson Date: Sun, 31 Mar 2019 10:39:11 -0700 Subject: [PATCH 436/470] Add a "Reviewed by Hound" badge (#1006) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0aedb469..7a10e29c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # SwiftyJSON -[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg) ![Platform](https://img.shields.io/badge/platforms-iOS%208.0%20%7C%20macOS%2010.10%20%7C%20tvOS%209.0%20%7C%20watchOS%203.0-F28D00.svg) +[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg) ![Platform](https://img.shields.io/badge/platforms-iOS%208.0%20%7C%20macOS%2010.10%20%7C%20tvOS%209.0%20%7C%20watchOS%203.0-F28D00.svg) [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com) SwiftyJSON makes it easy to deal with JSON data in Swift. From 8bbb74eec7366de10f78a05fc9dff588337c117e Mon Sep 17 00:00:00 2001 From: Moritz Vetter Date: Sun, 31 Mar 2019 19:44:03 +0200 Subject: [PATCH 437/470] Updated swift-tools to version 5.0 (#1013) * Updated SwiftyJSON to swift-tools 5.0 * supply path to Tests.json in a different manner * Made changes comply with xcode building scheme, removed compliance with [1/3] Compiling Swift Module 'SwiftyJSON' (1 sources) [2/3] Compiling Swift Module 'SwiftJSONTests' (17 sources) [3/3] Linking ./.build/x86_64-apple-macosx/debug/SwiftyJSONPackageTests.xctest/Contents/MacOS/SwiftyJSONPackageTests Exited with signal code 4 --- Package.swift | 12 +++++- Source/{ => SwiftyJSON}/SwiftyJSON.h | 0 Source/{ => SwiftyJSON}/SwiftyJSON.swift | 0 SwiftyJSON.xcodeproj/project.pbxproj | 39 ++++++++++--------- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++ Tests/{ => SwiftJSONTests}/ArrayTests.swift | 0 Tests/{ => SwiftJSONTests}/BaseTests.swift | 2 + Tests/{ => SwiftJSONTests}/CodableTests.swift | 0 .../ComparableTests.swift | 0 .../DictionaryTests.swift | 0 .../LiteralConvertibleTests.swift | 0 Tests/{ => SwiftJSONTests}/MergeTests.swift | 0 .../MutabilityTests.swift | 0 .../NestedJSONTests.swift | 0 Tests/{ => SwiftJSONTests}/NumberTests.swift | 0 .../PerformanceTests.swift | 0 .../{ => SwiftJSONTests}/PrintableTests.swift | 0 .../RawRepresentableTests.swift | 0 Tests/{ => SwiftJSONTests}/RawTests.swift | 0 .../SequenceTypeTests.swift | 0 Tests/{ => SwiftJSONTests}/StringTests.swift | 0 .../{ => SwiftJSONTests}/SubscriptTests.swift | 0 22 files changed, 41 insertions(+), 20 deletions(-) rename Source/{ => SwiftyJSON}/SwiftyJSON.h (100%) rename Source/{ => SwiftyJSON}/SwiftyJSON.swift (100%) create mode 100644 SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist rename Tests/{ => SwiftJSONTests}/ArrayTests.swift (100%) rename Tests/{ => SwiftJSONTests}/BaseTests.swift (99%) rename Tests/{ => SwiftJSONTests}/CodableTests.swift (100%) rename Tests/{ => SwiftJSONTests}/ComparableTests.swift (100%) rename Tests/{ => SwiftJSONTests}/DictionaryTests.swift (100%) rename Tests/{ => SwiftJSONTests}/LiteralConvertibleTests.swift (100%) rename Tests/{ => SwiftJSONTests}/MergeTests.swift (100%) rename Tests/{ => SwiftJSONTests}/MutabilityTests.swift (100%) rename Tests/{ => SwiftJSONTests}/NestedJSONTests.swift (100%) rename Tests/{ => SwiftJSONTests}/NumberTests.swift (100%) rename Tests/{ => SwiftJSONTests}/PerformanceTests.swift (100%) rename Tests/{ => SwiftJSONTests}/PrintableTests.swift (100%) rename Tests/{ => SwiftJSONTests}/RawRepresentableTests.swift (100%) rename Tests/{ => SwiftJSONTests}/RawTests.swift (100%) rename Tests/{ => SwiftJSONTests}/SequenceTypeTests.swift (100%) rename Tests/{ => SwiftJSONTests}/StringTests.swift (100%) rename Tests/{ => SwiftJSONTests}/SubscriptTests.swift (100%) diff --git a/Package.swift b/Package.swift index 801f1d5d..d9792b91 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,14 @@ +// swift-tools-version:5.0 import PackageDescription let package = Package( - name: "SwiftyJSON") + name: "SwiftyJSON", + products: [ + .library(name: "SwiftyJSON", targets: ["SwiftyJSON"]), + ], + dependencies: [], + targets: [ + .target(name: "SwiftyJSON", dependencies: []), + .testTarget(name: "SwiftJSONTests", dependencies: ["SwiftyJSON"]), + ] +) diff --git a/Source/SwiftyJSON.h b/Source/SwiftyJSON/SwiftyJSON.h similarity index 100% rename from Source/SwiftyJSON.h rename to Source/SwiftyJSON/SwiftyJSON.h diff --git a/Source/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift similarity index 100% rename from Source/SwiftyJSON.swift rename to Source/SwiftyJSON/SwiftyJSON.swift diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index be176003..7b08ff75 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -114,37 +114,37 @@ /* Begin PBXFileReference section */ 030B6CDC1A6E171D00C2D4F1 /* Info-macOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-macOS.plist"; sourceTree = ""; }; - 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MergeTests.swift; path = ../MergeTests.swift; sourceTree = ""; }; + 1B587CC41DDE04360012D8DB /* MergeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MergeTests.swift; path = ../SwiftJSONTests/MergeTests.swift; sourceTree = ""; }; 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2E4FEFDF19575BE100351305 /* Info-iOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-iOS.plist"; sourceTree = ""; }; - 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyJSON.h; sourceTree = ""; }; + 2E4FEFE019575BE100351305 /* SwiftyJSON.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SwiftyJSON.h; path = SwiftyJSON/SwiftyJSON.h; sourceTree = ""; }; 2E4FEFE619575BE100351305 /* SwiftyJSON iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - 5DD502901D9B21810004C112 /* NestedJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NestedJSONTests.swift; path = ../NestedJSONTests.swift; sourceTree = ""; }; - 712921EE2004E4EB00DA6340 /* CodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CodableTests.swift; path = ../CodableTests.swift; sourceTree = ""; }; + 5DD502901D9B21810004C112 /* NestedJSONTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NestedJSONTests.swift; path = ../SwiftJSONTests/NestedJSONTests.swift; sourceTree = ""; }; + 712921EE2004E4EB00DA6340 /* CodableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CodableTests.swift; path = ../SwiftJSONTests/CodableTests.swift; sourceTree = ""; }; 7236B4F61BAC14150020529B /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 7236B4F71BAC14150020529B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-tvOS.plist"; sourceTree = ""; }; 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Info-macOS.plist"; path = "../Info-macOS.plist"; sourceTree = ""; }; 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON macOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON macOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; - A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LiteralConvertibleTests.swift; path = ../LiteralConvertibleTests.swift; sourceTree = ""; }; - A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RawRepresentableTests.swift; path = ../RawRepresentableTests.swift; sourceTree = ""; }; - A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SubscriptTests.swift; path = ../SubscriptTests.swift; sourceTree = ""; }; - A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PrintableTests.swift; path = ../PrintableTests.swift; sourceTree = ""; }; + A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LiteralConvertibleTests.swift; path = ../SwiftJSONTests/LiteralConvertibleTests.swift; sourceTree = ""; }; + A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RawRepresentableTests.swift; path = ../SwiftJSONTests/RawRepresentableTests.swift; sourceTree = ""; }; + A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SubscriptTests.swift; path = ../SwiftJSONTests/SubscriptTests.swift; sourceTree = ""; }; + A819C4A019E37FC600ADCC3D /* PrintableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PrintableTests.swift; path = ../SwiftJSONTests/PrintableTests.swift; sourceTree = ""; }; A82A1C0D19D922DC009A653D /* Info-iOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Info-iOS.plist"; path = "../Info-iOS.plist"; sourceTree = ""; }; - A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MutabilityTests.swift; path = ../MutabilityTests.swift; sourceTree = ""; }; - A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftyJSON.swift; sourceTree = ""; }; + A830A6941E5B2DD8001D7F6D /* MutabilityTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MutabilityTests.swift; path = ../SwiftJSONTests/MutabilityTests.swift; sourceTree = ""; }; + A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftyJSON.swift; path = SwiftyJSON/SwiftyJSON.swift; sourceTree = ""; }; A8580F741BCF5C5B00DA927B /* SwiftyJSON tvOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON tvOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; A8580F781BCF5C5B00DA927B /* Info-tvOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "Info-tvOS.plist"; path = "../Info-tvOS.plist"; sourceTree = ""; }; - A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RawTests.swift; path = ../RawTests.swift; sourceTree = ""; }; - A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PerformanceTests.swift; path = ../PerformanceTests.swift; sourceTree = ""; }; - A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SequenceTypeTests.swift; path = ../SequenceTypeTests.swift; sourceTree = ""; }; - A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ComparableTests.swift; path = ../ComparableTests.swift; sourceTree = ""; }; - A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberTests.swift; path = ../NumberTests.swift; sourceTree = ""; }; - A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StringTests.swift; path = ../StringTests.swift; sourceTree = ""; }; - A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BaseTests.swift; path = ../BaseTests.swift; sourceTree = ""; }; + A863BE2719EED46F0092A41F /* RawTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RawTests.swift; path = ../SwiftJSONTests/RawTests.swift; sourceTree = ""; }; + A86BAA0D19EBC32B009EAAEB /* PerformanceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PerformanceTests.swift; path = ../SwiftJSONTests/PerformanceTests.swift; sourceTree = ""; }; + A87080E319E3C2A600CDE086 /* SequenceTypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SequenceTypeTests.swift; path = ../SwiftJSONTests/SequenceTypeTests.swift; sourceTree = ""; }; + A87080E519E3DF7800CDE086 /* ComparableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ComparableTests.swift; path = ../SwiftJSONTests/ComparableTests.swift; sourceTree = ""; }; + A87080E719E439DA00CDE086 /* NumberTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NumberTests.swift; path = ../SwiftJSONTests/NumberTests.swift; sourceTree = ""; }; + A87080E919E43C0700CDE086 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = StringTests.swift; path = ../SwiftJSONTests/StringTests.swift; sourceTree = ""; }; + A885D1D119CF1EE6002FD4C3 /* BaseTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = BaseTests.swift; path = ../SwiftJSONTests/BaseTests.swift; sourceTree = ""; }; A885D1DA19CFCFF0002FD4C3 /* Tests.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Tests.json; sourceTree = ""; }; - A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DictionaryTests.swift; path = ../DictionaryTests.swift; sourceTree = ""; }; - A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArrayTests.swift; path = ../ArrayTests.swift; sourceTree = ""; }; + A8B66C8B19E51D6500540692 /* DictionaryTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DictionaryTests.swift; path = ../SwiftJSONTests/DictionaryTests.swift; sourceTree = ""; }; + A8B66C8D19E52F4200540692 /* ArrayTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ArrayTests.swift; path = ../SwiftJSONTests/ArrayTests.swift; sourceTree = ""; }; E4D7CCE81B9465A700EE7221 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "Info-watchOS.plist"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -502,6 +502,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, ); mainGroup = 2E4FEFD119575BE100351305; diff --git a/SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/SwiftyJSON.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Tests/ArrayTests.swift b/Tests/SwiftJSONTests/ArrayTests.swift similarity index 100% rename from Tests/ArrayTests.swift rename to Tests/SwiftJSONTests/ArrayTests.swift diff --git a/Tests/BaseTests.swift b/Tests/SwiftJSONTests/BaseTests.swift similarity index 99% rename from Tests/BaseTests.swift rename to Tests/SwiftJSONTests/BaseTests.swift index 16dab02c..9139c204 100644 --- a/Tests/BaseTests.swift +++ b/Tests/SwiftJSONTests/BaseTests.swift @@ -31,6 +31,8 @@ class BaseTests: XCTestCase { super.setUp() +// let file = "./Tests/Tes/Tests.json" +// self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) if let file = Bundle(for: BaseTests.self).path(forResource: "Tests", ofType: "json") { self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) } else { diff --git a/Tests/CodableTests.swift b/Tests/SwiftJSONTests/CodableTests.swift similarity index 100% rename from Tests/CodableTests.swift rename to Tests/SwiftJSONTests/CodableTests.swift diff --git a/Tests/ComparableTests.swift b/Tests/SwiftJSONTests/ComparableTests.swift similarity index 100% rename from Tests/ComparableTests.swift rename to Tests/SwiftJSONTests/ComparableTests.swift diff --git a/Tests/DictionaryTests.swift b/Tests/SwiftJSONTests/DictionaryTests.swift similarity index 100% rename from Tests/DictionaryTests.swift rename to Tests/SwiftJSONTests/DictionaryTests.swift diff --git a/Tests/LiteralConvertibleTests.swift b/Tests/SwiftJSONTests/LiteralConvertibleTests.swift similarity index 100% rename from Tests/LiteralConvertibleTests.swift rename to Tests/SwiftJSONTests/LiteralConvertibleTests.swift diff --git a/Tests/MergeTests.swift b/Tests/SwiftJSONTests/MergeTests.swift similarity index 100% rename from Tests/MergeTests.swift rename to Tests/SwiftJSONTests/MergeTests.swift diff --git a/Tests/MutabilityTests.swift b/Tests/SwiftJSONTests/MutabilityTests.swift similarity index 100% rename from Tests/MutabilityTests.swift rename to Tests/SwiftJSONTests/MutabilityTests.swift diff --git a/Tests/NestedJSONTests.swift b/Tests/SwiftJSONTests/NestedJSONTests.swift similarity index 100% rename from Tests/NestedJSONTests.swift rename to Tests/SwiftJSONTests/NestedJSONTests.swift diff --git a/Tests/NumberTests.swift b/Tests/SwiftJSONTests/NumberTests.swift similarity index 100% rename from Tests/NumberTests.swift rename to Tests/SwiftJSONTests/NumberTests.swift diff --git a/Tests/PerformanceTests.swift b/Tests/SwiftJSONTests/PerformanceTests.swift similarity index 100% rename from Tests/PerformanceTests.swift rename to Tests/SwiftJSONTests/PerformanceTests.swift diff --git a/Tests/PrintableTests.swift b/Tests/SwiftJSONTests/PrintableTests.swift similarity index 100% rename from Tests/PrintableTests.swift rename to Tests/SwiftJSONTests/PrintableTests.swift diff --git a/Tests/RawRepresentableTests.swift b/Tests/SwiftJSONTests/RawRepresentableTests.swift similarity index 100% rename from Tests/RawRepresentableTests.swift rename to Tests/SwiftJSONTests/RawRepresentableTests.swift diff --git a/Tests/RawTests.swift b/Tests/SwiftJSONTests/RawTests.swift similarity index 100% rename from Tests/RawTests.swift rename to Tests/SwiftJSONTests/RawTests.swift diff --git a/Tests/SequenceTypeTests.swift b/Tests/SwiftJSONTests/SequenceTypeTests.swift similarity index 100% rename from Tests/SequenceTypeTests.swift rename to Tests/SwiftJSONTests/SequenceTypeTests.swift diff --git a/Tests/StringTests.swift b/Tests/SwiftJSONTests/StringTests.swift similarity index 100% rename from Tests/StringTests.swift rename to Tests/SwiftJSONTests/StringTests.swift diff --git a/Tests/SubscriptTests.swift b/Tests/SwiftJSONTests/SubscriptTests.swift similarity index 100% rename from Tests/SubscriptTests.swift rename to Tests/SwiftJSONTests/SubscriptTests.swift From f7ec2badf80fd27ab5f2bd15599530bed41717e7 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 2 Apr 2019 15:08:09 +0800 Subject: [PATCH 438/470] Bump pod version to 4.3.0 and update ci image to Xcode 10.2 --- .travis.yml | 2 +- SwiftyJSON.podspec | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 34acdea7..17140ab1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode10 +osx_image: xcode10.2 xcode_sdk: iphonesimulator12.0 script: - set -o pipefail diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index d5fbc3d1..d486f0a1 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,13 +1,13 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "4.2.0" + s.version = "4.3.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } s.authors = { "lingoer" => "lingoerer@gmail.com", "tangplin" => "tangplin@gmail.com" } s.requires_arc = true - s.swift_version = "4.2" + s.swift_version = "5.0" s.osx.deployment_target = "10.9" s.ios.deployment_target = "8.0" s.watchos.deployment_target = "3.0" From e0511293fcdc0a31f585370be8623e745ec34403 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Tue, 2 Apr 2019 15:54:01 +0800 Subject: [PATCH 439/470] Update project settings --- Example/Example.xcodeproj/project.pbxproj | 12 +++---- Example/Example/AppDelegate.swift | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 36 ++++++++++--------- .../xcschemes/SwiftyJSON iOS.xcscheme | 2 +- .../xcschemes/SwiftyJSON macOS.xcscheme | 2 +- .../xcschemes/SwiftyJSON tvOS.xcscheme | 2 +- .../xcschemes/SwiftyJSON watchOS.xcscheme | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index 54e81356..a58da571 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -124,19 +124,19 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = swiftyjson; TargetAttributes = { A82A1C1819D926B8009A653D = { CreatedOnToolsVersion = 6.0.1; - LastSwiftMigration = 0930; + LastSwiftMigration = 1020; ProvisioningStyle = Manual; }; }; }; buildConfigurationList = A82A1C1419D926B8009A653D /* Build configuration list for PBXProject "Example" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, @@ -313,8 +313,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -329,8 +328,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/Example/Example/AppDelegate.swift b/Example/Example/AppDelegate.swift index e2af9aa6..c4236b1d 100644 --- a/Example/Example/AppDelegate.swift +++ b/Example/Example/AppDelegate.swift @@ -28,7 +28,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { let navigationController = self.window?.rootViewController as! UINavigationController let viewController = navigationController.topViewController as! ViewController diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 7b08ff75..8160930b 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -457,7 +457,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; TargetAttributes = { 2E4FEFDA19575BE100351305 = { CreatedOnToolsVersion = 6.0; @@ -499,11 +499,11 @@ }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( - English, en, + Base, ); mainGroup = 2E4FEFD119575BE100351305; productRefGroup = 2E4FEFDC19575BE100351305 /* Products */; @@ -723,6 +723,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; @@ -783,6 +784,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; @@ -854,7 +856,7 @@ SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -878,7 +880,7 @@ PRODUCT_NAME = SwiftyJSON; SKIP_INSTALL = YES; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -900,7 +902,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -917,7 +919,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -942,7 +944,7 @@ SDKROOT = appletvos; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -968,7 +970,7 @@ PRODUCT_NAME = SwiftyJSON; SDKROOT = appletvos; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -1001,7 +1003,7 @@ SDKROOT = macosx; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1028,7 +1030,7 @@ PRODUCT_NAME = "$(PROJECT_NAME)"; SDKROOT = macosx; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1051,7 +1053,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -1070,7 +1072,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -1104,7 +1106,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Debug; @@ -1123,7 +1125,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.tangplin.SwiftyJSON-tvOS-Tests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 9.0; }; name = Release; @@ -1150,7 +1152,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 3.0; }; @@ -1177,7 +1179,7 @@ SDKROOT = watchos; SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "watchsimulator watchos"; - SWIFT_VERSION = 4.2; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 3.0; }; diff --git a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme index 98076542..f4d10cb9 100644 --- a/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme +++ b/SwiftyJSON.xcodeproj/xcshareddata/xcschemes/SwiftyJSON iOS.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 2 Apr 2019 18:39:43 +0800 Subject: [PATCH 440/470] chore: improve code base --- Example/Example.xcodeproj/project.pbxproj | 2 +- Example/Playground.playground/Contents.swift | 1 - Package.swift | 11 +- Source/SwiftyJSON/SwiftyJSON.swift | 575 ++++++++----------- SwiftyJSON.podspec | 2 +- 5 files changed, 234 insertions(+), 357 deletions(-) diff --git a/Example/Example.xcodeproj/project.pbxproj b/Example/Example.xcodeproj/project.pbxproj index a58da571..e0a5e55e 100644 --- a/Example/Example.xcodeproj/project.pbxproj +++ b/Example/Example.xcodeproj/project.pbxproj @@ -32,7 +32,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 04294C501BE5A9DE00D0397E /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = ""; }; + 04294C501BE5A9DE00D0397E /* Playground.playground */ = {isa = PBXFileReference; lastKnownFileType = file.playground; path = Playground.playground; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 04733F511D92E6ED002E3A99 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A82A1C1919D926B8009A653D /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; A82A1C1D19D926B8009A653D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; diff --git a/Example/Playground.playground/Contents.swift b/Example/Playground.playground/Contents.swift index 9306d850..7542d181 100644 --- a/Example/Playground.playground/Contents.swift +++ b/Example/Playground.playground/Contents.swift @@ -29,7 +29,6 @@ let jsonString = String(data: jsonData!, encoding: .utf8) ### Initialization */ -import SwiftyJSON let json1 = try? JSON(data: jsonData!) /*: diff --git a/Package.swift b/Package.swift index d9792b91..1a60e2e7 100644 --- a/Package.swift +++ b/Package.swift @@ -3,12 +3,15 @@ import PackageDescription let package = Package( name: "SwiftyJSON", + platforms: [ + .macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v3) + ], products: [ - .library(name: "SwiftyJSON", targets: ["SwiftyJSON"]), + .library(name: "SwiftyJSON", targets: ["SwiftyJSON"]) ], - dependencies: [], targets: [ .target(name: "SwiftyJSON", dependencies: []), - .testTarget(name: "SwiftJSONTests", dependencies: ["SwiftyJSON"]), - ] + .testTarget(name: "SwiftJSONTests", dependencies: ["SwiftyJSON"]) + ], + swiftLanguageVersions: [.v5] ) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index a6c1f3a6..f7a3f085 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -138,7 +138,7 @@ public struct JSON { - returns: The created JSON */ fileprivate init(jsonObject: Any) { - self.object = jsonObject + object = jsonObject } /** @@ -174,14 +174,14 @@ public struct JSON { Typecheck is set to true for the first recursion level to prevent total override of the source JSON */ fileprivate mutating func merge(with other: JSON, typecheck: Bool) throws { - if self.type == other.type { - switch self.type { + if type == other.type { + switch type { case .dictionary: for (key, _) in other { try self[key].merge(with: other[key], typecheck: false) } case .array: - self = JSON(self.arrayValue + other.arrayValue) + self = JSON(arrayValue + other.arrayValue) default: self = other } @@ -211,19 +211,13 @@ public struct JSON { /// Object in JSON public var object: Any { get { - switch self.type { - case .array: - return self.rawArray - case .dictionary: - return self.rawDictionary - case .string: - return self.rawString - case .number: - return self.rawNumber - case .bool: - return self.rawBool - default: - return self.rawNull + switch type { + case .array: return rawArray + case .dictionary: return rawDictionary + case .string: return rawString + case .number: return rawNumber + case .bool: return rawBool + default: return rawNull } } set { @@ -232,24 +226,24 @@ public struct JSON { case let number as NSNumber: if number.isBool { type = .bool - self.rawBool = number.boolValue + rawBool = number.boolValue } else { type = .number - self.rawNumber = number + rawNumber = number } case let string as String: type = .string - self.rawString = string + rawString = string case _ as NSNull: type = .null case nil: type = .null case let array as [Any]: type = .array - self.rawArray = array + rawArray = array case let dictionary as [String: Any]: type = .dictionary - self.rawDictionary = dictionary + rawDictionary = dictionary default: type = .unknown error = SwiftyJSONError.unsupportedType @@ -271,11 +265,11 @@ private func unwrap(_ object: Any) -> Any { case let array as [Any]: return array.map(unwrap) case let dictionary as [String: Any]: - var unwrappedDic = dictionary - for (k, v) in dictionary { - unwrappedDic[k] = unwrap(v) + var d = dictionary + dictionary.forEach { pair in + d[pair.key] = unwrap(pair.value) } - return unwrappedDic + return d default: return object } @@ -288,24 +282,18 @@ public enum Index: Comparable { static public func == (lhs: Index, rhs: Index) -> Bool { switch (lhs, rhs) { - case (.array(let left), .array(let right)): - return left == right - case (.dictionary(let left), .dictionary(let right)): - return left == right - case (.null, .null): return true - default: - return false + case (.array(let left), .array(let right)): return left == right + case (.dictionary(let left), .dictionary(let right)): return left == right + case (.null, .null): return true + default: return false } } static public func < (lhs: Index, rhs: Index) -> Bool { switch (lhs, rhs) { - case (.array(let left), .array(let right)): - return left < right - case (.dictionary(let left), .dictionary(let right)): - return left < right - default: - return false + case (.array(let left), .array(let right)): return left < right + case (.dictionary(let left), .dictionary(let right)): return left < right + default: return false } } } @@ -319,46 +307,33 @@ extension JSON: Swift.Collection { public var startIndex: Index { switch type { - case .array: - return .array(rawArray.startIndex) - case .dictionary: - return .dictionary(rawDictionary.startIndex) - default: - return .null + case .array: return .array(rawArray.startIndex) + case .dictionary: return .dictionary(rawDictionary.startIndex) + default: return .null } } public var endIndex: Index { switch type { - case .array: - return .array(rawArray.endIndex) - case .dictionary: - return .dictionary(rawDictionary.endIndex) - default: - return .null + case .array: return .array(rawArray.endIndex) + case .dictionary: return .dictionary(rawDictionary.endIndex) + default: return .null } } public func index(after i: Index) -> Index { switch i { - case .array(let idx): - return .array(rawArray.index(after: idx)) - case .dictionary(let idx): - return .dictionary(rawDictionary.index(after: idx)) - default: - return .null + case .array(let idx): return .array(rawArray.index(after: idx)) + case .dictionary(let idx): return .dictionary(rawDictionary.index(after: idx)) + default: return .null } } public subscript (position: Index) -> (String, JSON) { switch position { - case .array(let idx): - return (String(idx), JSON(self.rawArray[idx])) - case .dictionary(let idx): - let (key, value) = self.rawDictionary[idx] - return (key, JSON(value)) - default: - return ("", JSON.null) + case .array(let idx): return (String(idx), JSON(rawArray[idx])) + case .dictionary(let idx): return (rawDictionary[idx].key, JSON(rawDictionary[idx].value)) + default: return ("", JSON.null) } } } @@ -394,12 +369,12 @@ extension JSON { /// If `type` is `.array`, return json whose object is `array[index]`, otherwise return null json with error. fileprivate subscript(index index: Int) -> JSON { get { - if self.type != .array { + if type != .array { var r = JSON.null r.error = self.error ?? SwiftyJSONError.wrongType return r - } else if self.rawArray.indices.contains(index) { - return JSON(self.rawArray[index]) + } else if rawArray.indices.contains(index) { + return JSON(rawArray[index]) } else { var r = JSON.null r.error = SwiftyJSONError.indexOutOfBounds @@ -407,10 +382,10 @@ extension JSON { } } set { - if self.type == .array && - self.rawArray.indices.contains(index) && + if type == .array && + rawArray.indices.contains(index) && newValue.error == nil { - self.rawArray[index] = newValue.object + rawArray[index] = newValue.object } } } @@ -419,8 +394,8 @@ extension JSON { fileprivate subscript(key key: String) -> JSON { get { var r = JSON.null - if self.type == .dictionary { - if let o = self.rawDictionary[key] { + if type == .dictionary { + if let o = rawDictionary[key] { r = JSON(o) } else { r.error = SwiftyJSONError.notExist @@ -431,8 +406,8 @@ extension JSON { return r } set { - if self.type == .dictionary && newValue.error == nil { - self.rawDictionary[key] = newValue.object + if type == .dictionary && newValue.error == nil { + rawDictionary[key] = newValue.object } } } @@ -442,13 +417,13 @@ extension JSON { get { switch sub.jsonKey { case .index(let index): return self[index: index] - case .key(let key): return self[key: key] + case .key(let key): return self[key: key] } } set { switch sub.jsonKey { case .index(let index): self[index: index] = newValue - case .key(let key): self[key: key] = newValue + case .key(let key): self[key: key] = newValue } } } @@ -476,10 +451,8 @@ extension JSON { } set { switch path.count { - case 0: - return - case 1: - self[sub:path[0]].object = newValue.object + case 0: return + case 1: self[sub:path[0]].object = newValue.object default: var aPath = path aPath.remove(at: 0) @@ -576,15 +549,15 @@ extension JSON: Swift.RawRepresentable { } public var rawValue: Any { - return self.object + return object } public func rawData(options opt: JSONSerialization.WritingOptions = JSONSerialization.WritingOptions(rawValue: 0)) throws -> Data { - guard JSONSerialization.isValidJSONObject(self.object) else { + guard JSONSerialization.isValidJSONObject(object) else { throw SwiftyJSONError.invalidJSON } - return try JSONSerialization.data(withJSONObject: self.object, options: opt) + return try JSONSerialization.data(withJSONObject: object, options: opt) } public func rawString(_ encoding: String.Encoding = .utf8, options opt: JSONSerialization.WritingOptions = .prettyPrinted) -> String? { @@ -609,16 +582,16 @@ extension JSON: Swift.RawRepresentable { fileprivate func _rawString(_ encoding: String.Encoding = .utf8, options: [writingOptionsKeys: Any], maxObjectDepth: Int = 10) throws -> String? { guard maxObjectDepth > 0 else { throw SwiftyJSONError.invalidJSON } - switch self.type { + switch type { case .dictionary: do { if !(options[.castNilToNSNull] as? Bool ?? false) { let jsonOption = options[.jsonSerialization] as? JSONSerialization.WritingOptions ?? JSONSerialization.WritingOptions.prettyPrinted - let data = try self.rawData(options: jsonOption) + let data = try rawData(options: jsonOption) return String(data: data, encoding: encoding) } - guard let dict = self.object as? [String: Any?] else { + guard let dict = object as? [String: Any?] else { return nil } let body = try dict.keys.map { key throws -> String in @@ -648,11 +621,11 @@ extension JSON: Swift.RawRepresentable { do { if !(options[.castNilToNSNull] as? Bool ?? false) { let jsonOption = options[.jsonSerialization] as? JSONSerialization.WritingOptions ?? JSONSerialization.WritingOptions.prettyPrinted - let data = try self.rawData(options: jsonOption) + let data = try rawData(options: jsonOption) return String(data: data, encoding: encoding) } - guard let array = self.object as? [Any?] else { + guard let array = object as? [Any?] else { return nil } let body = try array.map { value throws -> String in @@ -675,16 +648,11 @@ extension JSON: Swift.RawRepresentable { } catch _ { return nil } - case .string: - return self.rawString - case .number: - return self.rawNumber.stringValue - case .bool: - return self.rawBool.description - case .null: - return "null" - default: - return nil + case .string: return rawString + case .number: return rawNumber.stringValue + case .bool: return rawBool.description + case .null: return "null" + default: return nil } } } @@ -694,11 +662,7 @@ extension JSON: Swift.RawRepresentable { extension JSON: Swift.CustomStringConvertible, Swift.CustomDebugStringConvertible { public var description: String { - if let string = self.rawString(options: .prettyPrinted) { - return string - } else { - return "unknown" - } + return rawString(options: .prettyPrinted) ?? "unknown" } public var debugDescription: String { @@ -712,11 +676,7 @@ extension JSON { //Optional [JSON] public var array: [JSON]? { - if self.type == .array { - return self.rawArray.map { JSON($0) } - } else { - return nil - } + return type == .array ? rawArray.map { JSON($0) } : nil } //Non-optional [JSON] @@ -727,19 +687,13 @@ extension JSON { //Optional [Any] public var arrayObject: [Any]? { get { - switch self.type { - case .array: - return self.rawArray - default: - return nil + switch type { + case .array: return rawArray + default: return nil } } set { - if let array = newValue { - self.object = array - } else { - self.object = NSNull() - } + self.object = newValue ?? NSNull() } } } @@ -750,10 +704,10 @@ extension JSON { //Optional [String : JSON] public var dictionary: [String: JSON]? { - if self.type == .dictionary { + if type == .dictionary { var d = [String: JSON](minimumCapacity: rawDictionary.count) - for (key, value) in rawDictionary { - d[key] = JSON(value) + rawDictionary.forEach { pair in + d[pair.key] = JSON(pair.value) } return d } else { @@ -763,26 +717,20 @@ extension JSON { //Non-optional [String : JSON] public var dictionaryValue: [String: JSON] { - return self.dictionary ?? [:] + return dictionary ?? [:] } //Optional [String : Any] public var dictionaryObject: [String: Any]? { get { - switch self.type { - case .dictionary: - return self.rawDictionary - default: - return nil + switch type { + case .dictionary: return rawDictionary + default: return nil } } set { - if let v = newValue { - self.object = v - } else { - self.object = NSNull() - } + object = newValue ?? NSNull() } } } @@ -794,38 +742,28 @@ extension JSON { // : Swift.Bool //Optional bool public var bool: Bool? { get { - switch self.type { - case .bool: - return self.rawBool - default: - return nil + switch type { + case .bool: return rawBool + default: return nil } } set { - if let newValue = newValue { - self.object = newValue as Bool - } else { - self.object = NSNull() - } + object = newValue ?? NSNull() } } //Non-optional bool public var boolValue: Bool { get { - switch self.type { - case .bool: - return self.rawBool - case .number: - return self.rawNumber.boolValue - case .string: - return ["true", "y", "t", "yes", "1"].contains { self.rawString.caseInsensitiveCompare($0) == .orderedSame } - default: - return false + switch type { + case .bool: return rawBool + case .number: return rawNumber.boolValue + case .string: return ["true", "y", "t", "yes", "1"].contains { rawString.caseInsensitiveCompare($0) == .orderedSame } + default: return false } } set { - self.object = newValue + object = newValue } } } @@ -837,38 +775,28 @@ extension JSON { //Optional string public var string: String? { get { - switch self.type { - case .string: - return self.object as? String - default: - return nil + switch type { + case .string: return object as? String + default: return nil } } set { - if let newValue = newValue { - self.object = NSString(string: newValue) - } else { - self.object = NSNull() - } + object = newValue ?? NSNull() } } //Non-optional string public var stringValue: String { get { - switch self.type { - case .string: - return self.object as? String ?? "" - case .number: - return self.rawNumber.stringValue - case .bool: - return (self.object as? Bool).map { String($0) } ?? "" - default: - return "" + switch type { + case .string: return object as? String ?? "" + case .number: return rawNumber.stringValue + case .bool: return (object as? Bool).map { String($0) } ?? "" + default: return "" } } set { - self.object = NSString(string: newValue) + object = newValue } } } @@ -880,40 +808,31 @@ extension JSON { //Optional number public var number: NSNumber? { get { - switch self.type { - case .number: - return self.rawNumber - case .bool: - return NSNumber(value: self.rawBool ? 1 : 0) - default: - return nil + switch type { + case .number: return rawNumber + case .bool: return NSNumber(value: rawBool ? 1 : 0) + default: return nil } } set { - self.object = newValue ?? NSNull() + object = newValue ?? NSNull() } } //Non-optional number public var numberValue: NSNumber { get { - switch self.type { + switch type { case .string: - let decimal = NSDecimalNumber(string: self.object as? String) - if decimal == NSDecimalNumber.notANumber { // indicates parse error - return NSDecimalNumber.zero - } - return decimal - case .number: - return self.object as? NSNumber ?? NSNumber(value: 0) - case .bool: - return NSNumber(value: self.rawBool ? 1 : 0) - default: - return NSNumber(value: 0.0) + let decimal = NSDecimalNumber(string: object as? String) + return decimal == .notANumber ? .zero : decimal + case .number: return object as? NSNumber ?? NSNumber(value: 0) + case .bool: return NSNumber(value: rawBool ? 1 : 0) + default: return NSNumber(value: 0.0) } } set { - self.object = newValue + object = newValue } } } @@ -923,17 +842,15 @@ extension JSON { extension JSON { public var null: NSNull? { + set { + object = NSNull() + } get { - switch self.type { - case .null: - return self.rawNull - default: - return nil + switch type { + case .null: return rawNull + default: return nil } } - set { - self.object = NSNull() - } } public func exists() -> Bool { if let errorValue = error, (400...1000).contains(errorValue.errorCode) { @@ -950,12 +867,12 @@ extension JSON { //Optional URL public var url: URL? { get { - switch self.type { + switch type { case .string: // Check for existing percent escapes first to prevent double-escaping of % character - if self.rawString.range(of: "%[0-9A-Fa-f]{2}", options: .regularExpression, range: nil, locale: nil) != nil { - return Foundation.URL(string: self.rawString) - } else if let encodedString_ = self.rawString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { + if rawString.range(of: "%[0-9A-Fa-f]{2}", options: .regularExpression, range: nil, locale: nil) != nil { + return Foundation.URL(string: rawString) + } else if let encodedString_ = rawString.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) { // We have to use `Foundation.URL` otherwise it conflicts with the variable name. return Foundation.URL(string: encodedString_) } else { @@ -966,7 +883,7 @@ extension JSON { } } set { - self.object = newValue?.absoluteString ?? NSNull() + object = newValue?.absoluteString ?? NSNull() } } } @@ -977,265 +894,265 @@ extension JSON { public var double: Double? { get { - return self.number?.doubleValue + return number?.doubleValue } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var doubleValue: Double { get { - return self.numberValue.doubleValue + return numberValue.doubleValue } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var float: Float? { get { - return self.number?.floatValue + return number?.floatValue } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var floatValue: Float { get { - return self.numberValue.floatValue + return numberValue.floatValue } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var int: Int? { get { - return self.number?.intValue + return number?.intValue } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var intValue: Int { get { - return self.numberValue.intValue + return numberValue.intValue } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var uInt: UInt? { get { - return self.number?.uintValue + return number?.uintValue } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var uIntValue: UInt { get { - return self.numberValue.uintValue + return numberValue.uintValue } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var int8: Int8? { get { - return self.number?.int8Value + return number?.int8Value } set { if let newValue = newValue { - self.object = NSNumber(value: Int(newValue)) + object = NSNumber(value: Int(newValue)) } else { - self.object = NSNull() + object = NSNull() } } } public var int8Value: Int8 { get { - return self.numberValue.int8Value + return numberValue.int8Value } set { - self.object = NSNumber(value: Int(newValue)) + object = NSNumber(value: Int(newValue)) } } public var uInt8: UInt8? { get { - return self.number?.uint8Value + return number?.uint8Value } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var uInt8Value: UInt8 { get { - return self.numberValue.uint8Value + return numberValue.uint8Value } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var int16: Int16? { get { - return self.number?.int16Value + return number?.int16Value } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var int16Value: Int16 { get { - return self.numberValue.int16Value + return numberValue.int16Value } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var uInt16: UInt16? { get { - return self.number?.uint16Value + return number?.uint16Value } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var uInt16Value: UInt16 { get { - return self.numberValue.uint16Value + return numberValue.uint16Value } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var int32: Int32? { get { - return self.number?.int32Value + return number?.int32Value } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var int32Value: Int32 { get { - return self.numberValue.int32Value + return numberValue.int32Value } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var uInt32: UInt32? { get { - return self.number?.uint32Value + return number?.uint32Value } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var uInt32Value: UInt32 { get { - return self.numberValue.uint32Value + return numberValue.uint32Value } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var int64: Int64? { get { - return self.number?.int64Value + return number?.int64Value } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var int64Value: Int64 { get { - return self.numberValue.int64Value + return numberValue.int64Value } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } public var uInt64: UInt64? { get { - return self.number?.uint64Value + return number?.uint64Value } set { if let newValue = newValue { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } else { - self.object = NSNull() + object = NSNull() } } } public var uInt64Value: UInt64 { get { - return self.numberValue.uint64Value + return numberValue.uint64Value } set { - self.object = NSNumber(value: newValue) + object = NSNumber(value: newValue) } } } @@ -1247,84 +1164,57 @@ extension JSON: Swift.Comparable {} public func == (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.number, .number): - return lhs.rawNumber == rhs.rawNumber - case (.string, .string): - return lhs.rawString == rhs.rawString - case (.bool, .bool): - return lhs.rawBool == rhs.rawBool - case (.array, .array): - return lhs.rawArray as NSArray == rhs.rawArray as NSArray - case (.dictionary, .dictionary): - return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary - case (.null, .null): - return true - default: - return false + case (.number, .number): return lhs.rawNumber == rhs.rawNumber + case (.string, .string): return lhs.rawString == rhs.rawString + case (.bool, .bool): return lhs.rawBool == rhs.rawBool + case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray + case (.dictionary, .dictionary): return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary + case (.null, .null): return true + default: return false } } public func <= (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.number, .number): - return lhs.rawNumber <= rhs.rawNumber - case (.string, .string): - return lhs.rawString <= rhs.rawString - case (.bool, .bool): - return lhs.rawBool == rhs.rawBool - case (.array, .array): - return lhs.rawArray as NSArray == rhs.rawArray as NSArray - case (.dictionary, .dictionary): - return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary - case (.null, .null): - return true - default: - return false + case (.number, .number): return lhs.rawNumber <= rhs.rawNumber + case (.string, .string): return lhs.rawString <= rhs.rawString + case (.bool, .bool): return lhs.rawBool == rhs.rawBool + case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray + case (.dictionary, .dictionary): return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary + case (.null, .null): return true + default: return false } } public func >= (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.number, .number): - return lhs.rawNumber >= rhs.rawNumber - case (.string, .string): - return lhs.rawString >= rhs.rawString - case (.bool, .bool): - return lhs.rawBool == rhs.rawBool - case (.array, .array): - return lhs.rawArray as NSArray == rhs.rawArray as NSArray - case (.dictionary, .dictionary): - return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary - case (.null, .null): - return true - default: - return false + case (.number, .number): return lhs.rawNumber >= rhs.rawNumber + case (.string, .string): return lhs.rawString >= rhs.rawString + case (.bool, .bool): return lhs.rawBool == rhs.rawBool + case (.array, .array): return lhs.rawArray as NSArray == rhs.rawArray as NSArray + case (.dictionary, .dictionary): return lhs.rawDictionary as NSDictionary == rhs.rawDictionary as NSDictionary + case (.null, .null): return true + default: return false } } public func > (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.number, .number): - return lhs.rawNumber > rhs.rawNumber - case (.string, .string): - return lhs.rawString > rhs.rawString - default: - return false + case (.number, .number): return lhs.rawNumber > rhs.rawNumber + case (.string, .string): return lhs.rawString > rhs.rawString + default: return false } } public func < (lhs: JSON, rhs: JSON) -> Bool { switch (lhs.type, rhs.type) { - case (.number, .number): - return lhs.rawNumber < rhs.rawNumber - case (.string, .string): - return lhs.rawString < rhs.rawString - default: - return false + case (.number, .number): return lhs.rawNumber < rhs.rawNumber + case (.string, .string): return lhs.rawString < rhs.rawString + default: return false } } @@ -1348,12 +1238,9 @@ extension NSNumber { func == (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == .orderedSame + case (false, true): return false + case (true, false): return false + default: return lhs.compare(rhs) == .orderedSame } } @@ -1364,48 +1251,36 @@ func != (lhs: NSNumber, rhs: NSNumber) -> Bool { func < (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == .orderedAscending + case (false, true): return false + case (true, false): return false + default: return lhs.compare(rhs) == .orderedAscending } } func > (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) == ComparisonResult.orderedDescending + case (false, true): return false + case (true, false): return false + default: return lhs.compare(rhs) == ComparisonResult.orderedDescending } } func <= (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) != .orderedDescending + case (false, true): return false + case (true, false): return false + default: return lhs.compare(rhs) != .orderedDescending } } func >= (lhs: NSNumber, rhs: NSNumber) -> Bool { switch (lhs.isBool, rhs.isBool) { - case (false, true): - return false - case (true, false): - return false - default: - return lhs.compare(rhs) != .orderedAscending + case (false, true): return false + case (true, false): return false + default: return lhs.compare(rhs) != .orderedAscending } } diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index d486f0a1..db895774 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -13,5 +13,5 @@ Pod::Spec.new do |s| s.watchos.deployment_target = "3.0" s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => s.version } - s.source_files = "Source/*.swift" + s.source_files = "Source/SwiftyJSON/*.swift" end From bad5f2f94a71216a32c030a3586bdcfc1f7e660b Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Mon, 15 Apr 2019 23:01:18 +0800 Subject: [PATCH 441/470] Bump to 5.0.0 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index db895774..c12cfbd8 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "4.3.0" + s.version = "5.0.0" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From d68db819a15f70dfc00d000977d4e64ce25a8b58 Mon Sep 17 00:00:00 2001 From: Tony Klausing Date: Fri, 6 Mar 2020 15:11:29 -0600 Subject: [PATCH 442/470] removed broken link --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 7a10e29c..49a5f64e 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,6 @@ Platform | Build Status 6. [Work with Moya](#work-with-moya) 7. [SwiftyJSON Model Generator](#swiftyjson-model-generator) -> [中文介绍](http://tangplin.github.io/swiftyjson/) - ## Why is the typical JSON handling in Swift NOT good? From 774f1e2b01b16e7e399b4e057d2f7b9c8526ba1a Mon Sep 17 00:00:00 2001 From: Denys Telezhkin Date: Tue, 11 Aug 2020 13:21:06 +0300 Subject: [PATCH 443/470] Bump iOS deployment target to iOS 9. Remove platforms from Package.swift. --- Package.swift | 3 --- SwiftyJSON.podspec | 2 +- SwiftyJSON.xcodeproj/project.pbxproj | 10 ++++------ 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/Package.swift b/Package.swift index 1a60e2e7..744e95dd 100644 --- a/Package.swift +++ b/Package.swift @@ -3,9 +3,6 @@ import PackageDescription let package = Package( name: "SwiftyJSON", - platforms: [ - .macOS(.v10_10), .iOS(.v8), .tvOS(.v9), .watchOS(.v3) - ], products: [ .library(name: "SwiftyJSON", targets: ["SwiftyJSON"]) ], diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index c12cfbd8..bd821743 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -9,7 +9,7 @@ Pod::Spec.new do |s| s.requires_arc = true s.swift_version = "5.0" s.osx.deployment_target = "10.9" - s.ios.deployment_target = "8.0" + s.ios.deployment_target = "9.0" s.watchos.deployment_target = "3.0" s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => s.version } diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 8160930b..c831948d 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -767,7 +767,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 = 9.0; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -822,7 +822,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 = 9.0; MACOSX_DEPLOYMENT_TARGET = 10.9; METAL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; @@ -849,7 +849,7 @@ GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = "Source/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; @@ -874,7 +874,7 @@ GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Source/Info-iOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; @@ -937,7 +937,6 @@ GCC_OPTIMIZATION_LEVEL = 0; INFOPLIST_FILE = "Source/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; @@ -964,7 +963,6 @@ GCC_OPTIMIZATION_LEVEL = s; INFOPLIST_FILE = "Source/Info-tvOS.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.swiftyjson.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = SwiftyJSON; From 70067f581fceb94bcda070762279025515e6b365 Mon Sep 17 00:00:00 2001 From: H3RSKO <34112131+H3RSKO@users.noreply.github.com> Date: Sun, 16 Aug 2020 13:27:18 -0400 Subject: [PATCH 444/470] Updated Readme Fixed sentence structure and typo in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49a5f64e..24654150 100644 --- a/README.md +++ b/README.md @@ -464,7 +464,7 @@ If both JSONs contain a value for the same key, _mostly_ this value gets overwri - In case of both values being a `JSON.Type.array` the values form the array found in the `other` JSON getting appended to the original JSON's array value. - In case of both values being a `JSON.Type.dictionary` both JSON-values are getting merged the same way the encapsulating JSON is merged. -In case, where two fields in a JSON have a different types, the value will get always overwritten. +In a case where two fields in a JSON have different types, the value will get always overwritten. There are two different fashions for merging: `merge` modifies the original JSON, whereas `merged` works non-destructively on a copy. From b3dcd7dbd0d488e1a7077cb33b00f2083e382f07 Mon Sep 17 00:00:00 2001 From: Kyle Fang Date: Sun, 28 Mar 2021 07:46:13 +0800 Subject: [PATCH 445/470] chore: bump cocoapods version --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index bd821743..944a24b7 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "5.0.0" + s.version = "5.0.1" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From 69c58e20d11991516ac9f0f3496f252bf067295f Mon Sep 17 00:00:00 2001 From: Lewis Smith Date: Fri, 2 Apr 2021 09:16:50 +0100 Subject: [PATCH 446/470] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 24654150..a4cd321f 100644 --- a/README.md +++ b/README.md @@ -396,7 +396,7 @@ let json: JSON = "I'm a json" ``` ```swift -/ /IntegerLiteralConvertible +// IntegerLiteralConvertible let json: JSON = 12345 ``` From 84bf7837a3da22099567b737899b98af15c37a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Dahlgren?= Date: Tue, 15 Mar 2022 16:29:48 +0100 Subject: [PATCH 447/470] Reorder build phases to fix Xcode 13.3 issue --- SwiftyJSON.xcodeproj/project.pbxproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index c831948d..3f48deaa 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -328,9 +328,9 @@ isa = PBXNativeTarget; buildConfigurationList = 2E4FEFF119575BE100351305 /* Build configuration list for PBXNativeTarget "SwiftyJSON iOS" */; buildPhases = ( + 2E4FEFD819575BE100351305 /* Headers */, 2E4FEFD619575BE100351305 /* Sources */, 2E4FEFD719575BE100351305 /* Frameworks */, - 2E4FEFD819575BE100351305 /* Headers */, 2E4FEFD919575BE100351305 /* Resources */, ); buildRules = ( @@ -364,9 +364,9 @@ isa = PBXNativeTarget; buildConfigurationList = 7236B4F31BAC14150020529B /* Build configuration list for PBXNativeTarget "SwiftyJSON tvOS" */; buildPhases = ( + 7236B4F01BAC14150020529B /* Headers */, 7236B4ED1BAC14150020529B /* Sources */, 7236B4EF1BAC14150020529B /* Frameworks */, - 7236B4F01BAC14150020529B /* Headers */, 7236B4F21BAC14150020529B /* Resources */, ); buildRules = ( @@ -382,9 +382,9 @@ isa = PBXNativeTarget; buildConfigurationList = 9C7DFC6E1A9102BD005AA3F7 /* Build configuration list for PBXNativeTarget "SwiftyJSON macOS" */; buildPhases = ( + 9C7DFC581A9102BD005AA3F7 /* Headers */, 9C7DFC561A9102BD005AA3F7 /* Sources */, 9C7DFC571A9102BD005AA3F7 /* Frameworks */, - 9C7DFC581A9102BD005AA3F7 /* Headers */, 9C7DFC591A9102BD005AA3F7 /* Resources */, ); buildRules = ( @@ -436,9 +436,9 @@ isa = PBXNativeTarget; buildConfigurationList = E4D7CCE51B9465A700EE7221 /* Build configuration list for PBXNativeTarget "SwiftyJSON watchOS" */; buildPhases = ( + E4D7CCE21B9465A700EE7221 /* Headers */, E4D7CCDF1B9465A700EE7221 /* Sources */, E4D7CCE11B9465A700EE7221 /* Frameworks */, - E4D7CCE21B9465A700EE7221 /* Headers */, E4D7CCE41B9465A700EE7221 /* Resources */, ); buildRules = ( From 764c0c8b944574cd63592a452c23865f54b66d0d Mon Sep 17 00:00:00 2001 From: Luo Xiu Date: Mon, 31 Oct 2022 18:34:10 +0800 Subject: [PATCH 448/470] fix compile warning, which will be compile error in upcoming swift 6 --- Source/SwiftyJSON/SwiftyJSON.swift | 2 +- Tests/SwiftJSONTests/RawRepresentableTests.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index f7a3f085..e625810e 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -236,7 +236,7 @@ public struct JSON { rawString = string case _ as NSNull: type = .null - case nil: + case Optional.none: type = .null case let array as [Any]: type = .array diff --git a/Tests/SwiftJSONTests/RawRepresentableTests.swift b/Tests/SwiftJSONTests/RawRepresentableTests.swift index 9c628a05..88a70de8 100644 --- a/Tests/SwiftJSONTests/RawRepresentableTests.swift +++ b/Tests/SwiftJSONTests/RawRepresentableTests.swift @@ -84,6 +84,12 @@ class RawRepresentableTests: XCTestCase { if JSON(rawValue: NSObject()) != nil { XCTFail("Should not run into here") } + + do { + let n: Int? = nil + let json = JSON(n as Any) + XCTAssertEqual(json.type, .null) + } } func testArray() { From d60a635197cfe3a36440a6768c3d94563fae3ee8 Mon Sep 17 00:00:00 2001 From: Antoine Bollengier <44288655+b5i@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:43:52 +0200 Subject: [PATCH 449/470] Added better readability to a comment --- Source/SwiftyJSON/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index e625810e..6e1b9ded 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -433,7 +433,7 @@ extension JSON { Example: - ``` + ```swift let json = JSON[data] let path = [9,"list","person","name"] let name = json[path] From c27a45e6386fc869d0e0f23eda1ef61104d2770e Mon Sep 17 00:00:00 2001 From: Antoine Bollengier <44288655+b5i@users.noreply.github.com> Date: Tue, 20 Jun 2023 10:49:02 +0200 Subject: [PATCH 450/470] Comments --- Source/SwiftyJSON/SwiftyJSON.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index 6e1b9ded..c8be53c2 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -467,10 +467,14 @@ extension JSON { Find a json in the complex data structures by using array of Int and/or String as path. - parameter path: The target json's path. Example: - + ```swift let name = json[9,"list","person","name"] - - The same as: let name = json[9]["list"]["person"]["name"] + ``` + + The same as: + ```swift + let name = json[9]["list"]["person"]["name"] + ``` - returns: Return a json found by the path or a null json with error */ From c8ae6e331dba0627181d0fd91e3c844070dd628a Mon Sep 17 00:00:00 2001 From: Will Jessop Date: Thu, 10 Aug 2023 10:57:32 -0400 Subject: [PATCH 451/470] Add info on removing dictionary keys in place --- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/README.md b/README.md index a4cd321f..0b3fc855 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ Platform | Build Status - [Raw object](#raw-object) - [Literal convertibles](#literal-convertibles) - [Merging](#merging) + - [Removing elements](#removing-elements) 5. [Work with Alamofire](#work-with-alamofire) 6. [Work with Moya](#work-with-moya) 7. [SwiftyJSON Model Generator](#swiftyjson-model-generator) @@ -503,6 +504,69 @@ let updated = original.merge(with: update) // ] ``` + +#### Removing elements + +If you are storing dictionaries, you can remove elements using `dictionaryObject.removeValue(forKey:)`. This mutates the JSON object in place. + +For example: + +```swift +var object = JSON([ + "one": ["color": "blue"], + "two": ["city": "tokyo", + "country": "japan", + "foods": [ + "breakfast": "tea", + "lunch": "sushi" + ] + ] +]) +``` + +Lets remove the `country` key: + +```swift +object["two"].dictionaryObject?.removeValue(forKey: "country") +``` + +If you `print(object)`, you'll see that the `country` key no longer exists. + +```json +{ + "one" : { + "color" : "blue" + }, + "two" : { + "city" : "tokyo", + "foods" : { + "breakfast" : "tea", + "lunch" : "sushi" + } + } +} +``` + +This also works for nested dictionaries: + +```swift +object["two"]["foods"].dictionaryObject?.removeValue(forKey: "breakfast") +``` + +```json +{ + "one" : { + "color" : "blue" + }, + "two" : { + "city" : "tokyo", + "foods" : { + "lunch" : "sushi" + } + } +} +``` + ## String representation There are two options available: - use the default Swift one From 75441b91f55b46037da50bb528f6b66b5491465a Mon Sep 17 00:00:00 2001 From: Annie Gupta Date: Thu, 18 Jan 2024 00:39:33 +0530 Subject: [PATCH 452/470] Errors in readme #1144 Fixed errors in README.MD Issue #1144 --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a4cd321f..d87739bb 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ An unreadable mess--for something that should really be simple! With SwiftyJSON all you have to do is: ```swift -let json = JSON(data: dataFromNetworking) +let json = try? JSON(data: dataFromNetworking) if let userName = json[0]["user"]["name"].string { //Now you got your value } @@ -70,7 +70,7 @@ if let userName = json[0]["user"]["name"].string { And don't worry about the Optional Wrapping thing. It's done for you automatically. ```swift -let json = JSON(data: dataFromNetworking) +let json = try? JSON(data: dataFromNetworking) let result = json[999999]["wrong_key"]["wrong_name"] if let userName = result.string { //Calm down, take it easy, the ".string" property still produces the correct Optional String type with safety @@ -143,7 +143,7 @@ import SwiftyJSON ``` ```swift -let json = JSON(data: dataFromNetworking) +let json = try? JSON(data: dataFromNetworking) ``` Or From 4c42874b2f2fb5eaa66afcc0c463f36bf92ea407 Mon Sep 17 00:00:00 2001 From: Nathan Molby Date: Tue, 19 Mar 2024 12:58:04 -0400 Subject: [PATCH 453/470] Add privacy manifest --- Package.swift | 9 +++++++-- Source/SwiftyJSON/PrivacyInfo.xcprivacy | 14 ++++++++++++++ SwiftyJSON.podspec | 1 + 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 Source/SwiftyJSON/PrivacyInfo.xcprivacy diff --git a/Package.swift b/Package.swift index 744e95dd..1fdaf06c 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.3 import PackageDescription let package = Package( @@ -7,7 +7,12 @@ let package = Package( .library(name: "SwiftyJSON", targets: ["SwiftyJSON"]) ], targets: [ - .target(name: "SwiftyJSON", dependencies: []), + .target(name: "SwiftyJSON", + dependencies: [], + resources: [ + .copy("PrivacyInfo.xcprivacy") + ] + ), .testTarget(name: "SwiftJSONTests", dependencies: ["SwiftyJSON"]) ], swiftLanguageVersions: [.v5] diff --git a/Source/SwiftyJSON/PrivacyInfo.xcprivacy b/Source/SwiftyJSON/PrivacyInfo.xcprivacy new file mode 100644 index 00000000..d37d6275 --- /dev/null +++ b/Source/SwiftyJSON/PrivacyInfo.xcprivacy @@ -0,0 +1,14 @@ + + + + + NSPrivacyCollectedDataTypes + + NSPrivacyAccessedAPITypes + + NSPrivacyTrackingDomains + + NSPrivacyTracking + + + diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 944a24b7..83f6f3b0 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -14,4 +14,5 @@ Pod::Spec.new do |s| s.tvos.deployment_target = "9.0" s.source = { :git => "https://github.com/SwiftyJSON/SwiftyJSON.git", :tag => s.version } s.source_files = "Source/SwiftyJSON/*.swift" + s.resource_bundles = {'SwiftyJSON' => ['Source/SwiftyJSON/PrivacyInfo.xcprivacy']} end From af76cf3ef710b6ca5f8c05f3a31307d44a3c5828 Mon Sep 17 00:00:00 2001 From: Zigii Wong Date: Wed, 27 Mar 2024 22:05:55 +0800 Subject: [PATCH 454/470] Version Bump to 5.0.2 --- SwiftyJSON.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.podspec b/SwiftyJSON.podspec index 83f6f3b0..dd091231 100644 --- a/SwiftyJSON.podspec +++ b/SwiftyJSON.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftyJSON" - s.version = "5.0.1" + s.version = "5.0.2" s.summary = "SwiftyJSON makes it easy to deal with JSON data in Swift" s.homepage = "https://github.com/SwiftyJSON/SwiftyJSON" s.license = { :type => "MIT" } From be72f800ceb3ef6d2e618e2be50d37ad7e0e094f Mon Sep 17 00:00:00 2001 From: Blazej SLEBODA <5544365+Adobels@users.noreply.github.com> Date: Thu, 11 Apr 2024 15:18:57 +0200 Subject: [PATCH 455/470] Fix missing PrivacyInfo.xcprivacy in xcodeproj file --- SwiftyJSON.xcodeproj/project.pbxproj | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 3f48deaa..ec223336 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -51,6 +51,10 @@ 9C459F041A9103C1008C9A41 /* DictionaryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8B19E51D6500540692 /* DictionaryTests.swift */; }; 9C459F051A9103C1008C9A41 /* ArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8B66C8D19E52F4200540692 /* ArrayTests.swift */; }; 9C7DFC661A9102BD005AA3F7 /* SwiftyJSON.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */; }; + A1DE64C62BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A1DE64C52BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy */; }; + A1DE64C72BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A1DE64C52BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy */; }; + A1DE64C82BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A1DE64C52BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy */; }; + A1DE64C92BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A1DE64C52BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy */; }; A819C49719E1A7DD00ADCC3D /* LiteralConvertibleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */; }; A819C49919E1B10300ADCC3D /* RawRepresentableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */; }; A819C49F19E2EE5B00ADCC3D /* SubscriptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */; }; @@ -126,6 +130,7 @@ 9C459EF61A9103B1008C9A41 /* Info-macOS.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Info-macOS.plist"; path = "../Info-macOS.plist"; sourceTree = ""; }; 9C7DFC5B1A9102BD005AA3F7 /* SwiftyJSON.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftyJSON.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9C7DFC651A9102BD005AA3F7 /* SwiftyJSON macOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "SwiftyJSON macOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; + A1DE64C52BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = SwiftyJSON/PrivacyInfo.xcprivacy; sourceTree = ""; }; A819C49619E1A7DD00ADCC3D /* LiteralConvertibleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LiteralConvertibleTests.swift; path = ../SwiftJSONTests/LiteralConvertibleTests.swift; sourceTree = ""; }; A819C49819E1B10300ADCC3D /* RawRepresentableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RawRepresentableTests.swift; path = ../SwiftJSONTests/RawRepresentableTests.swift; sourceTree = ""; }; A819C49E19E2EE5B00ADCC3D /* SubscriptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SubscriptTests.swift; path = ../SwiftJSONTests/SubscriptTests.swift; sourceTree = ""; }; @@ -241,6 +246,7 @@ 2E4FEFDE19575BE100351305 /* Supporting Files */ = { isa = PBXGroup; children = ( + A1DE64C52BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy */, 2E4FEFDF19575BE100351305 /* Info-iOS.plist */, 030B6CDC1A6E171D00C2D4F1 /* Info-macOS.plist */, E4D7CCE91B9465A800EE7221 /* Info-watchOS.plist */, @@ -527,6 +533,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A1DE64C62BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -542,6 +549,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A1DE64C92BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -549,6 +557,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A1DE64C72BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -572,6 +581,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + A1DE64C82BC7D95C0097BCE6 /* PrivacyInfo.xcprivacy in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; From ed2bedd6f804b0dd65b03b0cd68d9b2e9909130c Mon Sep 17 00:00:00 2001 From: Brandon Fraune <52302810+fraune@users.noreply.github.com> Date: Tue, 21 May 2024 12:39:35 -0500 Subject: [PATCH 456/470] Update .swiftlint.yml Resolve SwiftLint warning: `'variable_name' has been renamed to 'identifier_name' and will be completely removed in a future release.` --- .swiftlint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 03003d1d..36ee05ac 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -1,7 +1,7 @@ disabled_rules: - force_cast - force_try - - variable_name + - identifier_name - type_name - file_length - line_length From d0058a7b750f769b37e00de4e2546bec85ab55c0 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sat, 10 Aug 2024 19:21:22 +0200 Subject: [PATCH 457/470] Delete .travis.yml -- Travis CI is no longer free to open source https://app.travis-ci.com/github/SwiftyJSON --- .travis.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 17140ab1..00000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: objective-c -osx_image: xcode10.2 -xcode_sdk: iphonesimulator12.0 -script: -- set -o pipefail -- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON iOS" -destination "platform=iOS Simulator,name=iPhone 6" build-for-testing test | xcpretty -- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON macOS" build-for-testing test | xcpretty -- travis_retry xcodebuild -workspace SwiftyJSON.xcworkspace -scheme "SwiftyJSON tvOS" -destination "platform=tvOS Simulator,name=Apple TV" build-for-testing test | xcpretty From 06fcc37fb14d80d6130621bf6f9940f4d601023a Mon Sep 17 00:00:00 2001 From: Joe Ferrucci <2114494+JoeFerrucci@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:51:47 -0500 Subject: [PATCH 458/470] Remove spam URL URL is outdated and leads to spammy/phishy site through redirects. --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index d87739bb..c92bb44e 100644 --- a/README.md +++ b/README.md @@ -556,5 +556,4 @@ provider.request(.showProducts) { result in ## SwiftyJSON Model Generator Tools to generate SwiftyJSON Models -* [JSON Cafe](http://www.jsoncafe.com/) * [JSON Export](https://github.com/Ahmed-Ali/JSONExport) From b00fb02693b50122ef83894afd1846074e572e6a Mon Sep 17 00:00:00 2001 From: Antoine Bollengier <44288655+b5i@users.noreply.github.com> Date: Mon, 26 May 2025 22:30:16 +0200 Subject: [PATCH 459/470] perf: improve unwrap method performance by using native `mapValues` Around 10% better performance on tests, 20% on "real-world" usage. --- Source/SwiftyJSON/SwiftyJSON.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index c8be53c2..ec1822b9 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -265,11 +265,7 @@ private func unwrap(_ object: Any) -> Any { case let array as [Any]: return array.map(unwrap) case let dictionary as [String: Any]: - var d = dictionary - dictionary.forEach { pair in - d[pair.key] = unwrap(pair.value) - } - return d + return dictionary.mapValues(unwrap) default: return object } From 76f8d81bf1c300ddec2704cdc6fc2dd06b1313fd Mon Sep 17 00:00:00 2001 From: Antoine Bollengier <44288655+b5i@users.noreply.github.com> Date: Mon, 26 May 2025 23:16:49 +0200 Subject: [PATCH 460/470] perf: improve dictionnary property getter by using native `mapValues` Around 8% better on tests. --- Source/SwiftyJSON/SwiftyJSON.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index ec1822b9..1da9e58f 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -705,11 +705,7 @@ extension JSON { //Optional [String : JSON] public var dictionary: [String: JSON]? { if type == .dictionary { - var d = [String: JSON](minimumCapacity: rawDictionary.count) - rawDictionary.forEach { pair in - d[pair.key] = JSON(pair.value) - } - return d + return rawDictionary.mapValues(JSON.init(_:)) } else { return nil } From 45c240c76951c27f0aa39d63bfc02ef02943a10b Mon Sep 17 00:00:00 2001 From: Antoine Bollengier <44288655+b5i@users.noreply.github.com> Date: Mon, 26 May 2025 23:35:06 +0200 Subject: [PATCH 461/470] perf: improve performance of `dictionaryLiteral` initializer of JSON --- Source/SwiftyJSON/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index 1da9e58f..6e0904ac 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -524,7 +524,7 @@ extension JSON: Swift.ExpressibleByFloatLiteral { extension JSON: Swift.ExpressibleByDictionaryLiteral { public init(dictionaryLiteral elements: (String, Any)...) { - let dictionary = elements.reduce(into: [String: Any](), { $0[$1.0] = $1.1}) + let dictionary = Dictionary(elements, uniquingKeysWith: { $1 }) self.init(dictionary) } } From c9d0f9d8ccb5f68af4915ff6dafa55a1c17f1001 Mon Sep 17 00:00:00 2001 From: Antoine Bollengier <44288655+b5i@users.noreply.github.com> Date: Mon, 26 May 2025 23:43:34 +0200 Subject: [PATCH 462/470] perf: improve performance of `array` property getter by removing use of closure in map function --- Source/SwiftyJSON/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index 6e0904ac..7b4ff42f 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -676,7 +676,7 @@ extension JSON { //Optional [JSON] public var array: [JSON]? { - return type == .array ? rawArray.map { JSON($0) } : nil + return type == .array ? rawArray.map(JSON.init(_:)) : nil } //Non-optional [JSON] From ae7ca8b3d404a1b24e23cb5c927ddc6cbdfbf7fa Mon Sep 17 00:00:00 2001 From: Antoine Bollengier <44288655+b5i@users.noreply.github.com> Date: Mon, 26 May 2025 23:53:49 +0200 Subject: [PATCH 463/470] perf: remove use of closure in `stringValue` property getter --- Source/SwiftyJSON/SwiftyJSON.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index 7b4ff42f..97daf4fc 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -787,7 +787,7 @@ extension JSON { switch type { case .string: return object as? String ?? "" case .number: return rawNumber.stringValue - case .bool: return (object as? Bool).map { String($0) } ?? "" + case .bool: return (object as? Bool).map(String.init) ?? "" default: return "" } } From ef6d3592a29a1e3cc7c7a6f187523da7682d0799 Mon Sep 17 00:00:00 2001 From: wongzigii Date: Tue, 27 May 2025 15:32:20 +0800 Subject: [PATCH 464/470] Enable GitHub Action CI and fix tests --- .github/workflows/ci.yml | 25 ++++++++++++++++++++ Package.swift | 8 ++++++- Tests/SwiftJSONTests/BaseTests.swift | 4 ++-- Tests/SwiftJSONTests/PerformanceTests.swift | 4 ++-- Tests/SwiftJSONTests/SequenceTypeTests.swift | 8 ++++--- Tests/{Tes => SwiftJSONTests}/Tests.json | 0 6 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/ci.yml rename Tests/{Tes => SwiftJSONTests}/Tests.json (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..2680e910 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + build-and-test: + runs-on: macos-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Swift + uses: swift-actions/setup-swift@v2 + with: + swift-version: '6.0' + + - name: Build + run: swift build --build-tests + + - name: Run tests + run: swift test \ No newline at end of file diff --git a/Package.swift b/Package.swift index 1fdaf06c..ba89fb5f 100644 --- a/Package.swift +++ b/Package.swift @@ -13,7 +13,13 @@ let package = Package( .copy("PrivacyInfo.xcprivacy") ] ), - .testTarget(name: "SwiftJSONTests", dependencies: ["SwiftyJSON"]) + .testTarget( + name: "SwiftJSONTests", + dependencies: ["SwiftyJSON"], + resources: [ + .copy("Tests.json") + ] + ) ], swiftLanguageVersions: [.v5] ) diff --git a/Tests/SwiftJSONTests/BaseTests.swift b/Tests/SwiftJSONTests/BaseTests.swift index 9139c204..634e1c8b 100644 --- a/Tests/SwiftJSONTests/BaseTests.swift +++ b/Tests/SwiftJSONTests/BaseTests.swift @@ -33,8 +33,8 @@ class BaseTests: XCTestCase { // let file = "./Tests/Tes/Tests.json" // self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) - if let file = Bundle(for: BaseTests.self).path(forResource: "Tests", ofType: "json") { - self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) + if let file = Bundle.module.url(forResource: "Tests", withExtension: "json") { + self.testData = try? Data(contentsOf: file) } else { XCTFail("Can't find the test JSON file") } diff --git a/Tests/SwiftJSONTests/PerformanceTests.swift b/Tests/SwiftJSONTests/PerformanceTests.swift index 7535f7d8..70f1f2f2 100644 --- a/Tests/SwiftJSONTests/PerformanceTests.swift +++ b/Tests/SwiftJSONTests/PerformanceTests.swift @@ -30,8 +30,8 @@ class PerformanceTests: XCTestCase { override func setUp() { super.setUp() - if let file = Bundle(for: PerformanceTests.self).path(forResource: "Tests", ofType: "json") { - self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) + if let file = Bundle.module.url(forResource: "Tests", withExtension: "json") { + self.testData = try? Data(contentsOf: file) } else { XCTFail("Can't find the test JSON file") } diff --git a/Tests/SwiftJSONTests/SequenceTypeTests.swift b/Tests/SwiftJSONTests/SequenceTypeTests.swift index d0d8cadd..557c3dbb 100644 --- a/Tests/SwiftJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftJSONTests/SequenceTypeTests.swift @@ -25,10 +25,12 @@ import SwiftyJSON class SequenceTypeTests: XCTestCase { + var testData: Data? + func testJSONFile() { - if let file = Bundle(for: BaseTests.self).path(forResource: "Tests", ofType: "json") { - let testData = try? Data(contentsOf: URL(fileURLWithPath: file)) - guard let json = try? JSON(data: testData!) else { + if let file = Bundle.module.url(forResource: "Tests", withExtension: "json") { + self.testData = try? Data(contentsOf: file) + guard let json = try? JSON(data: self.testData!) else { XCTFail("Unable to parse the data") return } diff --git a/Tests/Tes/Tests.json b/Tests/SwiftJSONTests/Tests.json similarity index 100% rename from Tests/Tes/Tests.json rename to Tests/SwiftJSONTests/Tests.json From 9f751e8dca235d35954edebf943662dbf94d160c Mon Sep 17 00:00:00 2001 From: wongzigii Date: Tue, 27 May 2025 15:39:51 +0800 Subject: [PATCH 465/470] Update README CI Badge --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 58aeb989..e1740680 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,11 @@ # SwiftyJSON +[![CI](https://github.com/SwiftyJSON/SwiftyJSON/actions/workflows/ci.yml/badge.svg)](https://github.com/SwiftyJSON/SwiftyJSON/actions/workflows/ci.yml) + [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![CocoaPods](https://img.shields.io/cocoapods/v/SwiftyJSON.svg) ![Platform](https://img.shields.io/badge/platforms-iOS%208.0%20%7C%20macOS%2010.10%20%7C%20tvOS%209.0%20%7C%20watchOS%203.0-F28D00.svg) [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com) SwiftyJSON makes it easy to deal with JSON data in Swift. -Platform | Build Status ----------| --------------| -*OS | [![Travis CI](https://travis-ci.org/SwiftyJSON/SwiftyJSON.svg?branch=master)](https://travis-ci.org/SwiftyJSON/SwiftyJSON) | -[Linux](https://github.com/IBM-Swift/SwiftyJSON) | [![Build Status](https://travis-ci.org/IBM-Swift/SwiftyJSON.svg?branch=master)](https://travis-ci.org/IBM-Swift/SwiftyJSON) | - - 1. [Why is the typical JSON handling in Swift NOT good](#why-is-the-typical-json-handling-in-swift-not-good) 2. [Requirements](#requirements) 3. [Integration](#integration) From f02c453bb544085109a02f2f2fe8f2cfb0b7f6e8 Mon Sep 17 00:00:00 2001 From: lex00 <121451605+lex00@users.noreply.github.com> Date: Sun, 25 Jan 2026 21:14:51 -0700 Subject: [PATCH 466/470] Add Swift 6 support with Sendable conformance - Update Package.swift to swift-tools-version:6.0 - Remove swiftLanguageVersions lock - Add @unchecked Sendable to JSON struct - Add Sendable to Type, SwiftyJSONError, JSONKey enums - Add comprehensive concurrency tests (18 tests) - Update README requirements and CHANGELOG The JSON type can now safely cross actor boundaries in Swift 6 concurrency. Closes #1163 --- CHANGELOG.md | 9 + Package.swift | 5 +- README.md | 3 +- Source/SwiftyJSON/SwiftyJSON.swift | 8 +- Tests/SwiftJSONTests/ConcurrencyTests.swift | 386 ++++++++++++++++++++ 5 files changed, 403 insertions(+), 8 deletions(-) create mode 100644 Tests/SwiftJSONTests/ConcurrencyTests.swift diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a0935d3..082b0247 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ [Full Changelog](https://github.com/SwiftyJSON/SwiftyJSON/compare/2.2.0...HEAD) +### Added +- Swift 6 support with full Sendable conformance ([#1163](https://github.com/SwiftyJSON/SwiftyJSON/issues/1163)) +- Comprehensive concurrency tests for actor boundary validation + +### Changed +- `JSON` struct conforms to `@unchecked Sendable` +- `Type`, `SwiftyJSONError`, `JSONKey` enums conform to `Sendable` +- Minimum Swift tools version updated to 6.0 + **Closed issues:** - 156 compiler errors Mavericks + Xcode 6.2 [\#220](https://github.com/SwiftyJSON/SwiftyJSON/issues/220) diff --git a/Package.swift b/Package.swift index ba89fb5f..fb026e55 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription let package = Package( @@ -20,6 +20,5 @@ let package = Package( .copy("Tests.json") ] ) - ], - swiftLanguageVersions: [.v5] + ] ) diff --git a/README.md b/README.md index e1740680..a6f3037a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,8 @@ if let userName = result.string { ## Requirements - iOS 8.0+ | macOS 10.10+ | tvOS 9.0+ | watchOS 2.0+ -- Xcode 8 +- Xcode 16+ +- Swift 6.0+ ## Integration diff --git a/Source/SwiftyJSON/SwiftyJSON.swift b/Source/SwiftyJSON/SwiftyJSON.swift index 97daf4fc..d2f39ef2 100644 --- a/Source/SwiftyJSON/SwiftyJSON.swift +++ b/Source/SwiftyJSON/SwiftyJSON.swift @@ -24,7 +24,7 @@ import Foundation // MARK: - Error // swiftlint:disable line_length -public enum SwiftyJSONError: Int, Swift.Error { +public enum SwiftyJSONError: Int, Swift.Error, Sendable { case unsupportedType = 999 case indexOutOfBounds = 900 case elementTooDeep = 902 @@ -67,7 +67,7 @@ JSON's type definitions. See http://www.json.org */ -public enum Type: Int { +public enum Type: Int, Sendable { case number case string case bool @@ -79,7 +79,7 @@ public enum Type: Int { // MARK: - JSON Base -public struct JSON { +public struct JSON: @unchecked Sendable { /** Creates a JSON using the data. @@ -339,7 +339,7 @@ extension JSON: Swift.Collection { /** * To mark both String and Int can be used in subscript. */ -public enum JSONKey { +public enum JSONKey: Sendable { case index(Int) case key(String) } diff --git a/Tests/SwiftJSONTests/ConcurrencyTests.swift b/Tests/SwiftJSONTests/ConcurrencyTests.swift new file mode 100644 index 00000000..bb51afde --- /dev/null +++ b/Tests/SwiftJSONTests/ConcurrencyTests.swift @@ -0,0 +1,386 @@ +// ConcurrencyTests.swift +// +// Copyright (c) 2014 - 2017 Ruoyu Fu, Pinglin Tang +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +import XCTest +import SwiftyJSON + +class ConcurrencyTests: XCTestCase { + + // MARK: - Test 1: Actor Boundary Passing + + actor DataProcessor { + func process(_ json: JSON) -> String { + return json["name"].stringValue + } + + func processDictionary(_ json: JSON) -> Int { + return json["count"].intValue + } + + func processArray(_ json: JSON) -> Int { + return json[0].intValue + } + } + + func testActorBoundaryPassing() async { + let json = JSON(["name": "Test"]) + let processor = DataProcessor() + let result = await processor.process(json) + XCTAssertEqual(result, "Test") + } + + func testActorBoundaryPassingWithDictionary() async { + let json = JSON(["count": 42, "status": "active"]) + let processor = DataProcessor() + let result = await processor.processDictionary(json) + XCTAssertEqual(result, 42) + } + + func testActorBoundaryPassingWithArray() async { + let json = JSON([100, 200, 300]) + let processor = DataProcessor() + let result = await processor.processArray(json) + XCTAssertEqual(result, 100) + } + + // MARK: - Test 2: Sendable Closure and Task + + func testSendableClosureWithTask() async { + let json = JSON(["value": "Hello"]) + let task = Task { @Sendable () -> String in + return json["value"].stringValue + } + let result = await task.value + XCTAssertEqual(result, "Hello") + } + + func testSendableClosureWithComplexData() async { + let json = JSON([ + "user": ["name": "Alice", "age": 30], + "active": true + ]) + let task = Task { @Sendable () -> String in + return json["user"]["name"].stringValue + } + let result = await task.value + XCTAssertEqual(result, "Alice") + } + + // MARK: - Test 3: Async JSON Parsing + + func testAsyncJSONParsing() async throws { + let jsonString = "{\"status\":\"ok\"}" + let data = jsonString.data(using: .utf8)! + + let task = Task { + return try JSON(data: data) + } + + let json = try await task.value + let status = json["status"].stringValue + XCTAssertEqual(status, "ok") + } + + func testAsyncJSONParsingWithComplexData() async throws { + let jsonString = "{\"results\": [{\"id\": 1, \"name\": \"Item1\"}, {\"id\": 2, \"name\": \"Item2\"}]}" + let data = jsonString.data(using: .utf8)! + + let task = Task { + return try JSON(data: data) + } + + let json = try await task.value + XCTAssertEqual(json["results"].arrayValue.count, 2) + XCTAssertEqual(json["results"][0]["name"].stringValue, "Item1") + } + + // MARK: - Test 4: Concurrent Read Access with TaskGroup + + func testConcurrentReadAccess() async { + let json = JSON(["values": [1, 2, 3, 4, 5]]) + + await withTaskGroup(of: Int.self) { group in + for i in 0..<5 { + group.addTask { + return json["values"][i].intValue + } + } + + var sum = 0 + for await value in group { + sum += value + } + XCTAssertEqual(sum, 15) + } + } + + func testConcurrentReadAccessWithDictionary() async { + let json = JSON([ + "items": [ + ["id": 1, "value": 10], + ["id": 2, "value": 20], + ["id": 3, "value": 30] + ] + ]) + + await withTaskGroup(of: Int.self) { group in + for i in 0..<3 { + group.addTask { + return json["items"][i]["value"].intValue + } + } + + var sum = 0 + for await value in group { + sum += value + } + XCTAssertEqual(sum, 60) + } + } + + // MARK: - Test 5: MainActor Isolation + + @MainActor + func mainActorFunction(_ json: JSON) -> String { + return json["title"].stringValue + } + + func testMainActorIsolation() async { + let json = JSON(["title": "Main Thread Task"]) + let result = await mainActorFunction(json) + XCTAssertEqual(result, "Main Thread Task") + } + + // MARK: - Test 6: Task.detached Isolation + + func testTaskDetachedIsolation() async { + let json = JSON(["data": "detached"]) + + let task = Task.detached { @Sendable () -> String in + return json["data"].stringValue + } + + let result = await task.value + XCTAssertEqual(result, "detached") + } + + // MARK: - Test 7: Complex Nested JSON + + func testComplexNestedJSONConcurrency() async { + let json = JSON([ + "users": [ + [ + "id": 1, + "name": "Alice", + "posts": [ + ["id": 101, "title": "Post 1"], + ["id": 102, "title": "Post 2"] + ] + ], + [ + "id": 2, + "name": "Bob", + "posts": [ + ["id": 201, "title": "Post 3"] + ] + ] + ] + ]) + + await withTaskGroup(of: (Int, String).self) { group in + for i in 0..<2 { + group.addTask { + let userId = json["users"][i]["id"].intValue + let userName = json["users"][i]["name"].stringValue + return (userId, userName) + } + } + + var names: [String] = [] + for await (_, name) in group { + names.append(name) + } + + XCTAssert(names.contains("Alice")) + XCTAssert(names.contains("Bob")) + } + } + + func testComplexNestedJSONAccess() async { + let json = JSON([ + [ + ["deep": [1, 2, 3]], + ["deep": [4, 5, 6]] + ], + [ + ["deep": [7, 8, 9]], + ["deep": [10, 11, 12]] + ] + ]) + + let task = Task { @Sendable () -> Int in + return json[0][1]["deep"][2].intValue + } + + let result = await task.value + XCTAssertEqual(result, 6) + } + + // MARK: - Test 8: All JSON Types in Concurrent Context + + func testAllJSONTypesInConcurrency() async { + let json = JSON([ + "string": "value", + "number": 42, + "bool": true, + "null": NSNull(), + "array": [1, 2, 3], + "dictionary": ["nested": "object"] + ]) + + await withTaskGroup(of: String.self) { group in + group.addTask { + return json["string"].stringValue + } + group.addTask { + return String(json["number"].intValue) + } + group.addTask { + return String(json["bool"].boolValue) + } + group.addTask { + return json["null"].type == .null ? "null" : "not_null" + } + group.addTask { + return String(json["array"].arrayValue.count) + } + group.addTask { + return json["dictionary"]["nested"].stringValue + } + + var results: [String] = [] + for await result in group { + results.append(result) + } + + XCTAssertEqual(results.count, 6) + XCTAssert(results.contains("value")) + XCTAssert(results.contains("42")) + XCTAssert(results.contains("true")) + XCTAssert(results.contains("null")) + XCTAssert(results.contains("3")) + XCTAssert(results.contains("object")) + } + } + + // MARK: - Test 9: Error Handling Across Actor Boundaries + + actor ErrorProcessor { + func processJSON(_ json: JSON) throws -> String { + guard json["required"].exists() else { + throw SwiftyJSONError.notExist + } + return json["required"].stringValue + } + + func processWithTypeError(_ json: JSON) throws -> Int { + guard json["count"].type == .number else { + throw SwiftyJSONError.wrongType + } + return json["count"].intValue + } + } + + func testErrorHandlingAcrossActorBoundaries() async { + let json = JSON(["other": "value"]) + let processor = ErrorProcessor() + + do { + _ = try await processor.processJSON(json) + XCTFail("Should have thrown notExist error") + } catch SwiftyJSONError.notExist { + // Expected behavior + } catch { + XCTFail("Unexpected error type: \(error)") + } + } + + func testErrorHandlingWithWrongType() async { + let json = JSON(["count": "not_a_number"]) + let processor = ErrorProcessor() + + do { + _ = try await processor.processWithTypeError(json) + XCTFail("Should have thrown wrongType error") + } catch SwiftyJSONError.wrongType { + // Expected behavior + } catch { + XCTFail("Unexpected error type: \(error)") + } + } + + func testSuccessfulErrorHandling() async { + let json = JSON(["required": "present", "count": 123]) + let processor = ErrorProcessor() + + do { + let result = try await processor.processJSON(json) + XCTAssertEqual(result, "present") + + let count = try await processor.processWithTypeError(json) + XCTAssertEqual(count, 123) + } catch { + XCTFail("Should not have thrown error: \(error)") + } + } + + // MARK: - Test 10: Mixed Async Operations + + func testMixedAsyncOperations() async throws { + let jsonString = "{\"users\": [{\"id\": 1, \"name\": \"User1\"}, {\"id\": 2, \"name\": \"User2\"}]}" + let data = jsonString.data(using: .utf8)! + + let parseTask = Task { + return try JSON(data: data) + } + + let json = try await parseTask.value + + let names = await withTaskGroup(of: String.self) { group in + for i in 0..<2 { + group.addTask { + return json["users"][i]["name"].stringValue + } + } + + var result: [String] = [] + for await name in group { + result.append(name) + } + return result + } + + XCTAssertEqual(names.count, 2) + XCTAssert(names.contains("User1")) + XCTAssert(names.contains("User2")) + } +} From 636b70007f3ea3fe57df40151faaf1d62042fdaf Mon Sep 17 00:00:00 2001 From: lex00 <121451605+lex00@users.noreply.github.com> Date: Mon, 26 Jan 2026 17:27:31 -0700 Subject: [PATCH 467/470] Consolidate concurrency tests to 3 focused tests Each test now directly corresponds to a type made Sendable: - testJSONSendable: JSON crosses actor boundary - testTypeSendable: Type enum crosses actor boundary - testSwiftyJSONErrorSendable: SwiftyJSONError crosses actor boundary Removed redundant tests that proved the same thing in different ways (TaskGroup, Task.detached, MainActor variations). Added missing coverage for Type enum Sendable conformance. --- Tests/SwiftJSONTests/ConcurrencyTests.swift | 375 ++------------------ 1 file changed, 39 insertions(+), 336 deletions(-) diff --git a/Tests/SwiftJSONTests/ConcurrencyTests.swift b/Tests/SwiftJSONTests/ConcurrencyTests.swift index bb51afde..a6eaa099 100644 --- a/Tests/SwiftJSONTests/ConcurrencyTests.swift +++ b/Tests/SwiftJSONTests/ConcurrencyTests.swift @@ -23,364 +23,67 @@ import XCTest import SwiftyJSON +/// Tests verifying Sendable conformance for Swift 6 concurrency. +/// Each test targets a specific type made Sendable in this PR. class ConcurrencyTests: XCTestCase { - // MARK: - Test 1: Actor Boundary Passing - - actor DataProcessor { - func process(_ json: JSON) -> String { - return json["name"].stringValue - } - - func processDictionary(_ json: JSON) -> Int { - return json["count"].intValue - } - - func processArray(_ json: JSON) -> Int { - return json[0].intValue - } - } - - func testActorBoundaryPassing() async { - let json = JSON(["name": "Test"]) - let processor = DataProcessor() - let result = await processor.process(json) - XCTAssertEqual(result, "Test") - } - - func testActorBoundaryPassingWithDictionary() async { - let json = JSON(["count": 42, "status": "active"]) - let processor = DataProcessor() - let result = await processor.processDictionary(json) - XCTAssertEqual(result, 42) - } - - func testActorBoundaryPassingWithArray() async { - let json = JSON([100, 200, 300]) - let processor = DataProcessor() - let result = await processor.processArray(json) - XCTAssertEqual(result, 100) - } - - // MARK: - Test 2: Sendable Closure and Task - - func testSendableClosureWithTask() async { - let json = JSON(["value": "Hello"]) - let task = Task { @Sendable () -> String in - return json["value"].stringValue - } - let result = await task.value - XCTAssertEqual(result, "Hello") - } - - func testSendableClosureWithComplexData() async { - let json = JSON([ - "user": ["name": "Alice", "age": 30], - "active": true - ]) - let task = Task { @Sendable () -> String in - return json["user"]["name"].stringValue - } - let result = await task.value - XCTAssertEqual(result, "Alice") - } - - // MARK: - Test 3: Async JSON Parsing - - func testAsyncJSONParsing() async throws { - let jsonString = "{\"status\":\"ok\"}" - let data = jsonString.data(using: .utf8)! - - let task = Task { - return try JSON(data: data) + actor Processor { + func extract(_ json: JSON) -> String { + json["name"].stringValue } - let json = try await task.value - let status = json["status"].stringValue - XCTAssertEqual(status, "ok") - } - - func testAsyncJSONParsingWithComplexData() async throws { - let jsonString = "{\"results\": [{\"id\": 1, \"name\": \"Item1\"}, {\"id\": 2, \"name\": \"Item2\"}]}" - let data = jsonString.data(using: .utf8)! - - let task = Task { - return try JSON(data: data) + func extractType(_ json: JSON) -> Type { + json["value"].type } - let json = try await task.value - XCTAssertEqual(json["results"].arrayValue.count, 2) - XCTAssertEqual(json["results"][0]["name"].stringValue, "Item1") - } - - // MARK: - Test 4: Concurrent Read Access with TaskGroup - - func testConcurrentReadAccess() async { - let json = JSON(["values": [1, 2, 3, 4, 5]]) - - await withTaskGroup(of: Int.self) { group in - for i in 0..<5 { - group.addTask { - return json["values"][i].intValue - } - } - - var sum = 0 - for await value in group { - sum += value - } - XCTAssertEqual(sum, 15) - } - } - - func testConcurrentReadAccessWithDictionary() async { - let json = JSON([ - "items": [ - ["id": 1, "value": 10], - ["id": 2, "value": 20], - ["id": 3, "value": 30] - ] - ]) - - await withTaskGroup(of: Int.self) { group in - for i in 0..<3 { - group.addTask { - return json["items"][i]["value"].intValue - } - } - - var sum = 0 - for await value in group { - sum += value - } - XCTAssertEqual(sum, 60) - } - } - - // MARK: - Test 5: MainActor Isolation - - @MainActor - func mainActorFunction(_ json: JSON) -> String { - return json["title"].stringValue - } - - func testMainActorIsolation() async { - let json = JSON(["title": "Main Thread Task"]) - let result = await mainActorFunction(json) - XCTAssertEqual(result, "Main Thread Task") - } - - // MARK: - Test 6: Task.detached Isolation - - func testTaskDetachedIsolation() async { - let json = JSON(["data": "detached"]) - - let task = Task.detached { @Sendable () -> String in - return json["data"].stringValue - } - - let result = await task.value - XCTAssertEqual(result, "detached") - } - - // MARK: - Test 7: Complex Nested JSON - - func testComplexNestedJSONConcurrency() async { - let json = JSON([ - "users": [ - [ - "id": 1, - "name": "Alice", - "posts": [ - ["id": 101, "title": "Post 1"], - ["id": 102, "title": "Post 2"] - ] - ], - [ - "id": 2, - "name": "Bob", - "posts": [ - ["id": 201, "title": "Post 3"] - ] - ] - ] - ]) - - await withTaskGroup(of: (Int, String).self) { group in - for i in 0..<2 { - group.addTask { - let userId = json["users"][i]["id"].intValue - let userName = json["users"][i]["name"].stringValue - return (userId, userName) - } - } - - var names: [String] = [] - for await (_, name) in group { - names.append(name) - } - - XCTAssert(names.contains("Alice")) - XCTAssert(names.contains("Bob")) - } - } - - func testComplexNestedJSONAccess() async { - let json = JSON([ - [ - ["deep": [1, 2, 3]], - ["deep": [4, 5, 6]] - ], - [ - ["deep": [7, 8, 9]], - ["deep": [10, 11, 12]] - ] - ]) - - let task = Task { @Sendable () -> Int in - return json[0][1]["deep"][2].intValue - } - - let result = await task.value - XCTAssertEqual(result, 6) - } - - // MARK: - Test 8: All JSON Types in Concurrent Context - - func testAllJSONTypesInConcurrency() async { - let json = JSON([ - "string": "value", - "number": 42, - "bool": true, - "null": NSNull(), - "array": [1, 2, 3], - "dictionary": ["nested": "object"] - ]) - - await withTaskGroup(of: String.self) { group in - group.addTask { - return json["string"].stringValue - } - group.addTask { - return String(json["number"].intValue) - } - group.addTask { - return String(json["bool"].boolValue) - } - group.addTask { - return json["null"].type == .null ? "null" : "not_null" - } - group.addTask { - return String(json["array"].arrayValue.count) - } - group.addTask { - return json["dictionary"]["nested"].stringValue - } - - var results: [String] = [] - for await result in group { - results.append(result) - } - - XCTAssertEqual(results.count, 6) - XCTAssert(results.contains("value")) - XCTAssert(results.contains("42")) - XCTAssert(results.contains("true")) - XCTAssert(results.contains("null")) - XCTAssert(results.contains("3")) - XCTAssert(results.contains("object")) - } - } - - // MARK: - Test 9: Error Handling Across Actor Boundaries - - actor ErrorProcessor { - func processJSON(_ json: JSON) throws -> String { + func requireField(_ json: JSON) throws -> String { guard json["required"].exists() else { throw SwiftyJSONError.notExist } return json["required"].stringValue } - - func processWithTypeError(_ json: JSON) throws -> Int { - guard json["count"].type == .number else { - throw SwiftyJSONError.wrongType - } - return json["count"].intValue - } } - func testErrorHandlingAcrossActorBoundaries() async { - let json = JSON(["other": "value"]) - let processor = ErrorProcessor() - - do { - _ = try await processor.processJSON(json) - XCTFail("Should have thrown notExist error") - } catch SwiftyJSONError.notExist { - // Expected behavior - } catch { - XCTFail("Unexpected error type: \(error)") - } - } + /// Verifies JSON conforms to Sendable (can cross actor boundary) + func testJSONSendable() async { + let json = JSON(["name": "test", "count": 42]) + let processor = Processor() - func testErrorHandlingWithWrongType() async { - let json = JSON(["count": "not_a_number"]) - let processor = ErrorProcessor() + let result = await processor.extract(json) - do { - _ = try await processor.processWithTypeError(json) - XCTFail("Should have thrown wrongType error") - } catch SwiftyJSONError.wrongType { - // Expected behavior - } catch { - XCTFail("Unexpected error type: \(error)") - } + XCTAssertEqual(result, "test") } - func testSuccessfulErrorHandling() async { - let json = JSON(["required": "present", "count": 123]) - let processor = ErrorProcessor() + /// Verifies Type enum conforms to Sendable (can be returned across actor boundary) + func testTypeSendable() async { + let processor = Processor() - do { - let result = try await processor.processJSON(json) - XCTAssertEqual(result, "present") + let stringType = await processor.extractType(JSON(["value": "hello"])) + let numberType = await processor.extractType(JSON(["value": 123])) + let boolType = await processor.extractType(JSON(["value": true])) + let nullType = await processor.extractType(JSON(["value": NSNull()])) + let arrayType = await processor.extractType(JSON(["value": [1, 2, 3]])) + let dictType = await processor.extractType(JSON(["value": ["nested": "object"]])) - let count = try await processor.processWithTypeError(json) - XCTAssertEqual(count, 123) - } catch { - XCTFail("Should not have thrown error: \(error)") - } + XCTAssertEqual(stringType, .string) + XCTAssertEqual(numberType, .number) + XCTAssertEqual(boolType, .bool) + XCTAssertEqual(nullType, .null) + XCTAssertEqual(arrayType, .array) + XCTAssertEqual(dictType, .dictionary) } - // MARK: - Test 10: Mixed Async Operations + /// Verifies SwiftyJSONError conforms to Sendable (can be thrown across actor boundary) + func testSwiftyJSONErrorSendable() async { + let processor = Processor() - func testMixedAsyncOperations() async throws { - let jsonString = "{\"users\": [{\"id\": 1, \"name\": \"User1\"}, {\"id\": 2, \"name\": \"User2\"}]}" - let data = jsonString.data(using: .utf8)! - - let parseTask = Task { - return try JSON(data: data) - } - - let json = try await parseTask.value - - let names = await withTaskGroup(of: String.self) { group in - for i in 0..<2 { - group.addTask { - return json["users"][i]["name"].stringValue - } - } - - var result: [String] = [] - for await name in group { - result.append(name) - } - return result + do { + _ = try await processor.requireField(JSON(["other": "value"])) + XCTFail("Should have thrown") + } catch SwiftyJSONError.notExist { + // Error successfully crossed actor boundary + } catch { + XCTFail("Unexpected error: \(error)") } - - XCTAssertEqual(names.count, 2) - XCTAssert(names.contains("User1")) - XCTAssert(names.contains("User2")) } } From d24f061e37c6e0f40b99a53846e9d4682fe01d57 Mon Sep 17 00:00:00 2001 From: wongzigii Date: Wed, 4 Feb 2026 17:10:27 +0800 Subject: [PATCH 468/470] update ci --- .github/workflows/ci.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2680e910..a3816d45 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,14 +12,12 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - - name: Set up Swift - uses: swift-actions/setup-swift@v2 - with: - swift-version: '6.0' + + - name: Select Xcode + run: sudo xcode-select -s /Applications/Xcode_16.4.app - name: Build - run: swift build --build-tests + run: xcrun swift build --build-tests - name: Run tests - run: swift test \ No newline at end of file + run: xcrun swift test \ No newline at end of file From 28094b0b74ea2c26003dee4d2b916a3943027ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jean=2E333=28=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=8B=E1=85=B2?= =?UTF-8?q?=E1=84=8C=E1=85=B5=E1=86=AB=29/kakaomobility?= <41438361+Yoojin99@users.noreply.github.com> Date: Thu, 26 Feb 2026 15:14:18 +0900 Subject: [PATCH 469/470] Fix Tests group path in Xcode project --- SwiftyJSON.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index ec223336..3c325ac2 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -278,7 +278,7 @@ 2E4FEFEB19575BE100351305 /* Supporting Files */, ); name = Tests; - path = Tests/Tes; + path = Tests/SwiftJSONTests; sourceTree = ""; }; 2E4FEFEB19575BE100351305 /* Supporting Files */ = { From d9712989ba2275f2d04e62a9fa74e704bc54fdda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?jean=2E333=28=E1=84=8C=E1=85=A5=E1=86=BC=E1=84=8B=E1=85=B2?= =?UTF-8?q?=E1=84=8C=E1=85=B5=E1=86=AB=29/kakaomobility?= <41438361+Yoojin99@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:06:37 +0900 Subject: [PATCH 470/470] Fix test resource loading for Xcode and SwiftPM --- Tests/SwiftJSONTests/BaseTests.swift | 9 ++++++--- Tests/SwiftJSONTests/PerformanceTests.swift | 7 ++++++- Tests/SwiftJSONTests/SequenceTypeTests.swift | 7 ++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Tests/SwiftJSONTests/BaseTests.swift b/Tests/SwiftJSONTests/BaseTests.swift index 634e1c8b..8bbebcde 100644 --- a/Tests/SwiftJSONTests/BaseTests.swift +++ b/Tests/SwiftJSONTests/BaseTests.swift @@ -31,9 +31,12 @@ class BaseTests: XCTestCase { super.setUp() -// let file = "./Tests/Tes/Tests.json" -// self.testData = try? Data(contentsOf: URL(fileURLWithPath: file)) - if let file = Bundle.module.url(forResource: "Tests", withExtension: "json") { + #if SWIFT_PACKAGE + let testBundle = Bundle.module + #else + let testBundle = Bundle(for: BaseTests.self) + #endif + if let file = testBundle.url(forResource: "Tests", withExtension: "json") { self.testData = try? Data(contentsOf: file) } else { XCTFail("Can't find the test JSON file") diff --git a/Tests/SwiftJSONTests/PerformanceTests.swift b/Tests/SwiftJSONTests/PerformanceTests.swift index 70f1f2f2..c0e6cc0b 100644 --- a/Tests/SwiftJSONTests/PerformanceTests.swift +++ b/Tests/SwiftJSONTests/PerformanceTests.swift @@ -30,7 +30,12 @@ class PerformanceTests: XCTestCase { override func setUp() { super.setUp() - if let file = Bundle.module.url(forResource: "Tests", withExtension: "json") { + #if SWIFT_PACKAGE + let testBundle = Bundle.module + #else + let testBundle = Bundle(for: PerformanceTests.self) + #endif + if let file = testBundle.url(forResource: "Tests", withExtension: "json") { self.testData = try? Data(contentsOf: file) } else { XCTFail("Can't find the test JSON file") diff --git a/Tests/SwiftJSONTests/SequenceTypeTests.swift b/Tests/SwiftJSONTests/SequenceTypeTests.swift index 557c3dbb..a039453f 100644 --- a/Tests/SwiftJSONTests/SequenceTypeTests.swift +++ b/Tests/SwiftJSONTests/SequenceTypeTests.swift @@ -28,7 +28,12 @@ class SequenceTypeTests: XCTestCase { var testData: Data? func testJSONFile() { - if let file = Bundle.module.url(forResource: "Tests", withExtension: "json") { + #if SWIFT_PACKAGE + let testBundle = Bundle.module + #else + let testBundle = Bundle(for: SequenceTypeTests.self) + #endif + if let file = testBundle.url(forResource: "Tests", withExtension: "json") { self.testData = try? Data(contentsOf: file) guard let json = try? JSON(data: self.testData!) else { XCTFail("Unable to parse the data")