diff --git a/Alexander.xcodeproj/project.pbxproj b/Alexander.xcodeproj/project.pbxproj index 4d87dab..21b3b81 100644 --- a/Alexander.xcodeproj/project.pbxproj +++ b/Alexander.xcodeproj/project.pbxproj @@ -7,22 +7,23 @@ objects = { /* Begin PBXBuildFile section */ - 3A512EC81BE15A380091A124 /* JSONCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AADB1B824C1200491A67 /* JSONCodable.swift */; }; 3A512ED21BE169390091A124 /* Alexander.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A512ECB1BE168C30091A124 /* Alexander.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3A512ED31BE1693C0091A124 /* Alexander.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A512ECE1BE168C30091A124 /* Alexander.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3A512EE31BE169920091A124 /* Alexander.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A512ED91BE169910091A124 /* Alexander.framework */; }; 3A512F021BE16AD10091A124 /* Alexander.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A512EFD1BE16AC00091A124 /* Alexander.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3A512F031BE16AD60091A124 /* Alexander.h in Headers */ = {isa = PBXBuildFile; fileRef = 3A512EFF1BE16AC60091A124 /* Alexander.h */; settings = {ATTRIBUTES = (Public, ); }; }; 3A512F041BE16B250091A124 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BEDAE5C1B5DC4B200AD52FE /* JSON.swift */; }; - 3A512F051BE16B250091A124 /* JSONCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AADB1B824C1200491A67 /* JSONCodable.swift */; }; 3A512F061BE16B250091A124 /* Defines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AAD81B82452800491A67 /* Defines.swift */; }; 3A512F071BE16B250091A124 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BEDAE5C1B5DC4B200AD52FE /* JSON.swift */; }; - 3A512F081BE16B250091A124 /* JSONCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AADB1B824C1200491A67 /* JSONCodable.swift */; }; 3A512F091BE16B250091A124 /* Defines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AAD81B82452800491A67 /* Defines.swift */; }; 3AA08DDA1BFE417C001BCA4D /* Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DD91BFE417C001BCA4D /* Deprecated.swift */; }; 3AA08DDB1BFE417C001BCA4D /* Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DD91BFE417C001BCA4D /* Deprecated.swift */; }; 3AA08DDC1BFE417C001BCA4D /* Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DD91BFE417C001BCA4D /* Deprecated.swift */; }; 3AA08DDD1BFE417C001BCA4D /* Deprecated.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DD91BFE417C001BCA4D /* Deprecated.swift */; }; + 3AA08DDF1BFE4FCD001BCA4D /* EncoderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DDE1BFE4FCD001BCA4D /* EncoderType.swift */; }; + 3AA08DE01BFE4FCD001BCA4D /* EncoderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DDE1BFE4FCD001BCA4D /* EncoderType.swift */; }; + 3AA08DE11BFE4FCD001BCA4D /* EncoderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DDE1BFE4FCD001BCA4D /* EncoderType.swift */; }; + 3AA08DE21BFE4FCD001BCA4D /* EncoderType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AA08DDE1BFE4FCD001BCA4D /* EncoderType.swift */; }; 3AE5C3941BFD3EBC00F1080F /* AlexanderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE5C3931BFD3EBC00F1080F /* AlexanderTests.swift */; }; 3AE5C3951BFD3EBC00F1080F /* AlexanderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE5C3931BFD3EBC00F1080F /* AlexanderTests.swift */; }; 3AE5C3961BFD3EBC00F1080F /* AlexanderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE5C3931BFD3EBC00F1080F /* AlexanderTests.swift */; }; @@ -35,7 +36,6 @@ 3AE5C3A31BFD551800F1080F /* UserDecoderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AE5C3A01BFD551800F1080F /* UserDecoderTests.swift */; }; 3B62AAD91B82452800491A67 /* Defines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AAD81B82452800491A67 /* Defines.swift */; }; 3B62AADA1B82452800491A67 /* Defines.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AAD81B82452800491A67 /* Defines.swift */; }; - 3B62AADC1B824C1200491A67 /* JSONCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3B62AADB1B824C1200491A67 /* JSONCodable.swift */; }; 3BEDAE2B1B5DC30500AD52FE /* Alexander.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BEDAE1F1B5DC30500AD52FE /* Alexander.framework */; }; 3BEDAE5D1B5DC4B200AD52FE /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3BEDAE5C1B5DC4B200AD52FE /* JSON.swift */; }; 3BEDAE6F1B5DC4EC00AD52FE /* Alexander.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3BEDAE641B5DC4EC00AD52FE /* Alexander.framework */; }; @@ -82,11 +82,11 @@ 3A512F101BE16BB60091A124 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3A512F121BE16BB60091A124 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 3AA08DD91BFE417C001BCA4D /* Deprecated.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Deprecated.swift; sourceTree = ""; }; + 3AA08DDE1BFE4FCD001BCA4D /* EncoderType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncoderType.swift; sourceTree = ""; }; 3AE5C3931BFD3EBC00F1080F /* AlexanderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlexanderTests.swift; sourceTree = ""; }; 3AE5C39B1BFD522300F1080F /* DecoderType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DecoderType.swift; sourceTree = ""; }; 3AE5C3A01BFD551800F1080F /* UserDecoderTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UserDecoderTests.swift; sourceTree = ""; }; 3B62AAD81B82452800491A67 /* Defines.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Defines.swift; sourceTree = ""; }; - 3B62AADB1B824C1200491A67 /* JSONCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONCodable.swift; sourceTree = ""; }; 3BEDAE1F1B5DC30500AD52FE /* Alexander.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Alexander.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3BEDAE2A1B5DC30500AD52FE /* Alexander iOS Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Alexander iOS Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 3BEDAE5C1B5DC4B200AD52FE /* JSON.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSON.swift; sourceTree = ""; }; @@ -269,7 +269,7 @@ children = ( 3BEDAE5C1B5DC4B200AD52FE /* JSON.swift */, 3AE5C39B1BFD522300F1080F /* DecoderType.swift */, - 3B62AADB1B824C1200491A67 /* JSONCodable.swift */, + 3AA08DDE1BFE4FCD001BCA4D /* EncoderType.swift */, 3B62AAD81B82452800491A67 /* Defines.swift */, 3AA08DD91BFE417C001BCA4D /* Deprecated.swift */, 3A512EC91BE168C30091A124 /* Configuration */, @@ -555,7 +555,7 @@ buildActionMask = 2147483647; files = ( 3AE5C39E1BFD522300F1080F /* DecoderType.swift in Sources */, - 3A512F051BE16B250091A124 /* JSONCodable.swift in Sources */, + 3AA08DE11BFE4FCD001BCA4D /* EncoderType.swift in Sources */, 3AA08DDC1BFE417C001BCA4D /* Deprecated.swift in Sources */, 3A512F041BE16B250091A124 /* JSON.swift in Sources */, 3A512F061BE16B250091A124 /* Defines.swift in Sources */, @@ -576,7 +576,7 @@ buildActionMask = 2147483647; files = ( 3AE5C39F1BFD522300F1080F /* DecoderType.swift in Sources */, - 3A512F081BE16B250091A124 /* JSONCodable.swift in Sources */, + 3AA08DE21BFE4FCD001BCA4D /* EncoderType.swift in Sources */, 3AA08DDD1BFE417C001BCA4D /* Deprecated.swift in Sources */, 3A512F071BE16B250091A124 /* JSON.swift in Sources */, 3A512F091BE16B250091A124 /* Defines.swift in Sources */, @@ -589,8 +589,8 @@ files = ( 3AE5C39C1BFD522300F1080F /* DecoderType.swift in Sources */, 3B62AAD91B82452800491A67 /* Defines.swift in Sources */, + 3AA08DDF1BFE4FCD001BCA4D /* EncoderType.swift in Sources */, 3AA08DDA1BFE417C001BCA4D /* Deprecated.swift in Sources */, - 3B62AADC1B824C1200491A67 /* JSONCodable.swift in Sources */, 3BEDAE5D1B5DC4B200AD52FE /* JSON.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -610,9 +610,9 @@ files = ( 3AE5C39D1BFD522300F1080F /* DecoderType.swift in Sources */, 3B62AADA1B82452800491A67 /* Defines.swift in Sources */, + 3AA08DE01BFE4FCD001BCA4D /* EncoderType.swift in Sources */, 3AA08DDB1BFE417C001BCA4D /* Deprecated.swift in Sources */, 3BEDAE7D1B5DC58800AD52FE /* JSON.swift in Sources */, - 3A512EC81BE15A380091A124 /* JSONCodable.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Alexander/Deprecated.swift b/Alexander/Deprecated.swift index ae7b608..88a1b9e 100644 --- a/Alexander/Deprecated.swift +++ b/Alexander/Deprecated.swift @@ -42,7 +42,7 @@ extension JSON { } } -@available(*, deprecated, message = "Use DecoderType instead.") +@available(*, deprecated, message = "Use Alexander.DecoderType instead.") public protocol JSONDecodable { static func decode(JSON: Alexander.JSON) -> Self? } @@ -66,3 +66,8 @@ public extension Alexander.JSON { return decodeArray(RawRepresentableDecoder) } } + +@available(*, deprecated, message = "Use Alexander.EncoderType instead.") +public protocol JSONEncodable { + var JSON: Alexander.JSON { get } +} diff --git a/Alexander/EncoderType.swift b/Alexander/EncoderType.swift new file mode 100644 index 0000000..2ea33d4 --- /dev/null +++ b/Alexander/EncoderType.swift @@ -0,0 +1,33 @@ +// +// EncoderType.swift +// Alexander +// +// Created by Caleb Davenport on 11/19/15. +// Copyright © 2015 Hodinkee. All rights reserved. +// + +public protocol EncoderType { + typealias Value + static func encode(value: Value) -> JSON +} + +public struct NSDateTimeIntervalSince1970Encoder: EncoderType { + public typealias Value = NSDate + public static func encode(value: NSDate) -> JSON { + return JSON(object: value.timeIntervalSince1970) + } +} + +public struct NSDateTimeIntervalSinceReferenceDateEncoder: EncoderType { + public typealias Value = NSDate + public static func encode(value: NSDate) -> JSON { + return JSON(object: value.timeIntervalSinceReferenceDate) + } +} + +public struct NSURLEncoder: EncoderType { + public typealias Value = NSURL + public static func encode(value: NSURL) -> JSON { + return JSON(object: value.absoluteString) + } +} diff --git a/Alexander/JSONCodable.swift b/Alexander/JSONCodable.swift deleted file mode 100644 index a305f3f..0000000 --- a/Alexander/JSONCodable.swift +++ /dev/null @@ -1,11 +0,0 @@ -// -// JSONCodable.swift -// Alexander -// -// Created by Jonathan Baker on 8/6/15. -// Copyright (c) 2015 Hodinkee. All rights reserved. -// - -public protocol JSONEncodable { - var JSON: Alexander.JSON { get } -}