Skip to content

Commit 9dec070

Browse files
author
Karthikeya Udupa KM
committed
Merge pull request #2 from brendan09/master
Make NSCoding / SwiftyJSON optional, add ObjectMapper, add specific numerical types.
2 parents 172b078 + f671532 commit 9dec070

File tree

8 files changed

+325
-71
lines changed

8 files changed

+325
-71
lines changed

SwiftyJSONAccelerator.xcodeproj/project.pbxproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
93F1744A1BD0707D007E7DFC /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 93F174481BD0707D007E7DFC /* Main.storyboard */; };
2121
93F174551BD0707D007E7DFC /* SwiftyJSONAcceleratorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F174541BD0707D007E7DFC /* SwiftyJSONAcceleratorTests.swift */; };
2222
93F174601BD070AA007E7DFC /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F1745F1BD070AA007E7DFC /* JSONHelper.swift */; };
23+
C667011B1BDCABCE009BA254 /* SwiftyJSONTemplate.txt in Resources */ = {isa = PBXBuildFile; fileRef = C667011A1BDCABCE009BA254 /* SwiftyJSONTemplate.txt */; };
24+
C667011D1BDCAF23009BA254 /* ObjectMapperTemplate.txt in Resources */ = {isa = PBXBuildFile; fileRef = C667011C1BDCAF23009BA254 /* ObjectMapperTemplate.txt */; };
25+
C667011F1BDCBE1F009BA254 /* NSCodingTemplate.txt in Resources */ = {isa = PBXBuildFile; fileRef = C667011E1BDCBE1F009BA254 /* NSCodingTemplate.txt */; };
2326
/* End PBXBuildFile section */
2427

2528
/* Begin PBXContainerItemProxy section */
@@ -49,6 +52,9 @@
4952
93F174541BD0707D007E7DFC /* SwiftyJSONAcceleratorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftyJSONAcceleratorTests.swift; sourceTree = "<group>"; };
5053
93F174561BD0707D007E7DFC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5154
93F1745F1BD070AA007E7DFC /* JSONHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = "<group>"; };
55+
C667011A1BDCABCE009BA254 /* SwiftyJSONTemplate.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SwiftyJSONTemplate.txt; sourceTree = "<group>"; };
56+
C667011C1BDCAF23009BA254 /* ObjectMapperTemplate.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ObjectMapperTemplate.txt; sourceTree = "<group>"; };
57+
C667011E1BDCBE1F009BA254 /* NSCodingTemplate.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = NSCodingTemplate.txt; sourceTree = "<group>"; };
5258
/* End PBXFileReference section */
5359

5460
/* Begin PBXFrameworksBuildPhase section */
@@ -73,6 +79,9 @@
7379
isa = PBXGroup;
7480
children = (
7581
9341A14E1BD6E7290048CE2C /* BaseTemplate.txt */,
82+
C667011A1BDCABCE009BA254 /* SwiftyJSONTemplate.txt */,
83+
C667011C1BDCAF23009BA254 /* ObjectMapperTemplate.txt */,
84+
C667011E1BDCBE1F009BA254 /* NSCodingTemplate.txt */,
7685
);
7786
path = "Base Files";
7887
sourceTree = "<group>";
@@ -228,7 +237,10 @@
228237
isa = PBXResourcesBuildPhase;
229238
buildActionMask = 2147483647;
230239
files = (
240+
C667011B1BDCABCE009BA254 /* SwiftyJSONTemplate.txt in Resources */,
241+
C667011F1BDCBE1F009BA254 /* NSCodingTemplate.txt in Resources */,
231242
93F174471BD0707D007E7DFC /* Assets.xcassets in Resources */,
243+
C667011D1BDCAF23009BA254 /* ObjectMapperTemplate.txt in Resources */,
232244
9341A14F1BD6E7290048CE2C /* BaseTemplate.txt in Resources */,
233245
93F1744A1BD0707D007E7DFC /* Main.storyboard in Resources */,
234246
);

SwiftyJSONAccelerator/Base Files/BaseTemplate.txt

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,33 @@
55
// Copyright (c) __MyCompanyName__. All rights reserved.
66
//
77

8-
import Foundation{INCLUDE_SWIFTY}
8+
import Foundation{INCLUDE_SWIFTY}{INCLUDE_OBJECT_MAPPER}
99

10-
public {OBJECT_KIND} {OBJECT_NAME}: NSObject, NSCoding {
10+
public {OBJECT_KIND} {OBJECT_NAME}: {OBJECT_BASE_CLASS}{NSCODING_PROTOCOL_SUPPORT} {
1111

12-
// MARK: Declaration for string constants to be used to decode and also serialize.
12+
// MARK: Declaration for string constants to be used to decode and also serialize.
1313
{STRING_CONSTANT_BLOCK}
1414

15-
// MARK: Properties
15+
// MARK: Properties
1616
{PROPERTIES}
1717

18-
// MARK: Initalizers
19-
/**
20-
Initates the class based on the object
21-
- parameter object: The object of either Dictionary or Array kind that was passed.
22-
- returns: An initalized instance of the class.
23-
*/
24-
convenience public init(object: AnyObject) {
25-
self.init(json: JSON(object))
26-
}
18+
// MARK: Initalizers
19+
{SWIFTY_JSON_SUPPORT}
2720

28-
/**
29-
Initates the class based on the JSON that was passed.
30-
- parameter json: JSON object from SwiftyJSON.
31-
- returns: An initalized instance of the class.
32-
*/
33-
public init(json: JSON) {
34-
{INITALIZER}
35-
}
21+
{OBJECT_MAPPER_SUPPORT}
3622

3723
/**
3824
Generates description of the object in the form of a NSDictionary.
3925
- returns: A Key value pair containing all valid values in the object.
4026
*/
4127
public func dictionaryRepresentation() -> [String : AnyObject ] {
4228

43-
var dictionary: [String : AnyObject ] = [ : ]
29+
var dictionary: [String : AnyObject ] = [ : ]
4430
{DESC}
4531

46-
return dictionary
47-
}
48-
49-
// MARK: NSCoding Protocol
50-
required public init(coder aDecoder: NSCoder) {
51-
{DECODERS}
32+
return dictionary
5233
}
5334

54-
public func encodeWithCoder(aCoder: NSCoder) {
55-
{ENCODERS}
56-
}
35+
{NSCODING_SUPPORT}
5736

5837
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// MARK: NSCoding Protocol
2+
required public init(coder aDecoder: NSCoder) {
3+
{DECODERS}
4+
}
5+
6+
public func encodeWithCoder(aCoder: NSCoder) {
7+
{ENCODERS}
8+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
Map a JSON object to this class using ObjectMapper
3+
- parameter map: A mapping from ObjectMapper
4+
*/
5+
required init?(_ map: Map){
6+
7+
}
8+
9+
/**
10+
Map a JSON object to this class using ObjectMapper
11+
- parameter map: A mapping from ObjectMapper
12+
*/
13+
func mapping(map: Map) {
14+
{OBJECT_MAPPER_INITIALIZER}
15+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
Initates the class based on the object
3+
- parameter object: The object of either Dictionary or Array kind that was passed.
4+
- returns: An initalized instance of the class.
5+
*/
6+
convenience public init(object: AnyObject) {
7+
self.init(json: JSON(object))
8+
}
9+
10+
/**
11+
Initates the class based on the JSON that was passed.
12+
- parameter json: JSON object from SwiftyJSON.
13+
- returns: An initalized instance of the class.
14+
*/
15+
public init(json: JSON) {
16+
{INITALIZER}
17+
}

0 commit comments

Comments
 (0)