Skip to content

Commit 22748c1

Browse files
author
Sven
committed
feat:update readme
1 parent 3aaf279 commit 22748c1

File tree

4 files changed

+97
-8
lines changed

4 files changed

+97
-8
lines changed

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
SwiftJSONModeler是一个Xcode插件,一键转换json字符串Swfit模型,一键转化 YApi 平台接口为模型,并且自动引入注释。
1+
SwiftJSONModeler是一个Xcode插件,一键转换json字符串为Swfit模型,一键转化 YApi 平台接口为模型,并且自动引入注释。
22
* 支持struct, class
33
* 支持单json转模, 多层嵌套 json
44
* 支持YApi RAW或接口id解析转模,并且自动引入 YApi 平台注释和兼容数据类型
55
* 支持自定义遵循 和 import
66
* 支持自定义模型前缀和后缀
77
* 可设置隐式和显示可选类型,默认显示可选`?`(不使用则为隐式可选`!`)
88
* YApi 支持按照自定义路径解析模型,自动解析子类型
9+
* 导入导出配置plist配置,以便团队共享。
910

1011

1112
## json 转Swfit模型
1213

13-
复制单json, 一步转为模型
14+
复制json字符串, 一步转为Swift模型,支持多层嵌套自动识别
1415

1516
![运行效果](./Sources/example.gif)
1617

@@ -97,7 +98,7 @@ struct HKSubJsonModel: HandyJSON {
9798

9899
如果无法预览查看[Source/YApiRAW.gif](./Sources/YApiRAW.gif)
99100

100-
如果你使用YApi接口平台,我们支持两种方式,通过接口 Id)和 Raw 数据转模。一键转为模型,并且自动根据YApi为模型引入注释。
101+
如果你使用YApi接口平台,我们支持两种方式,通过接口 Id和 Raw 数据转模。一键转为模型,并且自动根据YApi为模型引入注释。
101102

102103
### 通过Id转模
103104

@@ -144,7 +145,10 @@ struct HKSubJsonModel: HandyJSON {
144145

145146
再将应用移动到应用程序, 重启Xcode即可使用。
146147

147-
> Tip:如果重启Xcode之后在Editor中还没看见插件选项,请选择系统设置-> 扩展->Xcode Source Editor中对应插件是否导入
148+
### 注意事项
149+
150+
1. 安装弹出安全提示,选择系统设置 -> 安全性与隐私 -> 通用 点击允许打开该软件即可。
151+
2. 如果重启Xcode之后在Editor中还没看见插件选项,请选择系统设置-> 扩展->Xcode Source Editor中对应插件是否勾选
148152

149153
## 设置
150154
SwiftJSONModeler提供多种自定义可选设置,可通过插件的Config选项进行设置。
@@ -169,6 +173,16 @@ SwiftJSONModeler提供多种自定义可选设置,可通过插件的Config选
169173

170174
![](./Sources/mutilToken.png)
171175

176+
> 多 token 接口无法转模问题
177+
>
178+
> 通过 id 转模,配置多个 token 项目,可能会存在某个项目无法通过 id 砖模型,原因 YApi 平台的 token 无法获取到相应的json数据.
179+
>
180+
> 解决办法: 使用其他项目 token 尝试
181+
182+
设置通过 plist 文件保存,可以导入导出。
183+
184+
> Tips: plist 文件还有其他未展示的设置, 比如默认设置 String 类型为空字符串等
185+
172186
## 设置快捷键
173187

174188
可以给插件设置快捷键,快速转换模型

SwiftJSONModeler For Xcode.xcodeproj/xcuserdata/yibin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,69 @@
180180
landmarkType = "7">
181181
</BreakpointContent>
182182
</BreakpointProxy>
183+
<BreakpointProxy
184+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
185+
<BreakpointContent
186+
uuid = "9F6A3FF9-2096-496B-8998-5DF112BBB5C9"
187+
shouldBeEnabled = "Yes"
188+
ignoreCount = "0"
189+
continueAfterRunningActions = "No"
190+
filePath = "SwiftJSONModeler For Xcode/YApi/YApiHelper.swift"
191+
startingColumnNumber = "9223372036854775807"
192+
endingColumnNumber = "9223372036854775807"
193+
startingLineNumber = "56"
194+
endingLineNumber = "56"
195+
landmarkName = "object(from:dic:)"
196+
landmarkType = "7">
197+
</BreakpointContent>
198+
</BreakpointProxy>
199+
<BreakpointProxy
200+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
201+
<BreakpointContent
202+
uuid = "4EE8686A-9525-4D85-BBD2-7C358537B8EC"
203+
shouldBeEnabled = "Yes"
204+
ignoreCount = "0"
205+
continueAfterRunningActions = "No"
206+
filePath = "SwiftJSONModeler For Xcode/YApi/YApiHelper.swift"
207+
startingColumnNumber = "9223372036854775807"
208+
endingColumnNumber = "9223372036854775807"
209+
startingLineNumber = "42"
210+
endingLineNumber = "42"
211+
landmarkName = "check(from:)"
212+
landmarkType = "7">
213+
</BreakpointContent>
214+
</BreakpointProxy>
215+
<BreakpointProxy
216+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
217+
<BreakpointContent
218+
uuid = "7AAA994E-CF13-4368-AE2D-9112BFA27732"
219+
shouldBeEnabled = "Yes"
220+
ignoreCount = "0"
221+
continueAfterRunningActions = "No"
222+
filePath = "SwiftJSONModeler For Xcode/YApi/YApiHelper.swift"
223+
startingColumnNumber = "9223372036854775807"
224+
endingColumnNumber = "9223372036854775807"
225+
startingLineNumber = "101"
226+
endingLineNumber = "101"
227+
landmarkName = "getPathObjects(path:from:)"
228+
landmarkType = "7">
229+
</BreakpointContent>
230+
</BreakpointProxy>
231+
<BreakpointProxy
232+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
233+
<BreakpointContent
234+
uuid = "72921868-82CF-4D8E-9A98-41E44BC2BE8A"
235+
shouldBeEnabled = "Yes"
236+
ignoreCount = "0"
237+
continueAfterRunningActions = "No"
238+
filePath = "SwiftJSONModeler For Xcode/YApi/YApiHelper.swift"
239+
startingColumnNumber = "9223372036854775807"
240+
endingColumnNumber = "9223372036854775807"
241+
startingLineNumber = "95"
242+
endingLineNumber = "95"
243+
landmarkName = "getPathObjects(path:from:)"
244+
landmarkType = "7">
245+
</BreakpointContent>
246+
</BreakpointProxy>
183247
</Breakpoints>
184248
</Bucket>

SwiftJSONModeler For Xcode/YApi/YApiCreator.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class YApiCreator {
164164
if yapiObject.key != nil {
165165
name = yapiObject.key!.upperCaseFirst()
166166
}
167-
let des: String = yapiObject.des ?? "<#描述#>"
167+
let des: String = yapiObject.des ?? ""
168168
var keyword = keyStruct
169169
if commandIdentifier.contains(keyStruct) {
170170
keyword = keyStruct
@@ -174,7 +174,9 @@ class YApiCreator {
174174
name = config.prefix + name + config.subffix
175175
let parent = config.parent
176176
var objctLines: [String] = []
177-
objctLines.append("/// \(des)")
177+
if !des.isEmpty {
178+
objctLines.append("/// \(des)")
179+
}
178180
if parent.isEmpty {
179181
objctLines.append("\(keyword) \(name) {")
180182
} else {

SwiftJSONModeler For Xcode/YApi/YApiRequest.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class YApiRequest {
5555
var request = URLRequest(url: URL(string: url)!, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 30)
5656
request.httpMethod = "GET"
5757
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
58-
58+
print(request)
5959
let session = URLSession(configuration: .default)
6060
let task = session.dataTask(with: request) { (data, response, error) in
6161
if error != nil {
@@ -74,7 +74,16 @@ class YApiRequest {
7474
let dataStr = String(data: data, encoding: .utf8)
7575
print("____dataStr")
7676
print(dataStr)
77-
guard let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any], let code = json["errcode"] as? Int, code == 0, let dataDic = json["data"] as? [String: Any], let resBody = dataDic["res_body"] as? String else {
77+
guard let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] else {
78+
errorCenter.message = "获取数据 json 解析异常"
79+
return nil
80+
}
81+
guard let code = json["errcode"] as? Int, code == 0, let dataDic = json["data"] as? [String: Any], let resBody = dataDic["res_body"] as? String else {
82+
var error = "获取接口数据异常"
83+
if let message = json["errmsg"] as? String {
84+
error = message
85+
}
86+
errorCenter.message = error
7887
return nil
7988
}
8089
let raw = resBody.replacingOccurrences(of: #"\""#, with: "\"")

0 commit comments

Comments
 (0)