Skip to content

Commit d816607

Browse files
committed
Move NSCoding to template file.
1 parent 8d395a7 commit d816607

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

SwiftyJSONAccelerator.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
93F174601BD070AA007E7DFC /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 93F1745F1BD070AA007E7DFC /* JSONHelper.swift */; };
2323
C667011B1BDCABCE009BA254 /* SwiftyJSONTemplate.txt in Resources */ = {isa = PBXBuildFile; fileRef = C667011A1BDCABCE009BA254 /* SwiftyJSONTemplate.txt */; };
2424
C667011D1BDCAF23009BA254 /* ObjectMapperTemplate.txt in Resources */ = {isa = PBXBuildFile; fileRef = C667011C1BDCAF23009BA254 /* ObjectMapperTemplate.txt */; };
25+
C667011F1BDCBE1F009BA254 /* NSCodingTemplate.txt in Resources */ = {isa = PBXBuildFile; fileRef = C667011E1BDCBE1F009BA254 /* NSCodingTemplate.txt */; };
2526
/* End PBXBuildFile section */
2627

2728
/* Begin PBXContainerItemProxy section */
@@ -53,6 +54,7 @@
5354
93F1745F1BD070AA007E7DFC /* JSONHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = JSONHelper.swift; sourceTree = "<group>"; };
5455
C667011A1BDCABCE009BA254 /* SwiftyJSONTemplate.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SwiftyJSONTemplate.txt; sourceTree = "<group>"; };
5556
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>"; };
5658
/* End PBXFileReference section */
5759

5860
/* Begin PBXFrameworksBuildPhase section */
@@ -79,6 +81,7 @@
7981
9341A14E1BD6E7290048CE2C /* BaseTemplate.txt */,
8082
C667011A1BDCABCE009BA254 /* SwiftyJSONTemplate.txt */,
8183
C667011C1BDCAF23009BA254 /* ObjectMapperTemplate.txt */,
84+
C667011E1BDCBE1F009BA254 /* NSCodingTemplate.txt */,
8285
);
8386
path = "Base Files";
8487
sourceTree = "<group>";
@@ -235,6 +238,7 @@
235238
buildActionMask = 2147483647;
236239
files = (
237240
C667011B1BDCABCE009BA254 /* SwiftyJSONTemplate.txt in Resources */,
241+
C667011F1BDCBE1F009BA254 /* NSCodingTemplate.txt in Resources */,
238242
93F174471BD0707D007E7DFC /* Assets.xcassets in Resources */,
239243
C667011D1BDCAF23009BA254 /* ObjectMapperTemplate.txt in Resources */,
240244
9341A14F1BD6E7290048CE2C /* BaseTemplate.txt in Resources */,
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+
}

SwiftyJSONAccelerator/SJModelGenerator.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,19 @@ public class ModelGenerator {
214214

215215
if self.supportNSCoding
216216
{
217-
content = content.stringByReplacingOccurrencesOfString("{NSCODING_PROTOCOL_SUPPORT}", withString: ", NSCoding")
218-
content = content.stringByReplacingOccurrencesOfString("{NSCODING_SUPPORT}", withString: "\t// MARK: NSCoding Protocol\n\trequired public init(coder aDecoder: NSCoder) {\n\t{DECODERS}\n\t}\n\n\tpublic func encodeWithCoder(aCoder: NSCoder) {\n{ENCODERS}\n\t}")
217+
if let nscodingBase = try? String(contentsOfFile: NSBundle.mainBundle().pathForResource("NSCodingTemplate", ofType: "txt")!)
218+
{
219+
content = content.stringByReplacingOccurrencesOfString("{NSCODING_PROTOCOL_SUPPORT}", withString: ", NSCoding")
220+
content = content.stringByReplacingOccurrencesOfString("{NSCODING_SUPPORT}", withString: nscodingBase)
219221

220-
content = content.stringByReplacingOccurrencesOfString("{ENCODERS}", withString: encoders)
221-
content = content.stringByReplacingOccurrencesOfString("{DECODERS}", withString: decoders)
222+
content = content.stringByReplacingOccurrencesOfString("{ENCODERS}", withString: encoders)
223+
content = content.stringByReplacingOccurrencesOfString("{DECODERS}", withString: decoders)
224+
}
225+
else
226+
{
227+
content = content.stringByReplacingOccurrencesOfString("{NSCODING_PROTOCOL_SUPPORT}", withString: "")
228+
content = content.stringByReplacingOccurrencesOfString("{NSCODING_SUPPORT}", withString: "")
229+
}
222230
}
223231
else
224232
{

0 commit comments

Comments
 (0)