Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 467a07d

Browse files
xmkevinchenNadohs
authored andcommitted
Xcode GM supported (matthewcheok#53)
* Updated for Swift 3 * Fixed tests * Add support exporting nested JSON objects * test for encoding nested JSON objects and remove unneeded imports. * implementation for top level array and tests for Decoding * - Solved dynamicType and String initializer * - Fixed syntax upgrade issues * - Fixed unit tests * - Updated the Array extension to adopt swift 3 new syntax * - Fixed the Mirror doesn't have displayStyle for Swift default type, like String, Int, etc * - Updated JSONCompatible toJSON bug * Xcode GM supported * Upgraded version
1 parent 9056435 commit 467a07d

27 files changed

+604
-394
lines changed

JSONCodable.playground/Contents.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ We'll add conformance to `JSONEncodable`. You may also add conformance to `JSONC
3131
*/
3232

3333
extension User: JSONEncodable {
34-
func toJSON() throws -> AnyObject {
34+
func toJSON() throws -> Any {
3535
return try JSONEncoder.create({ (encoder) -> Void in
3636
try encoder.encode(id, key: "id")
3737
try encoder.encode(name, key: "full_name")
@@ -83,7 +83,7 @@ You can open the console and see the output using `CMD + SHIFT + Y` or ⇧⌘Y.
8383
Let's work with an incoming JSON Dictionary:
8484
*/
8585

86-
let JSON = [
86+
let JSON: [String: Any] = [
8787
"id": 24,
8888
"full_name": "John Appleseed",
8989
"email": "[email protected]",
@@ -114,5 +114,7 @@ And encode it to JSON using one of the provided methods:
114114
- `func JSONString() throws -> String`
115115
*/
116116

117+
try! 1.toJSON()
118+
117119
let dict = try! user.toJSON()
118120
print("Encoded: \n\(dict as! JSONObject)\n\n")

JSONCodable.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'JSONCodable'
3-
s.version = '2.1'
3+
s.version = '2.2'
44
s.ios.deployment_target = '8.0'
55
s.osx.deployment_target = '10.10'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

JSONCodable.xcodeproj/project.pbxproj

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
A1B71C7E1D37E90B006DA33A /* MirrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B71C7D1D37E90B006DA33A /* MirrorTests.swift */; };
3838
A1B71C801D37E982006DA33A /* ClassInheritance.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B71C7F1D37E982006DA33A /* ClassInheritance.swift */; };
3939
A1B71C811D37EA92006DA33A /* JSONEncodable+Mirror.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1B71C7B1D37E6BD006DA33A /* JSONEncodable+Mirror.swift */; };
40+
BD885BBE1D17358E00CA767A /* EncodeNestingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD885BBD1D17358E00CA767A /* EncodeNestingTests.swift */; };
41+
BD885BC01D173A0700CA767A /* PropertyItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD885BBF1D173A0700CA767A /* PropertyItem.swift */; };
42+
BDD667CC1D1F3572003F94D7 /* Messages.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD667CB1D1F3572003F94D7 /* Messages.swift */; };
4043
/* End PBXBuildFile section */
4144

4245
/* Begin PBXContainerItemProxy section */
@@ -76,6 +79,9 @@
7679
A1B71C7B1D37E6BD006DA33A /* JSONEncodable+Mirror.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "JSONEncodable+Mirror.swift"; sourceTree = "<group>"; };
7780
A1B71C7D1D37E90B006DA33A /* MirrorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MirrorTests.swift; sourceTree = "<group>"; };
7881
A1B71C7F1D37E982006DA33A /* ClassInheritance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClassInheritance.swift; sourceTree = "<group>"; };
82+
BD885BBD1D17358E00CA767A /* EncodeNestingTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EncodeNestingTests.swift; sourceTree = "<group>"; };
83+
BD885BBF1D173A0700CA767A /* PropertyItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PropertyItem.swift; sourceTree = "<group>"; };
84+
BDD667CB1D1F3572003F94D7 /* Messages.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Messages.swift; sourceTree = "<group>"; };
7985
/* End PBXFileReference section */
8086

8187
/* Begin PBXFrameworksBuildPhase section */
@@ -118,6 +124,8 @@
118124
isa = PBXGroup;
119125
children = (
120126
5211CD091CE2EBFB0097F255 /* NestItem.swift */,
127+
BDD667CB1D1F3572003F94D7 /* Messages.swift */,
128+
BD885BBF1D173A0700CA767A /* PropertyItem.swift */,
121129
9E455C021BCE1C1E00070A4F /* Fruit.swift */,
122130
9E8E07231BD3F15800F98421 /* Food.swift */,
123131
9E455C041BCE1D0700070A4F /* User.swift */,
@@ -134,6 +142,7 @@
134142
9ECF00C31BCF82F5008D557C /* HelperTests.swift */,
135143
52E8F44E1C9087D200F40F7F /* UtilityTests.swift */,
136144
9E455C0A1BCE1F0100070A4F /* RegularTests.swift */,
145+
BD885BBD1D17358E00CA767A /* EncodeNestingTests.swift */,
137146
9E455BF91BCE185B00070A4F /* EnumTests.swift */,
138147
9ECF00BF1BCE251B008D557C /* TransformerTests.swift */,
139148
A1B71C7D1D37E90B006DA33A /* MirrorTests.swift */,
@@ -266,7 +275,7 @@
266275
9EDF80101B59CFCE00E4A2D6 /* Project object */ = {
267276
isa = PBXProject;
268277
attributes = {
269-
LastUpgradeCheck = 0710;
278+
LastUpgradeCheck = 0800;
270279
TargetAttributes = {
271280
9E455BF61BCE185B00070A4F = {
272281
CreatedOnToolsVersion = 7.0.1;
@@ -276,6 +285,7 @@
276285
};
277286
9EDB39221B59D01D00C63019 = {
278287
CreatedOnToolsVersion = 7.0;
288+
LastSwiftMigration = 0800;
279289
};
280290
};
281291
};
@@ -335,10 +345,13 @@
335345
9ECF00C21BCF6E43008D557C /* ImageAsset.swift in Sources */,
336346
9E455C031BCE1C1E00070A4F /* Fruit.swift in Sources */,
337347
9ECF00C01BCE251B008D557C /* TransformerTests.swift in Sources */,
348+
BDD667CC1D1F3572003F94D7 /* Messages.swift in Sources */,
338349
9E455BFA1BCE185B00070A4F /* EnumTests.swift in Sources */,
339350
9E8E07241BD3F15800F98421 /* Food.swift in Sources */,
351+
BD885BBE1D17358E00CA767A /* EncodeNestingTests.swift in Sources */,
340352
9E455C0B1BCE1F0100070A4F /* RegularTests.swift in Sources */,
341353
9E455C051BCE1D0700070A4F /* User.swift in Sources */,
354+
BD885BC01D173A0700CA767A /* PropertyItem.swift in Sources */,
342355
9E455C091BCE1DE100070A4F /* Company.swift in Sources */,
343356
);
344357
runOnlyForDeploymentPostprocessing = 0;
@@ -427,6 +440,7 @@
427440
PRODUCT_NAME = "$(TARGET_NAME)";
428441
SDKROOT = macosx;
429442
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
443+
SWIFT_VERSION = 3.0;
430444
};
431445
name = Debug;
432446
};
@@ -467,6 +481,8 @@
467481
PRODUCT_BUNDLE_IDENTIFIER = com.matthewcheok.JSONCodableTests;
468482
PRODUCT_NAME = "$(TARGET_NAME)";
469483
SDKROOT = macosx;
484+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
485+
SWIFT_VERSION = 3.0;
470486
};
471487
name = Release;
472488
};
@@ -522,6 +538,7 @@
522538
SDKROOT = iphoneos;
523539
SKIP_INSTALL = YES;
524540
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
541+
SWIFT_VERSION = 3.0;
525542
TARGETED_DEVICE_FAMILY = "1,2";
526543
VERSIONING_SYSTEM = "apple-generic";
527544
VERSION_INFO_PREFIX = "";
@@ -573,6 +590,8 @@
573590
PRODUCT_NAME = JSONCodable;
574591
SDKROOT = iphoneos;
575592
SKIP_INSTALL = YES;
593+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
594+
SWIFT_VERSION = 3.0;
576595
TARGETED_DEVICE_FAMILY = "1,2";
577596
VALIDATE_PRODUCT = YES;
578597
VERSIONING_SYSTEM = "apple-generic";
@@ -633,6 +652,7 @@
633652
SDKROOT = macosx;
634653
SKIP_INSTALL = YES;
635654
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
655+
SWIFT_VERSION = 3.0;
636656
VERSIONING_SYSTEM = "apple-generic";
637657
VERSION_INFO_PREFIX = "";
638658
};
@@ -683,6 +703,8 @@
683703
PRODUCT_NAME = JSONCodable;
684704
SDKROOT = macosx;
685705
SKIP_INSTALL = YES;
706+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
707+
SWIFT_VERSION = 3.0;
686708
VERSIONING_SYSTEM = "apple-generic";
687709
VERSION_INFO_PREFIX = "";
688710
};
@@ -691,7 +713,22 @@
691713
9EDF80141B59CFCE00E4A2D6 /* Debug */ = {
692714
isa = XCBuildConfiguration;
693715
buildSettings = {
716+
CLANG_WARN_BOOL_CONVERSION = YES;
717+
CLANG_WARN_CONSTANT_CONVERSION = YES;
718+
CLANG_WARN_EMPTY_BODY = YES;
719+
CLANG_WARN_ENUM_CONVERSION = YES;
720+
CLANG_WARN_INT_CONVERSION = YES;
721+
CLANG_WARN_UNREACHABLE_CODE = YES;
722+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
723+
ENABLE_STRICT_OBJC_MSGSEND = YES;
694724
ENABLE_TESTABILITY = YES;
725+
GCC_NO_COMMON_BLOCKS = YES;
726+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
727+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
728+
GCC_WARN_UNDECLARED_SELECTOR = YES;
729+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
730+
GCC_WARN_UNUSED_FUNCTION = YES;
731+
GCC_WARN_UNUSED_VARIABLE = YES;
695732
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
696733
MACOSX_DEPLOYMENT_TARGET = 10.10;
697734
ONLY_ACTIVE_ARCH = YES;
@@ -701,6 +738,21 @@
701738
9EDF80151B59CFCE00E4A2D6 /* Release */ = {
702739
isa = XCBuildConfiguration;
703740
buildSettings = {
741+
CLANG_WARN_BOOL_CONVERSION = YES;
742+
CLANG_WARN_CONSTANT_CONVERSION = YES;
743+
CLANG_WARN_EMPTY_BODY = YES;
744+
CLANG_WARN_ENUM_CONVERSION = YES;
745+
CLANG_WARN_INT_CONVERSION = YES;
746+
CLANG_WARN_UNREACHABLE_CODE = YES;
747+
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
748+
ENABLE_STRICT_OBJC_MSGSEND = YES;
749+
GCC_NO_COMMON_BLOCKS = YES;
750+
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
751+
GCC_WARN_ABOUT_RETURN_TYPE = YES;
752+
GCC_WARN_UNDECLARED_SELECTOR = YES;
753+
GCC_WARN_UNINITIALIZED_AUTOS = YES;
754+
GCC_WARN_UNUSED_FUNCTION = YES;
755+
GCC_WARN_UNUSED_VARIABLE = YES;
704756
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
705757
MACOSX_DEPLOYMENT_TARGET = 10.10;
706758
};

JSONCodable.xcodeproj/xcshareddata/xcschemes/JSONCodable OSX.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0710"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

JSONCodable.xcodeproj/xcshareddata/xcschemes/JSONCodable iOS.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0710"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

JSONCodable/JSONCodable.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,7 @@ extension Bool: JSONCompatible {}
2121
extension Int: JSONCompatible {}
2222

2323
extension JSONCompatible {
24-
public func toJSON() throws -> AnyObject {
25-
return self as! AnyObject
26-
}
24+
public func toJSON() throws -> Any {
25+
return self
26+
}
2727
}
28-
29-
// Swift 2 Shims
30-
31-
#if !swift(>=3.0)
32-
typealias ErrorProtocol = ErrorType
33-
#endif

0 commit comments

Comments
 (0)