We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
`import Foundation
class DefaultCodableBuilder: BuilderProtocol { func isMatchLang(_ lang: LangType) -> Bool { return lang == .DefualtCodable }
func propertyText(_ type: PropertyType, keyName: String, strategy: PropertyStrategy, maxKeyNameLength: Int, typeName: String?) -> String { assert(!((type == .Dictionary || type == .ArrayDictionary) && typeName == nil), " Dictionary type the typeName can not be nil") let tempKeyName = strategy.processed(keyName) var str = "" switch type { case .String, .Null: str = "\t<String> var \(tempKeyName): String\n" case .Int: str = "\t<Int> var \(tempKeyName): Int\n" case .Float: str = "\t<Float> var \(tempKeyName): Float\n" case .Double: str = "\t<Double> var \(tempKeyName): Double\n" case .Bool: str = "\t<Bool> var \(tempKeyName): Bool\n" case .Dictionary: str = "\t<\(typeName!)> var \(tempKeyName): \(typeName!)\n" case .ArrayString, .ArrayNull: str = "\t<Array> var \(tempKeyName): [String]\n" case .ArrayInt: str = "\t<Array> var \(tempKeyName): [Int]\n" case .ArrayFloat: str = "\t<Array> var \(tempKeyName): [Float]\n" case .ArrayDouble: str = "\t<Array> var \(tempKeyName): [Double]\n" case .ArrayBool: str = "\t<Array> var \(tempKeyName): [Bool]\n" case .ArrayDictionary: str = "\t<Array> var \(tempKeyName): [\(typeName!)]\n" } str.insert(contentsOf: "@Default", at: str.index(str.startIndex, offsetBy: 1)) str.insert(contentsOf: " = .defaultValue", at: str.index(str.endIndex, offsetBy: -1)) return str } func contentParentClassText(_ clsText: String?) -> String { return StringUtils.isEmpty(clsText) ? ": Codable" : ": \(clsText!)" } func contentText(_ structType: StructType, clsName: String, parentClsName: String, propertiesText: inout String, propertiesInitText: inout String?, propertiesGetterSetterText: inout String?) -> String { if structType == .class { return "\nclass \(clsName)\(parentClsName), DefaultValue {\n\(propertiesText)\n\tstatic let defaultValue = \(clsName)()\n\trequired init() {}\n}\n" } else { propertiesText.removeLastChar() return "\nstruct \(clsName)\(parentClsName), DefaultValue {\n\(propertiesText)\n\tstatic let defaultValue = \(clsName)(\(propertiesInitText!.substring(from: 2)))\n}\n" } } func fileExtension() -> String { return "swift" } func fileImportText(_ rootName: String, contents: [Content], strategy: PropertyStrategy, prefix: String?) -> String { return"\nimport Foundation\n" }
}` Codable设置默认值
The text was updated successfully, but these errors were encountered:
看了你写的文章,非常👍🏻,建议可以吧 @default 和 .defaultValue 在设置页面写成可配置项,欢迎提交一个pr!
Sorry, something went wrong.
这个默认值功能添加了嘛大佬 ^V^
No branches or pull requests
`import Foundation
class DefaultCodableBuilder: BuilderProtocol {
func isMatchLang(_ lang: LangType) -> Bool {
return lang == .DefualtCodable
}
}`
Codable设置默认值
The text was updated successfully, but these errors were encountered: