diff --git a/SwiftyJSON.xcodeproj/project.pbxproj b/SwiftyJSON.xcodeproj/project.pbxproj index 3bb83fe0..de3b8479 100644 --- a/SwiftyJSON.xcodeproj/project.pbxproj +++ b/SwiftyJSON.xcodeproj/project.pbxproj @@ -9,16 +9,10 @@ /* 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 */; }; A885D1D419CF223F002FD4C3 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; - A885D1D519CF223F002FD4C3 /* SwiftyJSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = A8491E1D19CD6DAE00CCFAE6 /* SwiftyJSON.swift */; }; - A885D1D619CF2240002FD4C3 /* 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 */ @@ -29,13 +23,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 */ @@ -44,8 +31,6 @@ 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; }; 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 = ""; }; @@ -67,21 +52,6 @@ ); 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 */ @@ -99,8 +69,6 @@ children = ( 2E4FEFDB19575BE100351305 /* SwiftyJSON.framework */, 2E4FEFE619575BE100351305 /* SwiftyJSONTests.xctest */, - 2E4FF00219575CE600351305 /* SwiftyJSON.framework */, - 2E4FF00C19575CE600351305 /* SwiftyJSON-OSXTests.xctest */, ); name = Products; sourceTree = ""; @@ -152,14 +120,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 2E4FEFFF19575CE600351305 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - 2E4FF01C19575D1100351305 /* SwiftyJSON.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ @@ -199,42 +159,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 */ @@ -250,13 +174,6 @@ CreatedOnToolsVersion = 6.0; TestTargetID = 2E4FEFDA19575BE100351305; }; - 2E4FF00119575CE600351305 = { - CreatedOnToolsVersion = 6.0; - }; - 2E4FF00B19575CE600351305 = { - CreatedOnToolsVersion = 6.0; - TestTargetID = 2E4FF00119575CE600351305; - }; }; }; buildConfigurationList = 2E4FEFD519575BE100351305 /* Build configuration list for PBXProject "SwiftyJSON" */; @@ -273,8 +190,6 @@ targets = ( 2E4FEFDA19575BE100351305 /* SwiftyJSON */, 2E4FEFE519575BE100351305 /* SwiftyJSONTests */, - 2E4FF00119575CE600351305 /* SwiftyJSON-OSX */, - 2E4FF00B19575CE600351305 /* SwiftyJSON-OSXTests */, ); }; /* End PBXProject section */ @@ -295,21 +210,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 */ @@ -330,23 +230,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 */, - A885D1D619CF2240002FD4C3 /* SwiftyJSON.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ @@ -355,11 +238,6 @@ target = 2E4FEFDA19575BE100351305 /* SwiftyJSON */; targetProxy = 2E4FEFE819575BE100351305 /* PBXContainerItemProxy */; }; - 2E4FF00F19575CE600351305 /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = 2E4FF00119575CE600351305 /* SwiftyJSON-OSX */; - targetProxy = 2E4FF00E19575CE600351305 /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -451,13 +329,14 @@ 2E4FEFF219575BE100351305 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SwiftyJSON/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -467,13 +346,14 @@ 2E4FEFF319575BE100351305 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = "$(ARCHS_STANDARD)"; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = SwiftyJSON/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; @@ -512,92 +392,6 @@ }; 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 */ @@ -628,24 +422,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/SwiftyJSON/SwiftyJSON.swift b/SwiftyJSON/SwiftyJSON.swift old mode 100644 new mode 100755 index de740e4e..ccd1fa08 --- a/SwiftyJSON/SwiftyJSON.swift +++ b/SwiftyJSON/SwiftyJSON.swift @@ -32,15 +32,15 @@ public enum JSON { case Mapping(Dictionary) case Null(NSError?) - init(data:NSData, options opt: NSJSONReadingOptions = nil, error: NSErrorPointer = nil) { - if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: opt, error: error){ + public init(data:NSData, error: NSErrorPointer = nil) { + if let object: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: error){ self = JSON(object: object) } else { self = .Null(nil) } } - init(object: AnyObject) { + public init(object: AnyObject) { switch object { case let number as NSNumber: self = .ScalarNumber(number) @@ -66,10 +66,18 @@ public enum JSON { self = .Null(nil) } } + + public init(_ dictionary: [String: AnyObject?]) { + var aJSONDictionary = [String: JSON]() + for (key: String, value: AnyObject?) in dictionary { + aJSONDictionary[key] = value != nil ? JSON(object: value!) : JSON.Null(nil) + } + self = .Mapping(aJSONDictionary) + } } // MARK: - Subscript -extension JSON { +public extension JSON { subscript(index: Int) -> JSON { get { @@ -131,7 +139,7 @@ extension JSON: Printable, DebugPrintable { } // MARK: - Sequence: Array -extension JSON { +public extension JSON { var arrayValue: Array? { get { @@ -146,7 +154,7 @@ extension JSON { } // MARK: - Mapping: Dictionary -extension JSON { +public extension JSON { var dictionaryValue: Dictionary? { get { @@ -182,7 +190,7 @@ extension JSON: BooleanType { } //MARK: - Scalar: String, NSNumber, NSURL, Int, ... -extension JSON { +public extension JSON { var stringValue: String? { get { @@ -349,9 +357,32 @@ extension JSON { } } +//MARK: - Any value +public extension JSON { + + var anyValue: Any? { + switch self { + case .ScalarNumber(let number): return number + case .ScalarString(let string): return string + case .Sequence(let array): return array + case .Mapping(let dictionary): return dictionary + default: return nil + } + } + + var anyObject: AnyObject? { + switch self { + case .ScalarNumber(let number): return number + case .ScalarString(let string): return string + default: return nil + } + } + +} + //MARK: - Comparable extension JSON: Comparable { - + private var type: Int { get { switch self {