Skip to content

Commit 5df1eb5

Browse files
committed
style: format code.
1 parent 31233fb commit 5df1eb5

File tree

6 files changed

+31
-54
lines changed

6 files changed

+31
-54
lines changed

SKGenerateModelTool.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@
442442
"@executable_path/../Frameworks",
443443
);
444444
MACOSX_DEPLOYMENT_TARGET = 11.5;
445+
MARKETING_VERSION = 1.2.0;
445446
PRODUCT_BUNDLE_IDENTIFIER = com.Xcoder1011.SKGenerateModelTool;
446447
PRODUCT_NAME = "$(TARGET_NAME)";
447448
SWIFT_OBJC_BRIDGING_HEADER = "SKGenerateModelTool/SKEncryptString/SKGenerateModelTool-Bridging-Header.h";
@@ -464,6 +465,7 @@
464465
"@executable_path/../Frameworks",
465466
);
466467
MACOSX_DEPLOYMENT_TARGET = 11.5;
468+
MARKETING_VERSION = 1.2.0;
467469
PRODUCT_BUNDLE_IDENTIFIER = com.Xcoder1011.SKGenerateModelTool;
468470
PRODUCT_NAME = "$(TARGET_NAME)";
469471
SWIFT_OBJC_BRIDGING_HEADER = "SKGenerateModelTool/SKEncryptString/SKGenerateModelTool-Bridging-Header.h";

SKGenerateModelTool/EncryptionController.swift

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class EncryptionController: NSViewController {
3434

3535
override func viewDidLoad() {
3636
super.viewDidLoad()
37-
3837
configureInitialState()
3938
}
4039

@@ -46,15 +45,13 @@ class EncryptionController: NSViewController {
4645
}
4746
saveUserPreferences()
4847
configJsonTextView(text: inputString, textView: inputTextView, color: inputTextColor)
49-
5048
// 执行加密
5149
let key = useKeyBtn.state == .on ? keyTF.stringValue : nil
5250
encryptAndDisplay(inputString: inputString, key: key)
5351
}
5452

5553
@IBAction func copyCodeString(_ sender: NSButton) {
5654
let stringToCopy: String
57-
5855
switch sender.tag {
5956
case CopyButtonTag.header:
6057
stringToCopy = hTextView.textStorage?.string ?? ""
@@ -63,7 +60,6 @@ class EncryptionController: NSViewController {
6360
default:
6461
return
6562
}
66-
6763
copyToClipboard(string: stringToCopy)
6864
}
6965
}
@@ -73,25 +69,14 @@ class EncryptionController: NSViewController {
7369
private extension EncryptionController {
7470
func configureInitialState() {
7571
useKeyBtn.state = UserDefaults.standard.bool(forKey: UserDefaultsKeys.useKeyBtnState) ? .on : .off
76-
7772
if let key = UserDefaults.standard.string(forKey: UserDefaultsKeys.cipherContent) {
7873
keyTF.stringValue = key
7974
}
80-
81-
/////////////// 使用范例 (Usage Example) /////////////////
82-
83-
// if let string = sk_OCString(_3596508958) {
84-
// print("示例:解密后的数据为:\(string)")
85-
// }
86-
// if let string = sk_OCString(_4038772756) {
87-
// print("The decrypted data is:\(string)")
88-
// }
8975
}
9076

9177
func saveUserPreferences() {
9278
let useKey = useKeyBtn.state == .on
9379
UserDefaults.standard.set(useKey, forKey: UserDefaultsKeys.useKeyBtnState)
94-
9580
if useKey {
9681
UserDefaults.standard.setValue(keyTF.stringValue, forKey: UserDefaultsKeys.cipherContent)
9782
}
@@ -102,10 +87,10 @@ private extension EncryptionController {
10287
guard let self = self else { return }
10388

10489
let headerString = hStr.substring(to: hStr.length)
105-
self.configJsonTextView(text: headerString, textView: self.hTextView, color: self.codeTextColor)
90+
configJsonTextView(text: headerString, textView: self.hTextView, color: self.codeTextColor)
10691

10792
let implementationString = mStr.substring(to: mStr.length)
108-
self.configJsonTextView(text: implementationString, textView: self.mTextView, color: self.codeTextColor)
93+
configJsonTextView(text: implementationString, textView: self.mTextView, color: self.codeTextColor)
10994
}
11095
}
11196

SKGenerateModelTool/SKCodeBuilder/SKCodeBuilder.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ public class SKCodeBuilder {
2121
}
2222

2323
/// 生成文件
24-
func generateFile(with filePath: String?, hString: NSMutableString, mString: NSMutableString, complete: GenerateFileComplete?) {
24+
func generateFile(with filePath: String?,
25+
hString: NSMutableString,
26+
mString: NSMutableString,
27+
complete: GenerateFileComplete?)
28+
{
2529
let fileManager = SKFileManager(config: config)
2630
fileManager.generateFile(with: filePath, hString: hString, mString: mString, complete: complete)
2731
}

SKGenerateModelTool/SKCodeBuilder/SKFileManager.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class SKFileManager {
3131
// MARK: - Public Method
3232

3333
/// 同步生成文件
34-
func generateFile(with filePath: String?, hString: NSMutableString, mString: NSMutableString, complete: GenerateFileComplete?) {
34+
func generateFile(with filePath: String?,
35+
hString: NSMutableString,
36+
mString: NSMutableString,
37+
complete: GenerateFileComplete?)
38+
{
3539
do {
3640
let resultPath = try generateFileSync(with: filePath, hString: hString, mString: mString)
3741
complete?(true, resultPath)
@@ -42,7 +46,10 @@ class SKFileManager {
4246
}
4347

4448
/// 异步生成文件
45-
func generateFileAsync(with filePath: String?, hString: NSMutableString, mString: NSMutableString) async throws -> String {
49+
func generateFileAsync(with filePath: String?,
50+
hString: NSMutableString,
51+
mString: NSMutableString) async throws -> String
52+
{
4653
return try await Task {
4754
try generateFileSync(with: filePath, hString: hString, mString: mString)
4855
}.value
@@ -51,7 +58,10 @@ class SKFileManager {
5158
// MARK: - Private Method
5259

5360
/// 同步生成文件
54-
private func generateFileSync(with filePath: String?, hString: NSMutableString, mString: NSMutableString) throws -> String {
61+
private func generateFileSync(with filePath: String?,
62+
hString: NSMutableString,
63+
mString: NSMutableString) throws -> String
64+
{
5565
guard hString.length > 0, mString.length > 0 else {
5666
throw SKFileError.emptyContent
5767
}
@@ -85,7 +95,10 @@ class SKFileManager {
8595
}
8696

8797
/// 写入文件
88-
private func writeFiles(to filePath: String, hString: NSMutableString, mString: NSMutableString) throws {
98+
private func writeFiles(to filePath: String,
99+
hString: NSMutableString,
100+
mString: NSMutableString) throws
101+
{
89102
let fileName = (config.codeType == .dart) ? config.rootModelName.underscore_name : config.rootModelName
90103

91104
// 根据代码类型确定文件路径

SKGenerateModelTool/SKCodeBuilder/SKModelGenerator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ private extension SKModelGenerator {
7878
}
7979

8080
/// 处理字典值
81-
func handleDictValue(dictValue: Any, key: String, hString: NSMutableString, mString: NSMutableString) {
81+
func handleDictValue(dictValue: Any,
82+
key: String,
83+
hString: NSMutableString,
84+
mString: NSMutableString)
85+
{
8286
// 生成类声明
8387
generateClassDeclaration(dictValue: dictValue, key: key, hString: hString, mString: mString)
8488

SKGenerateModelTool/ViewController.swift

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,13 @@ class ViewController: NSViewController, NSControlTextEditingDelegate {
111111
updateCodeTheme()
112112
var urlString = urlTF.stringValue
113113
guard !urlString.isBlank else { return }
114-
115114
urlString = urlString.urlEncoding()
116115
UserDefaults.standard.setValue(urlString, forKey: CacheKeys.lastInputURL)
117116

118117
guard let url = URL(string: urlString) else {
119118
showAlertInfoWith("无效的URL格式", .warning)
120119
return
121120
}
122-
123121
Task {
124122
do {
125123
let jsonString = try await fetchJsonData(from: url)
@@ -133,24 +131,20 @@ class ViewController: NSViewController, NSControlTextEditingDelegate {
133131
/// 使用async/await获取JSON数据
134132
private func fetchJsonData(from url: URL) async throws -> String {
135133
var request = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 30)
136-
137134
// 处理POST请求
138135
if reqTypeBtn.indexOfSelectedItem == 1 {
139136
request = try configurePostRequest(originalUrl: url)
140137
}
141-
142138
let (data, _) = try await URLSession.shared.data(for: request)
143139
let jsonObj = try JSONSerialization.jsonObject(with: data, options: .mutableContainers)
144140

145141
guard JSONSerialization.isValidJSONObject(jsonObj) else {
146142
throw NSError(domain: "JSONError", code: 1, userInfo: [NSLocalizedDescriptionKey: "无效的JSON响应"])
147143
}
148-
149144
let formatJsonData = try JSONSerialization.data(withJSONObject: jsonObj, options: .prettyPrinted)
150145
guard let jsonString = String(data: formatJsonData, encoding: .utf8) else {
151146
throw NSError(domain: "JSONError", code: 2, userInfo: [NSLocalizedDescriptionKey: "无法将JSON数据转换为字符串"])
152147
}
153-
154148
return jsonString
155149
}
156150

@@ -159,49 +153,40 @@ class ViewController: NSViewController, NSControlTextEditingDelegate {
159153
guard let query = originalUrl.query else {
160154
return URLRequest(url: originalUrl, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 30)
161155
}
162-
163156
let urlString = originalUrl.absoluteString
164157
var urlWithoutQuery = urlString.replacingOccurrences(of: query, with: "")
165158
if urlWithoutQuery.hasSuffix("?") {
166159
urlWithoutQuery.removeLast()
167160
}
168-
169161
guard let newUrl = URL(string: urlWithoutQuery) else {
170162
throw NSError(domain: "URLError", code: 3, userInfo: [NSLocalizedDescriptionKey: "无法创建不带查询参数的URL"])
171163
}
172-
173164
var request = URLRequest(url: newUrl, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 30)
174165
request.httpMethod = "POST"
175166
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
176167
request.httpBody = query.data(using: .utf8)
177-
178168
return request
179169
}
180170

181171
/// 开始生成代码
182172
@IBAction func startMakeCode(_ sender: NSButton) {
183173
guard let jsonString = jsonTextView.textStorage?.string, !jsonString.isBlank else { return }
184-
185174
// 处理JSON字符串
186175
let trimmedStr = jsonString.trimmingCharacters(in: .whitespacesAndNewlines)
187176
let attriStr = NSMutableString(string: trimmedStr)
188-
189177
// 处理注释
190178
var commentDicts: [String: String] = [:]
191179
parseComments(from: trimmedStr, commentDicts: &commentDicts, attriStr: attriStr)
192-
193180
do {
194181
guard let jsonData = attriStr.data(using: String.Encoding.utf8.rawValue) else {
195182
showAlertInfoWith("警告: 请输入有效的JSON字符串!", .warning)
196183
return
197184
}
198-
199185
let jsonObj = try JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers)
200186
guard JSONSerialization.isValidJSONObject(jsonObj) else {
201187
showAlertInfoWith("警告: 不是有效的JSON格式!!!", .warning)
202188
return
203189
}
204-
205190
// 保存用户输入内容并更新主题
206191
saveUserInputContent()
207192
updateCodeTheme()
@@ -216,7 +201,6 @@ class ViewController: NSViewController, NSControlTextEditingDelegate {
216201
configJsonTextView(text: formattedJsonString, textView: jsonTextView, color: NSColor.blue)
217202
}
218203
}
219-
220204
Task {
221205
await generateModelCode(from: jsonObj)
222206
}
@@ -256,7 +240,6 @@ class ViewController: NSViewController, NSControlTextEditingDelegate {
256240

257241
@objc private func caculateInputContentWidth() {
258242
guard let tf = currentInputTF else { return }
259-
260243
let constraints = tf.constraints
261244
let attributes = [NSAttributedString.Key.font: tf.font as Any]
262245
let string = NSString(string: tf.stringValue)
@@ -265,9 +248,7 @@ class ViewController: NSViewController, NSControlTextEditingDelegate {
265248
options: [.usesLineFragmentOrigin, .usesFontLeading],
266249
attributes: attributes
267250
).width + 10
268-
269251
strWidth = max(strWidth, 114)
270-
271252
for constraint in constraints {
272253
if constraint.firstAttribute == .width {
273254
constraint.constant = strWidth
@@ -342,7 +323,6 @@ private extension ViewController {
342323
/// 处理生成的代码
343324
func handleGeneratedCode(_ hString: NSMutableString, _ mString: NSMutableString) {
344325
var multiplier: CGFloat = 3/5.0
345-
346326
switch builder.config.codeType {
347327
case .objectiveC:
348328
configJsonTextView(text: mString as String, textView: mTextView, color: codeTextColor)
@@ -351,7 +331,6 @@ private extension ViewController {
351331
case .dart:
352332
configJsonTextView(text: mString as String, textView: mTextView, color: codeTextColor)
353333
}
354-
355334
hTextViewHeightPriority = modifyConstraint(hTextViewHeightPriority, multiplier)
356335
configJsonTextView(text: hString as String, textView: hTextView, color: codeTextColor)
357336

@@ -414,49 +393,40 @@ private extension ViewController {
414393
if let lastUrl = UserDefaults.standard.string(forKey: CacheKeys.lastInputURL) {
415394
urlTF.stringValue = lastUrl
416395
}
417-
418396
// 父类名或协议名
419397
if let superClassName = UserDefaults.standard.string(forKey: CacheKeys.superClassName) {
420398
superClassNameTF.stringValue = superClassName
421399
}
422-
423400
// 模型名前缀
424401
if let modelNamePrefix = UserDefaults.standard.string(forKey: CacheKeys.modelNamePrefix) {
425402
modelNamePrefixTF.stringValue = modelNamePrefix
426403
}
427-
428404
// 根模型名
429405
if let rootModelName = UserDefaults.standard.string(forKey: CacheKeys.rootModelName) {
430406
rootModelNameTF.stringValue = rootModelName
431407
}
432-
433408
// 作者名
434409
if let authorName = UserDefaults.standard.string(forKey: CacheKeys.authorName) {
435410
authorNameTF.stringValue = authorName
436411
}
437-
438412
// 输出文件路径
439413
if let outFilePath = UserDefaults.standard.string(forKey: CacheKeys.generateFilePath) {
440414
outputFilePath = outFilePath
441415
}
442-
443416
// 代码类型
444417
let codeTypeIndex = UserDefaults.standard.integer(forKey: CacheKeys.buildCodeType)
445418
if codeTypeIndex > 0, codeTypeIndex <= SKCodeType.allCases.count {
446419
builder.config.codeType = SKCodeType.allCases[codeTypeIndex - 1]
447420
codeTypeBtn.selectItem(at: codeTypeIndex - 1)
448421
}
449-
450422
// JSON模型类型
451423
let jsonTypeIndex = UserDefaults.standard.integer(forKey: CacheKeys.supportJSONModelType)
452424
if jsonTypeIndex >= 0, jsonTypeIndex < SKJSONModelType.allCases.count {
453425
builder.config.jsonType = SKJSONModelType.allCases[jsonTypeIndex]
454426
jsonTypeBtn.selectItem(at: jsonTypeIndex)
455427
}
456-
457428
// 是否生成文件
458429
generateFileBtn.state = UserDefaults.standard.bool(forKey: CacheKeys.shouldGenerateFile) ? .on : .off
459-
460430
// 是否生成注释
461431
generateComment.state = UserDefaults.standard.bool(forKey: CacheKeys.shouldGenerateComment) ? .on : .off
462432
}
@@ -469,7 +439,6 @@ private extension ViewController {
469439
builder.config.codeType = SKCodeType.allCases[codeTypeIndex]
470440
UserDefaults.standard.set(codeTypeIndex + 1, forKey: CacheKeys.buildCodeType)
471441
}
472-
473442
// 父类名或协议名
474443
var superClassName = ""
475444
if builder.config.codeType == .dart || builder.config.codeType == .typeScript {

0 commit comments

Comments
 (0)