@@ -197,7 +197,7 @@ public class ModelGenerator {
197
197
198
198
if self . supportNSCoding! {
199
199
if let nscodingBase = try ? String ( contentsOfFile: NSBundle . mainBundle ( ) . pathForResource ( " NSCodingTemplate " , ofType: " txt " ) !) {
200
- content = content. stringByReplacingOccurrencesOfString ( " {NSCODING_PROTOCOL_SUPPORT} " , withString: " , NSCoding, NSObject " )
200
+ content = content. stringByReplacingOccurrencesOfString ( " {NSCODING_PROTOCOL_SUPPORT} " , withString: " , NSCoding " )
201
201
content = content. stringByReplacingOccurrencesOfString ( " {NSCODING_SUPPORT} " , withString: nscodingBase)
202
202
203
203
content = content. stringByReplacingOccurrencesOfString ( " {ENCODERS} " , withString: encoders)
@@ -318,7 +318,7 @@ public class ModelGenerator {
318
318
- returns: A generated string representation of the variable name.
319
319
*/
320
320
internal func variableNameBuilder( variableName: String ) -> String {
321
- var variableName = replaceInternalKeywordsForVariableName ( variableName) . stringByReplacingOccurrencesOfString ( " _ " , withString : " " )
321
+ var variableName = replaceSeperatorsWithSpace ( replaceInternalKeywordsForVariableName ( variableName) )
322
322
variableName = variableName. stringByTrimmingCharactersInSet ( NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) )
323
323
var finalVariableName : String = " "
324
324
for (index, element) in variableName. componentsSeparatedByString ( " " ) . enumerate ( ) {
@@ -335,6 +335,13 @@ public class ModelGenerator {
335
335
336
336
}
337
337
338
+ /**
339
+ Replaces the seperator characters between words with space.
340
+ */
341
+ internal func replaceSeperatorsWithSpace( variableName: String ) -> String {
342
+ return variableName. stringByReplacingOccurrencesOfString ( " _ " , withString: " " ) . stringByReplacingOccurrencesOfString ( " - " , withString: " " )
343
+ }
344
+
338
345
/**
339
346
Generate a variable name to store the key of the variable in the JSON for later use (generating JSON file, encoding and decoding). the format is k{ClassName}{VariableName}Key.
340
347
@@ -343,9 +350,10 @@ public class ModelGenerator {
343
350
344
351
- returns: A generated string that can be used to store the key of the variable in the JSON.
345
352
*/
346
- internal func variableNameKeyBuilder( className: String , var variableName: String ) -> String {
347
- variableName. replaceRange ( variableName. startIndex... variableName. startIndex, with: String ( variableName [ variableName. startIndex] ) . uppercaseString)
348
- return " k \( className) \( variableName) Key "
353
+ internal func variableNameKeyBuilder( className: String , variableName: String ) -> String {
354
+ var _variableName = variableName
355
+ _variableName. replaceRange ( variableName. startIndex... variableName. startIndex, with: String ( variableName [ variableName. startIndex] ) . uppercaseString)
356
+ return " k \( className) \( _variableName) Key "
349
357
}
350
358
351
359
/**
@@ -445,9 +453,9 @@ public class ModelGenerator {
445
453
- parameter key: Key against which the value is stored.
446
454
- returns: A single line declaration of the variable which is an array of primitive kind.
447
455
*/
448
- internal func initalizerForPrimitiveVariableArray( variableName: String , key: String , var type: String ) -> String {
449
- type = typeToSwiftType ( type)
450
- return " \t \t \( variableName) = [] \n \t \t if let items = json[ \( key) ].array { \n \t \t \t for item in items { \n \t \t \t \t if let tempValue = item. \( type ) { \n \t \t \t \t \( variableName) ?.append(tempValue) \n \t \t \t \t } \n \t \t \t } \n \t \t } else { \n \t \t \t \( variableName) = nil \n \t \t } "
456
+ internal func initalizerForPrimitiveVariableArray( variableName: String , key: String , type: String ) -> String {
457
+ let _type = typeToSwiftType ( type)
458
+ return " \t \t \( variableName) = [] \n \t \t if let items = json[ \( key) ].array { \n \t \t \t for item in items { \n \t \t \t \t if let tempValue = item. \( _type ) { \n \t \t \t \t \( variableName) ?.append(tempValue) \n \t \t \t \t } \n \t \t \t } \n \t \t } else { \n \t \t \t \( variableName) = nil \n \t \t } "
451
459
}
452
460
453
461
//MARK: Encoders and Decoder Generators
@@ -648,9 +656,10 @@ public class ModelGenerator {
648
656
- parameter type: VariableType
649
657
- returns: swift variable type.
650
658
*/
651
- internal func typeToSwiftType( var type: String ) -> String {
652
- type. replaceRange ( type. startIndex... type. startIndex, with: String ( type [ type. startIndex] ) . lowercaseString)
653
- return type
659
+ internal func typeToSwiftType( type: String ) -> String {
660
+ var _type = type
661
+ _type. replaceRange ( type. startIndex... type. startIndex, with: String ( type [ type. startIndex] ) . lowercaseString)
662
+ return _type
654
663
}
655
664
656
665
0 commit comments