Skip to content

Commit 6931719

Browse files
author
Sven
committed
update: 细节调整。
1 parent 4a1bcac commit 6931719

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

SwiftJSONModeler For Xcode.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
C92A971E24E5150600C87CCD /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = C92A971C24E514FB00C87CCD /* Constants.swift */; };
1818
C935B49C24EA24BE00E48231 /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C935B49B24EA24BE00E48231 /* JSONHelper.swift */; };
1919
C935B49E24EA56EF00E48231 /* JSONHelperTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C935B49D24EA56EF00E48231 /* JSONHelperTest.swift */; };
20+
C935B49F24EA664A00E48231 /* JSONHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C935B49B24EA24BE00E48231 /* JSONHelper.swift */; };
2021
C94AFC01241F4AE600389AF3 /* YApiHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC00241F4AE600389AF3 /* YApiHelper.swift */; };
2122
C94AFC04241F4E8A00389AF3 /* YApiObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = C94AFC03241F4E8A00389AF3 /* YApiObject.swift */; };
2223
C961C1DE23D82A8D008D0DE6 /* ConfigViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C961C1DD23D82A8D008D0DE6 /* ConfigViewController.swift */; };
@@ -387,6 +388,7 @@
387388
C9ED9CE323D7F9D0004567A1 /* SourceEditorCommand.swift in Sources */,
388389
C9CEE26D242B382900A04EA9 /* YApiCreator.swift in Sources */,
389390
C92A971E24E5150600C87CCD /* Constants.swift in Sources */,
391+
C935B49F24EA664A00E48231 /* JSONHelper.swift in Sources */,
390392
);
391393
runOnlyForDeploymentPostprocessing = 0;
392394
};

SwiftJSONModeler For Xcode/JSONHelper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public struct JSONHelper {
5454
let arrObjct = YApiObject(parentKey: key, key: key, mock: "", type: type, typeRaw: "Array", des: nil, childs: [objct])
5555
return arrObjct
5656
}
57-
let arrObjct = YApiObject(parentKey: nil, key: key, mock: "", type: type, typeRaw: "Array", des: nil, childs: [typeOf(nil, value: first)])
57+
let arrObjct = YApiObject(parentKey: key, key: key, mock: "", type: type, typeRaw: "Array", des: nil, childs: [typeOf(key, value: first)])
5858
return arrObjct
5959
}
6060
/// 类型数据类型判断
@@ -63,7 +63,7 @@ public struct JSONHelper {
6363
if value is NSNull {
6464
print("存在null")
6565
let type = YApiType.undefined
66-
let objct = YApiObject(parentKey: parentKey, key: key, mock: "", type: type, typeRaw: "<#NSNull#>", des: nil, childs: [])
66+
let objct = YApiObject(parentKey: parentKey, key: key, mock: "", type: type, typeRaw: "NSNull", des: nil, childs: [])
6767
return objct
6868
} else if value is String {
6969
let type = YApiType.string

SwiftJSONModeler For Xcode/YApi/YApiCreator.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ class YApiCreator {
4646
getPathObject()
4747
}
4848

49+
init(invocation: XCSourceEditorCommandInvocation, yapiObject: YApiObject) {
50+
self.invocation = invocation
51+
self.creatObjects.insert(yapiObject)
52+
let buffer = invocation.buffer
53+
lines = buffer.lines
54+
lineObject(self.creatObjects.first!)
55+
}
56+
4957
private func getPathObject() -> Void {
5058
objectHelper.aimPath = Config().yapiPath //设置获取data下数据
5159
guard let object = objectHelper.pathObject else {

SwiftJSONModeler/SourceEditorCommand.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
3939
handleInvocation(invocation, raw: pasteboardTest, completionHandler: completionHandler)
4040

4141
} else if commandIdentifier == classFromJSONCommand || commandIdentifier == structFromJSONCommand {
42-
handleInvocation(invocation, handler: completionHandler)
42+
handleInvocation(invocation, json: pasteboardTest, completionHandler: completionHandler)
43+
//handleInvocation(invocation, handler: completionHandler)
4344
} else if commandIdentifier == classFromYApiIdCommand || commandIdentifier == structFromYApiIdCommand {
4445
YApiRequest.data(id: pasteboardTest) { [weak self](raw) in
4546
if let raw = raw {
@@ -60,7 +61,24 @@ class SourceEditorCommand: NSObject, XCSourceEditorCommand {
6061
completionHandler(nil)
6162
}
6263
/// 通过json 转模
64+
private func handleInvocation(_ invocation: XCSourceEditorCommandInvocation, json: String, completionHandler: @escaping (Error?) -> Void) {
65+
guard let transformObject = JSONHelper(paste: json).transform() else {
66+
completionHandler(nil)
67+
return
68+
}
69+
let yapiCreator = YApiCreator(invocation: invocation,
70+
yapiObject: transformObject)
71+
let models = yapiCreator.getModels()
72+
var lines = invocation.buffer.lines
73+
lines.addObjects(from: models)
74+
importModel(lines: &lines)
75+
completionHandler(nil)
76+
}
77+
78+
6379
private func handleInvocation(_ invacation: XCSourceEditorCommandInvocation, handler: (Error?) -> Void) {
80+
81+
6482
let buffer = invacation.buffer
6583
var line = buffer.lines
6684
// importModel(lines: &line)

0 commit comments

Comments
 (0)