diff --git a/JSONConverter.xcodeproj/project.pbxproj b/JSONConverter.xcodeproj/project.pbxproj index 18c9bb6..e16a3e0 100644 --- a/JSONConverter.xcodeproj/project.pbxproj +++ b/JSONConverter.xcodeproj/project.pbxproj @@ -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; @@ -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; diff --git a/JSONConverter/Classes/Main/Controller/MainViewController.swift b/JSONConverter/Classes/Main/Controller/MainViewController.swift index f38991b..9eaef86 100644 --- a/JSONConverter/Classes/Main/Controller/MainViewController.swift +++ b/JSONConverter/Classes/Main/Controller/MainViewController.swift @@ -15,6 +15,7 @@ enum LangType: Int { case ObjectMapper case ObjC case Flutter + case Codable } enum StructType: Int { @@ -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 }() @@ -65,7 +66,7 @@ class MainViewController: NSViewController { @IBOutlet var classTextView: NSTextView! override func viewDidLoad() { - super.viewDidLoad() + super.viewDidLoad() setupUI() setupCacheConfigData() checkVerion() @@ -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) } } } diff --git a/JSONConverter/Classes/Main/Model/Content.swift b/JSONConverter/Classes/Main/Model/Content.swift index 0de24de..9d895d8 100644 --- a/JSONConverter/Classes/Main/Model/Content.swift +++ b/JSONConverter/Classes/Main/Model/Content.swift @@ -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 { @@ -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 diff --git a/JSONConverter/Classes/Main/Model/Property.swift b/JSONConverter/Classes/Main/Model/Property.swift index 10187b9..dcb0090 100644 --- a/JSONConverter/Classes/Main/Model/Property.swift +++ b/JSONConverter/Classes/Main/Model/Property.swift @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -149,7 +149,7 @@ class Property { switch langStruct.langType{ case .ObjC: propertyStr = "@property (nonatomic, strong) NSArray *\(propertyKey);\n" - case .Swift, .HandyJSON: + case .Swift, .HandyJSON, .Codable: propertyStr = "\tvar \(propertyKey) = [String]()\n" case .SwiftyJSON: propertyStr = "\tvar \(propertyKey) = [String]()\n" @@ -165,7 +165,7 @@ class Property { switch langStruct.langType{ case .ObjC: propertyStr = "@property (nonatomic, strong) NSArray *\(propertyKey);\n" - case .Swift, .HandyJSON: + case .Swift, .HandyJSON, .Codable: propertyStr = "\tvar \(propertyKey) = [Int]()\n" case .SwiftyJSON: propertyStr = "\tvar \(propertyKey) = [Int]()\n" @@ -181,7 +181,7 @@ class Property { switch langStruct.langType{ case .ObjC: propertyStr = "@property (nonatomic, strong) NSArray *\(propertyKey);\n" - case .Swift, .HandyJSON: + case .Swift, .HandyJSON, .Codable: propertyStr = "\tvar \(propertyKey) = [Float]()\n" case .SwiftyJSON: propertyStr = "\tvar \(propertyKey) = [Float]()\n" @@ -197,7 +197,7 @@ class Property { switch langStruct.langType{ case .ObjC: propertyStr = "@property (nonatomic, strong) NSArray *\(propertyKey);\n" - case .Swift, .HandyJSON: + case .Swift, .HandyJSON, .Codable: propertyStr = "\tvar \(propertyKey) = [Double]()\n" case .SwiftyJSON: propertyStr = "\tvar \(propertyKey) = [Double]()\n" @@ -213,7 +213,7 @@ class Property { switch langStruct.langType{ case .ObjC: propertyStr = "@property (nonatomic, strong) NSArray *\(propertyKey);\n" - case .Swift, .HandyJSON: + case .Swift, .HandyJSON, .Codable: propertyStr = "\tvar \(propertyKey) = [Bool]()\n" case .SwiftyJSON: propertyStr = "\tvar \(propertyKey) = [Bool]()\n" @@ -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" @@ -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" diff --git a/README.md b/README.md index e0ef896..fa68a99 100755 --- a/README.md +++ b/README.md @@ -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 对应的模型转化 * 版本更新自动提醒 * 转换配置缓存,默认保存上一次转换的配置,无需每次转换都要选择对应的语言和类型 * 黑暗模式