Skip to content

Commit

Permalink
Merge pull request #11 from weixianlove/master
Browse files Browse the repository at this point in the history
新增Swift Codable支持
  • Loading branch information
vvkeep authored Jan 20, 2020
2 parents 7d30270 + 73f928d commit 0d0d6a5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions JSONConverter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@
CODE_SIGN_ENTITLEMENTS = JSONConverter/JSONConverter.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 7DDW7FQJ8R;
DEVELOPMENT_TEAM = P3PPL3J2AK;
INFOPLIST_FILE = JSONConverter/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
Expand All @@ -549,7 +549,7 @@
CODE_SIGN_ENTITLEMENTS = JSONConverter/JSONConverter.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 7DDW7FQJ8R;
DEVELOPMENT_TEAM = P3PPL3J2AK;
INFOPLIST_FILE = JSONConverter/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 10.10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ enum LangType: Int {
case ObjectMapper
case ObjC
case Flutter
case Codable
}

enum StructType: Int {
Expand All @@ -37,7 +38,7 @@ let FILE_CACHE_CONFIG_KEY = "FILE_CACHE_CONFIG_KEY"
class MainViewController: NSViewController {

lazy var transTypeTitleArr: [String] = {
let titleArr = ["Swift", "HandyJSON", "SwiftyJSON", "ObjectMapper", "Objective-C", "Flutter"]
let titleArr = ["Swift", "HandyJSON", "SwiftyJSON", "ObjectMapper", "Objective-C", "Flutter", "Codable"]
return titleArr
}()

Expand Down Expand Up @@ -65,7 +66,7 @@ class MainViewController: NSViewController {
@IBOutlet var classTextView: NSTextView!

override func viewDidLoad() {
super.viewDidLoad()
super.viewDidLoad()
setupUI()
setupCacheConfigData()
checkVerion()
Expand Down Expand Up @@ -211,11 +212,15 @@ extension MainViewController: NSComboBoxDelegate {
let langType = LangType(rawValue: converTypeBox.indexOfSelectedItem)
if langType == LangType.ObjC || langType == LangType.Flutter { // 如果是OC Flutter 就选择 class
converStructBox.selectItem(at: 1)
} else if langType == LangType.Codable {//如果是Codable 就选择 struct
converStructBox.selectItem(at: 0)
}
}else if comBox == converStructBox { //选择类或结构体
let langType = LangType(rawValue: converTypeBox.indexOfSelectedItem)
if langType == LangType.ObjC || langType == LangType.Flutter { // 如果是OC Flutter 无论怎么选 都是 类
converStructBox.selectItem(at: 1)
} else if langType == LangType.Codable {//如果是Codable 就选择 struct
converStructBox.selectItem(at: 0)
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion JSONConverter/Classes/Main/Model/Content.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Content {
}else if langStruct.structType == .struct {
contentStr = "\nstruct \(className)\(superClassNamePart()) {\n\(propertyTotalPart)\n}\n"
}
case .HandyJSON:
case .HandyJSON, .Codable:
if langStruct.structType == .class {
contentStr = "\nclass \(className)\(superClassNamePart()) {\n\(propertyTotalPart)\n\trequired init() {}\n}\n"
}else if langStruct.structType == .struct {
Expand Down Expand Up @@ -98,6 +98,8 @@ class Content {
superClassPart = superClass.isEmpty ? ": Mappable" : ": \(superClass)"
case .Flutter:
superClassPart = superClass.isEmpty ? " extends Object" : " extends \(superClass)"
case .Codable:
superClassPart = superClass.isEmpty ? ": Codable" : ": \(superClass)"
}

return superClassPart
Expand Down
26 changes: 13 additions & 13 deletions JSONConverter/Classes/Main/Model/Property.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, copy) NSString *\(propertyKey);\n"
case .Swift,.HandyJSON:
case .Swift,.HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey): String?\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey): String?\n"
Expand All @@ -69,7 +69,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, assign) NSInteger \(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey): Int = 0\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey): Int = 0\n"
Expand All @@ -85,7 +85,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, assign) Float \(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey): Float = 0.0\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey): Float = 0.0\n"
Expand All @@ -101,7 +101,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, assign) Double \(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey): Double = 0.0\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey): Double = 0.0\n"
Expand All @@ -117,7 +117,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, assign) BOOL \(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey): Bool = false\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey): Bool = false\n"
Expand All @@ -133,7 +133,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, strong) \(propertyKey.className(withPrefix: prefixStr)) *\(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey): \(propertyKey.className(withPrefix: prefixStr))?\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey): \(propertyKey.className(withPrefix: prefixStr))?\n"
Expand All @@ -149,7 +149,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, strong) NSArray<NSString *> *\(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey) = [String]()\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey) = [String]()\n"
Expand All @@ -165,7 +165,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, strong) NSArray<Int> *\(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey) = [Int]()\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey) = [Int]()\n"
Expand All @@ -181,7 +181,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, strong) NSArray<Float> *\(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey) = [Float]()\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey) = [Float]()\n"
Expand All @@ -197,7 +197,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, strong) NSArray<Double> *\(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey) = [Double]()\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey) = [Double]()\n"
Expand All @@ -213,7 +213,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, strong) NSArray<Bool> *\(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey) = [Bool]()\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey) = [Bool]()\n"
Expand All @@ -229,7 +229,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, strong) NSArray<\(propertyKey.className(withPrefix: prefixStr)) *> *\(propertyKey);\n"
case .Swift, .HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey) = [\(propertyKey.className(withPrefix: prefixStr))]()\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey) = [\(propertyKey.className(withPrefix: prefixStr))]()\n"
Expand All @@ -245,7 +245,7 @@ class Property {
switch langStruct.langType{
case .ObjC:
propertyStr = "@property (nonatomic, copy) NSString *\(propertyKey);\n"
case .Swift,.HandyJSON:
case .Swift, .HandyJSON, .Codable:
propertyStr = "\tvar \(propertyKey): String?\n"
case .SwiftyJSON:
propertyStr = "\tvar \(propertyKey): String?\n"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ JSONConverter 是MAC上iOS开发的辅助小工具,可以快速的把json数

支持的功能
========================
* Objective-C、Swift(Codeable, SwiftyJSON, HandyJSON, ObjectMapper)、Flutter 对应的模型转化
* Objective-C、Swift(Codeable, SwiftyJSON, HandyJSON, ObjectMapper,Codable)、Flutter 对应的模型转化
* 版本更新自动提醒
* 转换配置缓存,默认保存上一次转换的配置,无需每次转换都要选择对应的语言和类型
* 黑暗模式
Expand Down

0 comments on commit 0d0d6a5

Please sign in to comment.