@@ -492,6 +492,7 @@ class SKCodeBuilder: NSObject {
492
492
var tempKey = key
493
493
if allKeys. contains ( key) {
494
494
tempKey = " \( key) 2 "
495
+ self . handlePropertyMapper. setValue ( key, forKey: tempKey)
495
496
}
496
497
allKeys. append ( tempKey)
497
498
return tempKey
@@ -500,16 +501,40 @@ class SKCodeBuilder: NSObject {
500
501
/// 生成类名
501
502
private func modelClassName( with key: String ) -> String {
502
503
if key. isBlank { return config. rootModelName }
503
- let firstCharacterIndex = key. index ( key. startIndex, offsetBy: 1 )
504
- var firstCharacter = String ( key [ ..< firstCharacterIndex] )
505
- firstCharacter = firstCharacter. uppercased ( )
506
- let start = String . Index. init ( utf16Offset: 0 , in: key)
507
- let end = String . Index. init ( utf16Offset: 1 , in: key)
508
- var modelName = key. replacingCharacters ( in: start..< end, with: firstCharacter)
509
-
504
+ let strings = key. components ( separatedBy: " _ " )
505
+ let mutableString = NSMutableString ( )
506
+ var modelName : String
507
+ if !strings. isEmpty {
508
+ for str in strings {
509
+ let firstCharacterIndex = str. index ( str. startIndex, offsetBy: 1 )
510
+ var firstCharacter = String ( str [ ..< firstCharacterIndex] )
511
+ firstCharacter = firstCharacter. uppercased ( )
512
+ let start = String . Index. init ( utf16Offset: 0 , in: str)
513
+ let end = String . Index. init ( utf16Offset: 1 , in: str)
514
+ let str = str. replacingCharacters ( in: start..< end, with: firstCharacter)
515
+ mutableString. append ( str)
516
+ }
517
+ modelName = mutableString as String
518
+ } else {
519
+ let firstCharacterIndex = key. index ( key. startIndex, offsetBy: 1 )
520
+ var firstCharacter = String ( key [ ..< firstCharacterIndex] )
521
+ firstCharacter = firstCharacter. uppercased ( )
522
+ let start = String . Index. init ( utf16Offset: 0 , in: key)
523
+ let end = String . Index. init ( utf16Offset: 1 , in: key)
524
+ modelName = key. replacingCharacters ( in: start..< end, with: firstCharacter)
525
+ }
510
526
if !modelName. hasPrefix ( config. modelNamePrefix) {
511
527
modelName = config. modelNamePrefix + modelName
512
528
}
529
+ if config. superClassName. hasSuffix ( " Item " ) {
530
+ if !modelName. hasSuffix ( " Item " ) {
531
+ modelName = modelName + " Item "
532
+ }
533
+ } else {
534
+ if !modelName. hasSuffix ( " Model " ) {
535
+ modelName = modelName + " Model "
536
+ }
537
+ }
513
538
return modelName
514
539
}
515
540
}
0 commit comments