@@ -197,7 +197,7 @@ public class ModelGenerator {
197197
198198 if self . supportNSCoding! {
199199 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 " )
201201 content = content. stringByReplacingOccurrencesOfString ( " {NSCODING_SUPPORT} " , withString: nscodingBase)
202202
203203 content = content. stringByReplacingOccurrencesOfString ( " {ENCODERS} " , withString: encoders)
@@ -318,7 +318,7 @@ public class ModelGenerator {
318318 - returns: A generated string representation of the variable name.
319319 */
320320 internal func variableNameBuilder( variableName: String ) -> String {
321- var variableName = replaceInternalKeywordsForVariableName ( variableName) . stringByReplacingOccurrencesOfString ( " _ " , withString : " " )
321+ var variableName = replaceSeperatorsWithSpace ( replaceInternalKeywordsForVariableName ( variableName) )
322322 variableName = variableName. stringByTrimmingCharactersInSet ( NSCharacterSet . whitespaceAndNewlineCharacterSet ( ) )
323323 var finalVariableName : String = " "
324324 for (index, element) in variableName. componentsSeparatedByString ( " " ) . enumerate ( ) {
@@ -335,6 +335,13 @@ public class ModelGenerator {
335335
336336 }
337337
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+
338345 /**
339346 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.
340347
@@ -343,9 +350,10 @@ public class ModelGenerator {
343350
344351 - returns: A generated string that can be used to store the key of the variable in the JSON.
345352 */
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 "
349357 }
350358
351359 /**
@@ -445,9 +453,9 @@ public class ModelGenerator {
445453 - parameter key: Key against which the value is stored.
446454 - returns: A single line declaration of the variable which is an array of primitive kind.
447455 */
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 } "
451459 }
452460
453461 //MARK: Encoders and Decoder Generators
@@ -648,9 +656,10 @@ public class ModelGenerator {
648656 - parameter type: VariableType
649657 - returns: swift variable type.
650658 */
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
654663 }
655664
656665
0 commit comments