diff --git a/JSONHelper.xcodeproj/project.pbxproj b/JSONHelper.xcodeproj/project.pbxproj index ed15a3c..3f6aab3 100644 --- a/JSONHelper.xcodeproj/project.pbxproj +++ b/JSONHelper.xcodeproj/project.pbxproj @@ -9,7 +9,26 @@ /* Begin PBXBuildFile section */ 5F024AE11B4127C900EF50C4 /* IntTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F024AE01B4127C900EF50C4 /* IntTests.swift */; }; 5F024AE31B412BA900EF50C4 /* BoolTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F024AE21B412BA900EF50C4 /* BoolTests.swift */; }; + 5F133DA21C3840BB00EF50C4 /* JSONAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F133DA11C3840BB00EF50C4 /* JSONAPI.swift */; }; + 5F133DA31C3840C800EF50C4 /* JSONAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F133DA11C3840BB00EF50C4 /* JSONAPI.swift */; }; + 5F133DA41C3840CA00EF50C4 /* JSONAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F133DA11C3840BB00EF50C4 /* JSONAPI.swift */; }; 5F1C55FC1C1AB25100EF50C4 /* JSONDataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F1C55FB1C1AB25100EF50C4 /* JSONDataTypes.swift */; }; + 5F31FF561C5339B900EF50C4 /* NSDateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF551C5339B900EF50C4 /* NSDateTests.swift */; }; + 5F31FF581C5339CE00EF50C4 /* NSURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF571C5339CE00EF50C4 /* NSURLTests.swift */; }; + 5F31FF5C1C533AD400EF50C4 /* Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5B1C533AD400EF50C4 /* Conversion.swift */; }; + 5F31FF5E1C533AE000EF50C4 /* Mapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5D1C533AE000EF50C4 /* Mapping.swift */; }; + 5F31FF601C533E9900EF50C4 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5F1C533E9900EF50C4 /* Color.swift */; }; + 5F31FF611C533E9900EF50C4 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5F1C533E9900EF50C4 /* Color.swift */; }; + 5F31FF621C533E9900EF50C4 /* Color.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5F1C533E9900EF50C4 /* Color.swift */; }; + 5F31FF631C533E9D00EF50C4 /* Mapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5D1C533AE000EF50C4 /* Mapping.swift */; }; + 5F31FF641C533E9D00EF50C4 /* Mapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5D1C533AE000EF50C4 /* Mapping.swift */; }; + 5F31FF651C533EA000EF50C4 /* Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5B1C533AD400EF50C4 /* Conversion.swift */; }; + 5F31FF661C533EA100EF50C4 /* Conversion.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF5B1C533AD400EF50C4 /* Conversion.swift */; }; + 5F31FF671C533EA400EF50C4 /* JSONDataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F1C55FB1C1AB25100EF50C4 /* JSONDataTypes.swift */; }; + 5F31FF681C533EA500EF50C4 /* JSONDataTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F1C55FB1C1AB25100EF50C4 /* JSONDataTypes.swift */; }; + 5F31FF691C533EAA00EF50C4 /* String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC1A4861B1CFFB500EF50C4 /* String.swift */; }; + 5F31FF6A1C533EAD00EF50C4 /* Int.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC1A4881B1D024500EF50C4 /* Int.swift */; }; + 5F31FF6C1C533F1600EF50C4 /* ColorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F31FF6B1C533F1600EF50C4 /* ColorTests.swift */; }; 5F928D991C0D469F00EF50C4 /* JSONHelper-tvOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 5F928D981C0D469F00EF50C4 /* JSONHelper-tvOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5FAD076A1A70F2FC00C4D09E /* JSONHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 5FAD07691A70F2FC00C4D09E /* JSONHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; 5FAD07701A70F2FC00C4D09E /* JSONHelper.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5FAD07641A70F2FC00C4D09E /* JSONHelper.framework */; }; @@ -31,8 +50,6 @@ 5FC1A4921B1D082D00EF50C4 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC1A48F1B1D082500EF50C4 /* NSDate.swift */; }; 5FC1A4941B1D1D8B00EF50C4 /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC1A4931B1D1D8B00EF50C4 /* NSURL.swift */; }; 5FC1A4951B1D1D8B00EF50C4 /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC1A4931B1D1D8B00EF50C4 /* NSURL.swift */; }; - 5FE42BDA1B12DB3E00EF50C4 /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FE42BD91B12DB3E00EF50C4 /* JSONHelper.swift */; }; - 5FE42BDB1B12DB3E00EF50C4 /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FE42BD91B12DB3E00EF50C4 /* JSONHelper.swift */; }; D76C52051ACD46B100B49735 /* JSONHelper.h in Headers */ = {isa = PBXBuildFile; fileRef = 5FAD07691A70F2FC00C4D09E /* JSONHelper.h */; settings = {ATTRIBUTES = (Public, ); }; }; /* End PBXBuildFile section */ @@ -64,8 +81,15 @@ 5F024AE01B4127C900EF50C4 /* IntTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IntTests.swift; sourceTree = ""; }; 5F024AE21B412BA900EF50C4 /* BoolTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BoolTests.swift; sourceTree = ""; }; 5F0E6F961ACDE06400D92679 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 5F133DA11C3840BB00EF50C4 /* JSONAPI.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = JSONAPI.swift; path = Support/JSONAPI.swift; sourceTree = ""; }; 5F1C55FB1C1AB25100EF50C4 /* JSONDataTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONDataTypes.swift; sourceTree = ""; }; - 5F928D961C0D469F00EF50C4 /* JSONHelper_tvOS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JSONHelper_tvOS.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 5F31FF551C5339B900EF50C4 /* NSDateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDateTests.swift; sourceTree = ""; }; + 5F31FF571C5339CE00EF50C4 /* NSURLTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSURLTests.swift; sourceTree = ""; }; + 5F31FF5B1C533AD400EF50C4 /* Conversion.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Conversion.swift; sourceTree = ""; }; + 5F31FF5D1C533AE000EF50C4 /* Mapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Mapping.swift; sourceTree = ""; }; + 5F31FF5F1C533E9900EF50C4 /* Color.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Color.swift; path = Extensions/Color.swift; sourceTree = ""; }; + 5F31FF6B1C533F1600EF50C4 /* ColorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ColorTests.swift; sourceTree = ""; }; + 5F928D961C0D469F00EF50C4 /* JSONHelper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JSONHelper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 5F928D981C0D469F00EF50C4 /* JSONHelper-tvOS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JSONHelper-tvOS.h"; sourceTree = ""; }; 5F928D9A1C0D469F00EF50C4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5FAD07641A70F2FC00C4D09E /* JSONHelper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JSONHelper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -89,7 +113,6 @@ 5FC1A48D1B1D057B00EF50C4 /* Bool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Bool.swift; path = Extensions/Bool.swift; sourceTree = ""; }; 5FC1A48F1B1D082500EF50C4 /* NSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSDate.swift; path = Extensions/NSDate.swift; sourceTree = ""; }; 5FC1A4931B1D1D8B00EF50C4 /* NSURL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = NSURL.swift; path = Extensions/NSURL.swift; sourceTree = ""; }; - 5FE42BD91B12DB3E00EF50C4 /* JSONHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = ""; }; D76C520A1ACD46B100B49735 /* JSONHelper.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = JSONHelper.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -156,6 +179,14 @@ path = iOS; sourceTree = ""; }; + 5F133DA01C3840A200EF50C4 /* Support */ = { + isa = PBXGroup; + children = ( + 5F133DA11C3840BB00EF50C4 /* JSONAPI.swift */, + ); + name = Support; + sourceTree = ""; + }; 5F928D9F1C0D478800EF50C4 /* tvOS */ = { isa = PBXGroup; children = ( @@ -169,9 +200,9 @@ isa = PBXGroup; children = ( 5FAD07661A70F2FC00C4D09E /* JSONHelper */, + 5FAD07731A70F2FC00C4D09E /* JSONHelperTests */, 5FAD07851A70F31300C4D09E /* JSONHelperExample */, 5FAD079B1A70F31300C4D09E /* JSONHelperExampleTests */, - 5FAD07731A70F2FC00C4D09E /* JSONHelperTests */, 5FAD07651A70F2FC00C4D09E /* Products */, ); sourceTree = ""; @@ -184,7 +215,7 @@ 5FAD07841A70F31300C4D09E /* JSONHelperExample.app */, 5FAD07981A70F31300C4D09E /* JSONHelperExampleTests.xctest */, D76C520A1ACD46B100B49735 /* JSONHelper.framework */, - 5F928D961C0D469F00EF50C4 /* JSONHelper_tvOS.framework */, + 5F928D961C0D469F00EF50C4 /* JSONHelper.framework */, ); name = Products; sourceTree = ""; @@ -194,8 +225,10 @@ children = ( 5FAD07691A70F2FC00C4D09E /* JSONHelper.h */, 5F1C55FB1C1AB25100EF50C4 /* JSONDataTypes.swift */, - 5FE42BD91B12DB3E00EF50C4 /* JSONHelper.swift */, + 5F31FF5B1C533AD400EF50C4 /* Conversion.swift */, + 5F31FF5D1C533AE000EF50C4 /* Mapping.swift */, 5FC1A4851B1CFBE500EF50C4 /* Extensions */, + 5F133DA01C3840A200EF50C4 /* Support */, 5FAD07671A70F2FC00C4D09E /* Supporting Files */, ); path = JSONHelper; @@ -215,9 +248,12 @@ isa = PBXGroup; children = ( 5FAD07761A70F2FC00C4D09E /* JSONHelperTests.swift */, - 5FB9D4DF1B38007C00EF50C4 /* StringTests.swift */, - 5F024AE01B4127C900EF50C4 /* IntTests.swift */, 5F024AE21B412BA900EF50C4 /* BoolTests.swift */, + 5F31FF6B1C533F1600EF50C4 /* ColorTests.swift */, + 5F024AE01B4127C900EF50C4 /* IntTests.swift */, + 5F31FF551C5339B900EF50C4 /* NSDateTests.swift */, + 5F31FF571C5339CE00EF50C4 /* NSURLTests.swift */, + 5FB9D4DF1B38007C00EF50C4 /* StringTests.swift */, ); path = JSONHelperTests; sourceTree = ""; @@ -263,11 +299,12 @@ 5FC1A4851B1CFBE500EF50C4 /* Extensions */ = { isa = PBXGroup; children = ( - 5FC1A4861B1CFFB500EF50C4 /* String.swift */, - 5FC1A4881B1D024500EF50C4 /* Int.swift */, 5FC1A48D1B1D057B00EF50C4 /* Bool.swift */, + 5F31FF5F1C533E9900EF50C4 /* Color.swift */, + 5FC1A4881B1D024500EF50C4 /* Int.swift */, 5FC1A48F1B1D082500EF50C4 /* NSDate.swift */, 5FC1A4931B1D1D8B00EF50C4 /* NSURL.swift */, + 5FC1A4861B1CFFB500EF50C4 /* String.swift */, ); name = Extensions; sourceTree = ""; @@ -302,9 +339,9 @@ /* End PBXHeadersBuildPhase section */ /* Begin PBXNativeTarget section */ - 5F928D951C0D469F00EF50C4 /* JSONHelper_tvOS */ = { + 5F928D951C0D469F00EF50C4 /* JSONHelper-tvOS */ = { isa = PBXNativeTarget; - buildConfigurationList = 5F928D9B1C0D469F00EF50C4 /* Build configuration list for PBXNativeTarget "JSONHelper_tvOS" */; + buildConfigurationList = 5F928D9B1C0D469F00EF50C4 /* Build configuration list for PBXNativeTarget "JSONHelper-tvOS" */; buildPhases = ( 5F928D911C0D469F00EF50C4 /* Sources */, 5F928D921C0D469F00EF50C4 /* Frameworks */, @@ -315,14 +352,14 @@ ); dependencies = ( ); - name = JSONHelper_tvOS; + name = "JSONHelper-tvOS"; productName = "JSONHelper-tvOS"; - productReference = 5F928D961C0D469F00EF50C4 /* JSONHelper_tvOS.framework */; + productReference = 5F928D961C0D469F00EF50C4 /* JSONHelper.framework */; productType = "com.apple.product-type.framework"; }; - 5FAD07631A70F2FC00C4D09E /* JSONHelper */ = { + 5FAD07631A70F2FC00C4D09E /* JSONHelper-iOS */ = { isa = PBXNativeTarget; - buildConfigurationList = 5FAD077A1A70F2FC00C4D09E /* Build configuration list for PBXNativeTarget "JSONHelper" */; + buildConfigurationList = 5FAD077A1A70F2FC00C4D09E /* Build configuration list for PBXNativeTarget "JSONHelper-iOS" */; buildPhases = ( 5FAD075F1A70F2FC00C4D09E /* Sources */, 5FAD07601A70F2FC00C4D09E /* Frameworks */, @@ -333,7 +370,7 @@ ); dependencies = ( ); - name = JSONHelper; + name = "JSONHelper-iOS"; productName = JSONHelper; productReference = 5FAD07641A70F2FC00C4D09E /* JSONHelper.framework */; productType = "com.apple.product-type.framework"; @@ -392,9 +429,9 @@ productReference = 5FAD07981A70F31300C4D09E /* JSONHelperExampleTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - D76C52001ACD46B100B49735 /* JSONHelper_Mac */ = { + D76C52001ACD46B100B49735 /* JSONHelper-Mac */ = { isa = PBXNativeTarget; - buildConfigurationList = D76C52071ACD46B100B49735 /* Build configuration list for PBXNativeTarget "JSONHelper_Mac" */; + buildConfigurationList = D76C52071ACD46B100B49735 /* Build configuration list for PBXNativeTarget "JSONHelper-Mac" */; buildPhases = ( D76C52011ACD46B100B49735 /* Sources */, D76C52031ACD46B100B49735 /* Frameworks */, @@ -405,7 +442,7 @@ ); dependencies = ( ); - name = JSONHelper_Mac; + name = "JSONHelper-Mac"; productName = JSONHelper; productReference = D76C520A1ACD46B100B49735 /* JSONHelper.framework */; productType = "com.apple.product-type.framework"; @@ -450,9 +487,9 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 5FAD07631A70F2FC00C4D09E /* JSONHelper */, - D76C52001ACD46B100B49735 /* JSONHelper_Mac */, - 5F928D951C0D469F00EF50C4 /* JSONHelper_tvOS */, + 5FAD07631A70F2FC00C4D09E /* JSONHelper-iOS */, + D76C52001ACD46B100B49735 /* JSONHelper-Mac */, + 5F928D951C0D469F00EF50C4 /* JSONHelper-tvOS */, 5FAD076E1A70F2FC00C4D09E /* JSONHelperTests */, 5FAD07831A70F31300C4D09E /* JSONHelperExample */, 5FAD07971A70F31300C4D09E /* JSONHelperExampleTests */, @@ -513,6 +550,13 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5F31FF691C533EAA00EF50C4 /* String.swift in Sources */, + 5F31FF641C533E9D00EF50C4 /* Mapping.swift in Sources */, + 5F31FF681C533EA500EF50C4 /* JSONDataTypes.swift in Sources */, + 5F31FF6A1C533EAD00EF50C4 /* Int.swift in Sources */, + 5F31FF661C533EA100EF50C4 /* Conversion.swift in Sources */, + 5F133DA41C3840CA00EF50C4 /* JSONAPI.swift in Sources */, + 5F31FF621C533E9900EF50C4 /* Color.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -523,9 +567,12 @@ 5FC1A4941B1D1D8B00EF50C4 /* NSURL.swift in Sources */, 5FC1A4891B1D024500EF50C4 /* Int.swift in Sources */, 5FC1A48E1B1D057B00EF50C4 /* Bool.swift in Sources */, + 5F31FF601C533E9900EF50C4 /* Color.swift in Sources */, 5FC1A4871B1CFFB500EF50C4 /* String.swift in Sources */, - 5FE42BDA1B12DB3E00EF50C4 /* JSONHelper.swift in Sources */, + 5F31FF5E1C533AE000EF50C4 /* Mapping.swift in Sources */, + 5F133DA21C3840BB00EF50C4 /* JSONAPI.swift in Sources */, 5FC1A4901B1D082500EF50C4 /* NSDate.swift in Sources */, + 5F31FF5C1C533AD400EF50C4 /* Conversion.swift in Sources */, 5F1C55FC1C1AB25100EF50C4 /* JSONDataTypes.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -536,8 +583,11 @@ files = ( 5F024AE11B4127C900EF50C4 /* IntTests.swift in Sources */, 5F024AE31B412BA900EF50C4 /* BoolTests.swift in Sources */, + 5F31FF581C5339CE00EF50C4 /* NSURLTests.swift in Sources */, 5FB9D4E01B38007C00EF50C4 /* StringTests.swift in Sources */, 5FAD07771A70F2FC00C4D09E /* JSONHelperTests.swift in Sources */, + 5F31FF6C1C533F1600EF50C4 /* ColorTests.swift in Sources */, + 5F31FF561C5339B900EF50C4 /* NSDateTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -563,10 +613,14 @@ buildActionMask = 2147483647; files = ( 5FC1A4951B1D1D8B00EF50C4 /* NSURL.swift in Sources */, + 5F31FF671C533EA400EF50C4 /* JSONDataTypes.swift in Sources */, 5FC1A48C1B1D036700EF50C4 /* Int.swift in Sources */, + 5F31FF611C533E9900EF50C4 /* Color.swift in Sources */, + 5F31FF651C533EA000EF50C4 /* Conversion.swift in Sources */, 5FC1A4911B1D082B00EF50C4 /* Bool.swift in Sources */, + 5F31FF631C533E9D00EF50C4 /* Mapping.swift in Sources */, + 5F133DA31C3840C800EF50C4 /* JSONAPI.swift in Sources */, 5FC1A48B1B1D036400EF50C4 /* String.swift in Sources */, - 5FE42BDB1B12DB3E00EF50C4 /* JSONHelper.swift in Sources */, 5FC1A4921B1D082D00EF50C4 /* NSDate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -576,12 +630,12 @@ /* Begin PBXTargetDependency section */ 5F0E6F951ACDD94E00D92679 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 5FAD07631A70F2FC00C4D09E /* JSONHelper */; + target = 5FAD07631A70F2FC00C4D09E /* JSONHelper-iOS */; targetProxy = 5F0E6F941ACDD94E00D92679 /* PBXContainerItemProxy */; }; 5FAD07721A70F2FC00C4D09E /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 5FAD07631A70F2FC00C4D09E /* JSONHelper */; + target = 5FAD07631A70F2FC00C4D09E /* JSONHelper-iOS */; targetProxy = 5FAD07711A70F2FC00C4D09E /* PBXContainerItemProxy */; }; 5FAD079A1A70F31300C4D09E /* PBXTargetDependency */ = { @@ -623,11 +677,11 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; ENABLE_TESTABILITY = YES; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "JSONHelper-tvOS/Info.plist"; + INFOPLIST_FILE = "JSONHelper/Supporting Files/tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.bsencan.JSONHelper; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = JSONHelper; SDKROOT = appletvos; SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = 3; @@ -645,11 +699,11 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "JSONHelper-tvOS/Info.plist"; + INFOPLIST_FILE = "JSONHelper/Supporting Files/tvOS/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.bsencan.JSONHelper; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = JSONHelper; SDKROOT = appletvos; SKIP_INSTALL = YES; TARGETED_DEVICE_FAMILY = 3; @@ -756,7 +810,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.bsencan.JSONHelper; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = JSONHelper; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; }; @@ -775,7 +829,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.bsencan.JSONHelper; - PRODUCT_NAME = "$(TARGET_NAME)"; + PRODUCT_NAME = JSONHelper; SKIP_INSTALL = YES; }; name = Release; @@ -918,7 +972,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 5F928D9B1C0D469F00EF50C4 /* Build configuration list for PBXNativeTarget "JSONHelper_tvOS" */ = { + 5F928D9B1C0D469F00EF50C4 /* Build configuration list for PBXNativeTarget "JSONHelper-tvOS" */ = { isa = XCConfigurationList; buildConfigurations = ( 5F928D9C1C0D469F00EF50C4 /* Debug */, @@ -936,7 +990,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 5FAD077A1A70F2FC00C4D09E /* Build configuration list for PBXNativeTarget "JSONHelper" */ = { + 5FAD077A1A70F2FC00C4D09E /* Build configuration list for PBXNativeTarget "JSONHelper-iOS" */ = { isa = XCConfigurationList; buildConfigurations = ( 5FAD077B1A70F2FC00C4D09E /* Debug */, @@ -972,7 +1026,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - D76C52071ACD46B100B49735 /* Build configuration list for PBXNativeTarget "JSONHelper_Mac" */ = { + D76C52071ACD46B100B49735 /* Build configuration list for PBXNativeTarget "JSONHelper-Mac" */ = { isa = XCConfigurationList; buildConfigurations = ( D76C52081ACD46B100B49735 /* Debug */, diff --git a/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-Mac.xcscheme b/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-Mac.xcscheme index 3b5f331..c26d3a1 100644 --- a/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-Mac.xcscheme +++ b/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-Mac.xcscheme @@ -16,7 +16,21 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "D76C52001ACD46B100B49735" BuildableName = "JSONHelper.framework" - BlueprintName = "JSONHelper_Mac" + BlueprintName = "JSONHelper-Mac" + ReferencedContainer = "container:JSONHelper.xcodeproj"> + + + + @@ -26,9 +40,29 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> + + + + + + + + @@ -47,7 +81,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "D76C52001ACD46B100B49735" BuildableName = "JSONHelper.framework" - BlueprintName = "JSONHelper_Mac" + BlueprintName = "JSONHelper-Mac" ReferencedContainer = "container:JSONHelper.xcodeproj"> @@ -65,7 +99,7 @@ BuildableIdentifier = "primary" BlueprintIdentifier = "D76C52001ACD46B100B49735" BuildableName = "JSONHelper.framework" - BlueprintName = "JSONHelper_Mac" + BlueprintName = "JSONHelper-Mac" ReferencedContainer = "container:JSONHelper.xcodeproj"> diff --git a/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-iOS.xcscheme b/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-iOS.xcscheme index 431cf48..715c7be 100644 --- a/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-iOS.xcscheme +++ b/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-iOS.xcscheme @@ -15,8 +15,8 @@ @@ -40,7 +40,8 @@ buildConfiguration = "Release" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> @@ -57,8 +58,8 @@ @@ -79,8 +80,8 @@ @@ -97,8 +98,8 @@ diff --git a/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-tvOS.xcscheme b/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-tvOS.xcscheme index bc31816..6173380 100644 --- a/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-tvOS.xcscheme +++ b/JSONHelper.xcodeproj/xcshareddata/xcschemes/JSONHelper-tvOS.xcscheme @@ -15,8 +15,22 @@ + + + + @@ -26,9 +40,29 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - shouldUseLaunchSchemeArgsEnv = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> + + + + + + + + @@ -46,8 +80,8 @@ @@ -64,8 +98,8 @@ diff --git a/JSONHelper/JSONHelper.swift b/JSONHelper/Conversion.swift similarity index 58% rename from JSONHelper/JSONHelper.swift rename to JSONHelper/Conversion.swift index 38122dc..6293704 100644 --- a/JSONHelper/JSONHelper.swift +++ b/JSONHelper/Conversion.swift @@ -1,8 +1,8 @@ // -// JSONHelper.swift +// Conversion.swift // -// Created by Baris Sencan on 28/08/2014. -// Copyright 2014 Baris Sencan +// Created by Barış Şencan on 01/22/2016. +// Copyright © 2016 Barış Şencan // // Distributed under the permissive zlib license // Get the latest version from here: @@ -30,42 +30,31 @@ import Foundation -/// An object that can attempt to convert values of unknown types to its own type. -public protocol Convertible { +/// Operator for use in right hand side to left hand side conversion. +infix operator <-- { associativity right precedence 150 } - /// TODOC - static func convertFromValue(value: Any?) -> Self? -} +/// Operator for use in left hand side to right hand side conversion. +infix operator --> { associativity left precedence 150 } /// Filters out values of type NSNull. /// /// :param: value Value to check. /// /// :returns: nil if value is of type NSNull, else the value is returned as-is. -public func convertToNilIfNull(value: Any?) -> Any? { +public func convertToNilIfNull(value: T?) -> T? { if value is NSNull { return nil } return value } -/// TODOC -public protocol Deserializable { - - /// TODOC - init(jsonObject: JSONObject) -} - -/// TODOC -public protocol Serializable { +/// An object that can attempt to convert values of unknown types to its own type. +public protocol Convertible { /// TODOC - func toJSONValue() -> JSONValue + static func convertFromValue(value: T?) -> Self? } -/// Operator for use in right hand side to left hand side conversion and deserialization. -infix operator <-- { associativity right precedence 150 } - public func <-- (inout lhs: C?, rhs: T?) -> C? { lhs = C.convertFromValue(convertToNilIfNull(rhs)) return lhs @@ -130,83 +119,18 @@ public func <-- (inout lhs: [String: C], rhs: T?) -> [String: return lhs } -public func <-- (inout lhs: D?, rhs: T?) -> D? { - let cleanedValue = convertToNilIfNull(rhs) - if let jsonObject = cleanedValue as? JSONObject { - lhs = D(jsonObject: jsonObject) - } else if let string = cleanedValue as? String { - lhs <-- dataStringToObject(string) - } else { - lhs = nil - } - return lhs -} - -public func <-- (inout lhs: D, rhs: T?) -> D { - var newValue: D? - newValue <-- rhs - if let newValue = newValue { - lhs = newValue - } - return lhs -} - -public func <-- (inout lhs: [D]?, rhs: T?) -> [D]? { - if let array = rhs as? [AnyObject] { - lhs = [D]() - for element in array { - var convertedElement: D? - convertedElement <-- element - if let convertedElement = convertedElement { - lhs?.append(convertedElement) - } - } - } else if let string = convertToNilIfNull(rhs) as? String { - lhs <-- dataStringToObject(string) - } else { - lhs = nil - } - return lhs -} - -public func <-- (inout lhs: [D], rhs: T?) -> [D] { - var newValue: [D]? - newValue <-- rhs - if let newValue = newValue { - lhs = newValue - } - return lhs -} - -/// Operator for use in left hand side to right hand side conversion and serialization. -infix operator --> { associativity left precedence 150 } - -public func --> (lhs: Any?, inout rhs: C?) -> C? { +public func --> (lhs: T?, inout rhs: C?) -> C? { return rhs <-- lhs } -public func --> (lhs: Any?, inout rhs: C) -> C { +public func --> (lhs: T?, inout rhs: C) -> C { return rhs <-- lhs } -public func --> (lhs: AnyObject?, inout rhs: [C]?) -> [C]? { +public func --> (lhs: T?, inout rhs: [C]?) -> [C]? { return rhs <-- lhs } -public func --> (lhs: AnyObject?, inout rhs: [C]) -> [C] { +public func --> (lhs: T?, inout rhs: [C]) -> [C] { return rhs <-- lhs } - -// TODO: Serialization - - -// MARK: - Helper methods - -private func dataStringToObject(dataString: String) -> AnyObject? { - guard let data: NSData = dataString.dataUsingEncoding(NSUTF8StringEncoding) else { return nil } - var jsonObject: AnyObject? - do { - jsonObject = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0)) - } catch {} - return jsonObject -} diff --git a/JSONHelper/Extensions/Bool.swift b/JSONHelper/Extensions/Bool.swift index b953eb7..d9937f7 100644 --- a/JSONHelper/Extensions/Bool.swift +++ b/JSONHelper/Extensions/Bool.swift @@ -1,8 +1,8 @@ // // Bool.swift // -// Created by Baris Sencan on 06/01/2015. -// Copyright 2014 Baris Sencan +// Created by Barış Şencan on 06/01/2015. +// Copyright © 2015 Barış Şencan // // Distributed under the permissive zlib license // Get the latest version from here: @@ -32,21 +32,21 @@ import Foundation extension Bool: Convertible { - public static func convertFromValue(value: Any?) -> Bool? { - if let value: Any = value { - if let boolValue = value as? Bool { - return boolValue - } else if let intValue = value as? Int { - return intValue > 0 - } else if let stringValue = value as? String { - switch stringValue.lowercaseString { - case "true", "t": - return true - case "false", "f": - return false - default: - return nil - } + public static func convertFromValue(value: T?) -> Bool? { + guard let value = value else { return nil } + + if let boolValue = value as? Bool { + return boolValue + } else if let intValue = value as? Int { + return intValue > 0 + } else if let stringValue = value as? String { + switch stringValue.lowercaseString { + case "true", "t", "yes", "y": + return true + case "false", "f", "no", "n": + return false + default: + return nil } } return nil diff --git a/JSONHelper/Extensions/Color.swift b/JSONHelper/Extensions/Color.swift index 070c86d..c50a9f5 100644 --- a/JSONHelper/Extensions/Color.swift +++ b/JSONHelper/Extensions/Color.swift @@ -1,42 +1,86 @@ // // Color.swift -// JSONHelper // -// Created by Baris Sencan on 6/29/15. -// Copyright (c) 2015 Baris Sencan. All rights reserved. +// Created by Barış Şencan on 06/29/2015. +// Copyright © 2015 Barış Şencan +// +// Distributed under the permissive zlib license +// Get the latest version from here: +// +// https://github.com/isair/JSONHelper +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. // private struct ColorConversionHelper { - private static func hexStringToRGB(hexString: String) -> (red: CGFloat, green: CGFloat, blue: CGFloat) { - let trimmedString = hexString.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) - let scanner = NSScanner(string: trimmedString) - if trimmedString.hasPrefix("#") { - scanner.scanLocation = 1 + private static func hexStringToRGBA(hexString: String) -> (red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat) { + var red = CGFloat(0) + var green = CGFloat(0) + var blue = CGFloat(0) + var alpha = CGFloat(1) + + if hexString.hasPrefix("#") { + let index = hexString.startIndex.advancedBy(1) + let hex = hexString.substringFromIndex(index) + let scanner = NSScanner(string: hex) + var hexValue = CUnsignedLongLong(0) + + if scanner.scanHexLongLong(&hexValue) { + switch (hex.characters.count) { + case 3: + red = CGFloat((hexValue & 0xF00) >> 8) / 15.0 + green = CGFloat((hexValue & 0x0F0) >> 4) / 15.0 + blue = CGFloat(hexValue & 0x00F) / 15.0 + case 4: + red = CGFloat((hexValue & 0xF000) >> 12) / 15.0 + green = CGFloat((hexValue & 0x0F00) >> 8) / 15.0 + blue = CGFloat((hexValue & 0x00F0) >> 4) / 15.0 + alpha = CGFloat(hexValue & 0x000F) / 15.0 + case 6: + red = CGFloat((hexValue & 0xFF0000) >> 16) / 255.0 + green = CGFloat((hexValue & 0x00FF00) >> 8) / 255.0 + blue = CGFloat(hexValue & 0x0000FF) / 255.0 + case 8: + red = CGFloat((hexValue & 0xFF000000) >> 24) / 255.0 + green = CGFloat((hexValue & 0x00FF0000) >> 16) / 255.0 + blue = CGFloat((hexValue & 0x0000FF00) >> 8) / 255.0 + alpha = CGFloat(hexValue & 0x000000FF) / 255.0 + default: + break + } + } } - var color:UInt32 = 0 - scanner.scanHexInt(&color) - let mask = 0x000000FF - let r = Int(color >> 16) & mask - let g = Int(color >> 8) & mask - let b = Int(color) & mask - let red = CGFloat(r) / 255.0 - let green = CGFloat(g) / 255.0 - let blue = CGFloat(b) / 255.0 - return (red: red, green: green, blue: blue) + return (red: red, green: green, blue: blue, alpha: alpha) } } -#if os(iOS) +#if os(iOS) || os(tvOS) import UIKit extension UIColor: Convertible { - public static func convertFromValue(value: Any?) -> Self? { + public static func convertFromValue(value: T?) -> Self? { if let stringValue = value as? String { - let rgb = ColorConversionHelper.hexStringToRGB(stringValue) - return self(red: rgb.red, green: rgb.green, blue: rgb.blue, alpha: 1) + let rgba = ColorConversionHelper.hexStringToRGBA(stringValue) + return self.init(red: rgba.red, green: rgba.green, blue: rgba.blue, alpha: rgba.alpha) } return nil } @@ -48,10 +92,10 @@ import AppKit extension NSColor: Convertible { - public static func convertFromValue(value: Any?) -> Self? { + public static func convertFromValue(value: T?) -> Self? { if let stringValue = value as? String { let rgb = ColorConversionHelper.hexStringToRGB(stringValue) - return self(red: rgb.red, green: rgb.green, blue: rgb.blue, alpha: 1) + return self.init(red: rgb.red, green: rgb.green, blue: rgb.blue, alpha: 1) } return nil } diff --git a/JSONHelper/Extensions/Int.swift b/JSONHelper/Extensions/Int.swift index bd4e865..f8c6654 100644 --- a/JSONHelper/Extensions/Int.swift +++ b/JSONHelper/Extensions/Int.swift @@ -1,8 +1,8 @@ // // Int.swift // -// Created by Baris Sencan on 06/01/2015. -// Copyright 2014 Baris Sencan +// Created by Barış Şencan on 06/01/2015. +// Copyright © 2015 Barış Şencan // // Distributed under the permissive zlib license // Get the latest version from here: @@ -32,13 +32,13 @@ import Foundation extension Int: Convertible { - public static func convertFromValue(value: Any?) -> Int? { - if let value: Any = value { - if let intValue = value as? Int { - return intValue - } else if let stringValue = value as? String { - return Int(stringValue) - } + public static func convertFromValue(value: T?) -> Int? { + guard let value = value else { return nil } + + if let intValue = value as? Int { + return intValue + } else if let stringValue = value as? String { + return Int(stringValue) } return nil } diff --git a/JSONHelper/Extensions/NSDate.swift b/JSONHelper/Extensions/NSDate.swift index 9176eb3..2ebf49f 100644 --- a/JSONHelper/Extensions/NSDate.swift +++ b/JSONHelper/Extensions/NSDate.swift @@ -1,8 +1,8 @@ // // NSDate.swift // -// Created by Baris Sencan on 06/01/2015. -// Copyright 2014 Baris Sencan +// Created by Barış Şencan on 06/01/2015. +// Copyright © 2015 Barış Şencan // // Distributed under the permissive zlib license // Get the latest version from here: @@ -33,23 +33,23 @@ import Foundation extension NSDate: Convertible { private static let sharedFormatter = NSDateFormatter() - public static func convertFromValue(value: Any?) -> Self? { - if let value: Any = value { - if let unixTimeStamp = value as? NSTimeInterval { - return self.init(timeIntervalSince1970: unixTimeStamp) - } else if let - jsonDictionaryValueAndFormatTuple = value as? (AnyObject?, String), - stringValue = jsonDictionaryValueAndFormatTuple.0 as? String { - sharedFormatter.dateFormat = jsonDictionaryValueAndFormatTuple.1 - if let convertedDate = sharedFormatter.dateFromString(stringValue) { - return self.init(timeIntervalSince1970: convertedDate.timeIntervalSince1970) - } - } else if let - jsonDictionaryValueAndConversionClosureTuple = value as? (AnyObject?, (value: AnyObject) -> NSDate?), - jsonDictionaryValue: AnyObject = jsonDictionaryValueAndConversionClosureTuple.0, - convertedDate = jsonDictionaryValueAndConversionClosureTuple.1(value: jsonDictionaryValue) { + public static func convertFromValue(value: T?) -> Self? { + guard let value = value else { return nil } + + if let unixTimeStamp = value as? NSTimeInterval { + return self.init(timeIntervalSince1970: unixTimeStamp) + } else if let + jsonDictionaryValueAndFormatTuple = value as? (AnyObject?, String), + stringValue = jsonDictionaryValueAndFormatTuple.0 as? String { + sharedFormatter.dateFormat = jsonDictionaryValueAndFormatTuple.1 + if let convertedDate = sharedFormatter.dateFromString(stringValue) { return self.init(timeIntervalSince1970: convertedDate.timeIntervalSince1970) - } + } + } else if let + jsonDictionaryValueAndConversionClosureTuple = value as? (AnyObject?, (value: AnyObject) -> NSDate?), + jsonDictionaryValue: AnyObject = jsonDictionaryValueAndConversionClosureTuple.0, + convertedDate = jsonDictionaryValueAndConversionClosureTuple.1(value: jsonDictionaryValue) { + return self.init(timeIntervalSince1970: convertedDate.timeIntervalSince1970) } return nil } diff --git a/JSONHelper/Extensions/NSURL.swift b/JSONHelper/Extensions/NSURL.swift index 66ecfb8..bad2eb3 100644 --- a/JSONHelper/Extensions/NSURL.swift +++ b/JSONHelper/Extensions/NSURL.swift @@ -1,8 +1,8 @@ // // NSURL.swift // -// Created by Baris Sencan on 06/01/2015. -// Copyright 2014 Baris Sencan +// Created by Barış Şencan on 06/01/2015. +// Copyright © 2015 Barış Şencan // // Distributed under the permissive zlib license // Get the latest version from here: @@ -32,7 +32,7 @@ import Foundation extension NSURL: Convertible { - public static func convertFromValue(value: Any?) -> Self? { + public static func convertFromValue(value: T?) -> Self? { if let stringValue = value as? String { return self.init(string: stringValue) } diff --git a/JSONHelper/Extensions/String.swift b/JSONHelper/Extensions/String.swift index 3d2eb1b..2832f1e 100644 --- a/JSONHelper/Extensions/String.swift +++ b/JSONHelper/Extensions/String.swift @@ -1,8 +1,8 @@ // // String.swift // -// Created by Baris Sencan on 06/01/2015. -// Copyright 2014 Baris Sencan +// Created by Barış Şencan on 06/01/2015. +// Copyright © 2015 Barış Şencan // // Distributed under the permissive zlib license // Get the latest version from here: @@ -32,13 +32,13 @@ import Foundation extension String: Convertible { - public static func convertFromValue(value: Any?) -> String? { - if let value: Any = value { - if let stringValue = value as? String { - return stringValue - } else if let intValue = value as? Int { - return "\(intValue)" - } + public static func convertFromValue(value: T?) -> String? { + guard let value = value else { return nil } + + if let stringValue = value as? String { + return stringValue + } else if let intValue = value as? Int { + return "\(intValue)" } return nil } diff --git a/JSONHelper/JSONDataTypes.swift b/JSONHelper/JSONDataTypes.swift index 9718d58..8997758 100644 --- a/JSONHelper/JSONDataTypes.swift +++ b/JSONHelper/JSONDataTypes.swift @@ -1,9 +1,31 @@ // // JSONDataTypes.swift -// JSONHelper // -// Created by Baris Sencan on 10/12/2015. -// Copyright © 2015 Baris Sencan. All rights reserved. +// Created by Barış Şencan on 12/10/2015. +// Copyright © 2016 Barış Şencan +// +// Distributed under the permissive zlib license +// Get the latest version from here: +// +// https://github.com/isair/JSONHelper +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. // import Foundation diff --git a/JSONHelper/Mapping.swift b/JSONHelper/Mapping.swift new file mode 100644 index 0000000..e1e7b01 --- /dev/null +++ b/JSONHelper/Mapping.swift @@ -0,0 +1,104 @@ +// +// Mapping.swift +// +// Created by Barış Şencan on 01/22/2016. +// Copyright © 2016 Barış Şencan +// +// Distributed under the permissive zlib license +// Get the latest version from here: +// +// https://github.com/isair/JSONHelper +// +// This software is provided 'as-is', without any express or implied +// warranty. In no event will the authors be held liable for any damages +// arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it +// freely, subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; you must not +// claim that you wrote the original software. If you use this software +// in a product, an acknowledgment in the product documentation would be +// appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, and must not be +// misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// + +import Foundation + +/// TODOC +public protocol Deserializable { + + /// TODOC + init(jsonObject: JSONObject) +} + +/// TODOC +public protocol Serializable { + + /// TODOC + func toJSONValue() -> JSONValue +} + +public func <-- (inout lhs: D?, rhs: T?) -> D? { + let cleanedValue = convertToNilIfNull(rhs) + if let jsonObject = cleanedValue as? JSONObject { + lhs = D(jsonObject: jsonObject) + } else if let string = cleanedValue as? String { + lhs <-- dataStringToObject(string) + } else { + lhs = nil + } + return lhs +} + +public func <-- (inout lhs: D, rhs: T?) -> D { + var newValue: D? + newValue <-- rhs + if let newValue = newValue { + lhs = newValue + } + return lhs +} + +public func <-- (inout lhs: [D]?, rhs: T?) -> [D]? { + if let array = rhs as? [AnyObject] { + lhs = [D]() + for element in array { + var convertedElement: D? + convertedElement <-- element + if let convertedElement = convertedElement { + lhs?.append(convertedElement) + } + } + } else if let string = convertToNilIfNull(rhs) as? String { + lhs <-- dataStringToObject(string) + } else { + lhs = nil + } + return lhs +} + +public func <-- (inout lhs: [D], rhs: T?) -> [D] { + var newValue: [D]? + newValue <-- rhs + if let newValue = newValue { + lhs = newValue + } + return lhs +} + +// MARK: - Helper methods + +private func dataStringToObject(dataString: String) -> AnyObject? { + guard let data: NSData = dataString.dataUsingEncoding(NSUTF8StringEncoding) else { return nil } + var jsonObject: AnyObject? + do { + jsonObject = try NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue: 0)) + } catch {} + return jsonObject +} diff --git a/JSONHelper/Support/JSONAPI.swift b/JSONHelper/Support/JSONAPI.swift new file mode 100644 index 0000000..fd4b647 --- /dev/null +++ b/JSONHelper/Support/JSONAPI.swift @@ -0,0 +1,11 @@ +// +// JSONAPI.swift +// JSONHelper +// +// Created by Baris Sencan on 02/01/2016. +// Copyright © 2016 Baris Sencan. All rights reserved. +// + +import Foundation + +// TODO diff --git a/JSONHelperTests/BoolTests.swift b/JSONHelperTests/BoolTests.swift index 0a459d4..30fd15c 100644 --- a/JSONHelperTests/BoolTests.swift +++ b/JSONHelperTests/BoolTests.swift @@ -19,26 +19,26 @@ class BoolTests: XCTestCase { func testBoolToBoolConversion() { var value: Bool? value <-- (testBool as Any) - XCTAssertEqual(value!, testBool, "Bool to Bool conversion failed") + XCTAssertEqual(value, testBool, "Bool to Bool conversion failed") } func testIntToBoolConversion() { var value: Bool? for intAndResult in testIntsAndResults { value <-- (intAndResult.0 as Any) - XCTAssertEqual(value!, intAndResult.1, "Int to Bool conversion failed for value \(intAndResult.0)") + XCTAssertEqual(value, intAndResult.1, "Int to Bool conversion failed for value \(intAndResult.0)") } } func testStringToBoolConversion() { var value: Bool? value <-- (testString as Any) - XCTAssertEqual(value!, testBool, "String to Bool conversion failed") + XCTAssertEqual(value, testBool, "String to Bool conversion failed") } func testAlternativeStringToBoolConversion() { var value: Bool? value <-- (testStringAlternative as Any) - XCTAssertEqual(value!, testBool, "String to Bool conversion failed for alternative string representation") + XCTAssertEqual(value, testBool, "String to Bool conversion failed for alternative string representation") } } diff --git a/JSONHelperTests/ColorTests.swift b/JSONHelperTests/ColorTests.swift index 5f93a86..ce9c226 100644 --- a/JSONHelperTests/ColorTests.swift +++ b/JSONHelperTests/ColorTests.swift @@ -9,7 +9,7 @@ import XCTest import JSONHelper -#if os(iOS) +#if os(iOS) || os(tvOS) import UIKit @@ -23,12 +23,12 @@ class ColorTests: XCTestCase { let testStringAndResult = ("#ffffff", (r: CGFloat(1), g: CGFloat(1), b: CGFloat(1), a: CGFloat(1))) func testStringToColorConversion() { - #if os(iOS) + #if os(iOS) || os(tvOS) var value: UIColor? #else var value: NSColor? #endif - value <-- testStringAndResult.0 + value <-- (testStringAndResult.0 as Any) var r: CGFloat = 0 var g: CGFloat = 0 var b: CGFloat = 0 diff --git a/JSONHelperTests/IntTests.swift b/JSONHelperTests/IntTests.swift index 3b56038..9efbe86 100644 --- a/JSONHelperTests/IntTests.swift +++ b/JSONHelperTests/IntTests.swift @@ -17,12 +17,12 @@ class IntTests: XCTestCase { func testIntToIntConversion() { var value: Int? value <-- (testInt as Any) - XCTAssertEqual(value!, testInt, "Int to Int conversion failed") + XCTAssertEqual(value, testInt, "Int to Int conversion failed") } func testStringToIntConversion() { var value: Int? value <-- (testString as Any) - XCTAssertEqual(value!, testInt, "String to Int conversion failed") + XCTAssertEqual(value, testInt, "String to Int conversion failed") } } diff --git a/JSONHelperTests/NSDateTests.swift b/JSONHelperTests/NSDateTests.swift new file mode 100644 index 0000000..15c4330 --- /dev/null +++ b/JSONHelperTests/NSDateTests.swift @@ -0,0 +1,11 @@ +// +// NSDateTests.swift +// JSONHelper +// +// Created by Baris Sencan on 22/01/2016. +// Copyright © 2016 Baris Sencan. All rights reserved. +// + +import Foundation + +// TODO diff --git a/JSONHelperTests/NSURLTests.swift b/JSONHelperTests/NSURLTests.swift new file mode 100644 index 0000000..2be4175 --- /dev/null +++ b/JSONHelperTests/NSURLTests.swift @@ -0,0 +1,11 @@ +// +// NSURLTests.swift +// JSONHelper +// +// Created by Baris Sencan on 22/01/2016. +// Copyright © 2016 Baris Sencan. All rights reserved. +// + +import Foundation + +// TODO diff --git a/JSONHelperTests/StringTests.swift b/JSONHelperTests/StringTests.swift index 4e77a7e..4802af6 100644 --- a/JSONHelperTests/StringTests.swift +++ b/JSONHelperTests/StringTests.swift @@ -17,12 +17,12 @@ class StringTests: XCTestCase { func testStringToStringConversion() { var value: String? value <-- (testString as Any) - XCTAssertEqual(value!, testString, "String to String conversion failed") + XCTAssertEqual(value, testString, "String to String conversion failed") } func testIntToStringConversion() { var value: String? value <-- (testIntAndResult.0 as Any) - XCTAssertEqual(value!, testIntAndResult.1, "Int to String conversion failed") + XCTAssertEqual(value, testIntAndResult.1, "Int to String conversion failed") } }