Skip to content

Commit 767616b

Browse files
author
wushangkun
committed
load cache
1 parent 31cded5 commit 767616b

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
# SKGenerateModelTool
2-
Automatically generate model files, support JSON and URL requests. JSON转model工具
2+
3+
- 支持通过URL链接或json字符串一键生成model文件
4+
- 支持自定义model父类、自定义model前缀、自定义文件名、自定义作者名
5+
- 支持OC / Swift
6+
- 支持自定义输出文件夹路径
7+
- 兼容YYModel / MJExtension / HandyJSON解析
8+
- 兼容服务端返回“id”字段
9+
10+
- Supports one-click generation of model files through URL links or json strings
11+
- Support custom model parent class, custom model prefix, custom file name, custom author name
12+
- Support OC / Swift
13+
- Support custom output folder path
14+
- Compatible with YYModel / MJExtension / HandyJSON analysis
15+
- Compatible server returns "id" field
16+
17+
![photo1.png](https://upload-images.jianshu.io/upload_images/1129777-cf955d251053c767.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
18+

SKGenerateModelTool.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
"$(inherited)",
282282
"@executable_path/../Frameworks",
283283
);
284+
MACOSX_DEPLOYMENT_TARGET = 10.10;
284285
PRODUCT_BUNDLE_IDENTIFIER = com.Xcoder1011.SKGenerateModelTool;
285286
PRODUCT_NAME = "$(TARGET_NAME)";
286287
SWIFT_VERSION = 5.0;
@@ -299,6 +300,7 @@
299300
"$(inherited)",
300301
"@executable_path/../Frameworks",
301302
);
303+
MACOSX_DEPLOYMENT_TARGET = 10.10;
302304
PRODUCT_BUNDLE_IDENTIFIER = com.Xcoder1011.SKGenerateModelTool;
303305
PRODUCT_NAME = "$(TARGET_NAME)";
304306
SWIFT_VERSION = 5.0;

SKGenerateModelTool/ViewController.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ViewController: NSViewController {
2424
@IBOutlet weak var jsonTypeBtn: NSPopUpButton!
2525
@IBOutlet weak var generateFileBtn: NSButton!
2626

27-
var outputFilePath: String?
27+
/// cache key
2828

2929
let LastInputURLCacheKey = "LastInputURLCacheKey"
3030
let SuperClassNameCacheKey = "SuperClassNameCacheKey"
@@ -35,6 +35,11 @@ class ViewController: NSViewController {
3535
let SupportJSONModelTypeCacheKey = "SupportJSONModelTypeCacheKey"
3636
let ShouldGenerateFileCacheKey = "ShouldGenerateFileCacheKey"
3737
let GenerateFilePathCacheKey = "GenerateFilePathCacheKey"
38+
39+
/// cache key
40+
var outputFilePath: String?
41+
42+
var builder = SKCodeBuilder()
3843

3944
override func viewDidLoad() {
4045
super.viewDidLoad()
@@ -57,7 +62,9 @@ class ViewController: NSViewController {
5762
loadUserLastInputContent()
5863
}
5964

65+
/// load cache
6066
func loadUserLastInputContent() {
67+
6168
if let lastUrl = UserDefaults.standard.string(forKey: LastInputURLCacheKey) {
6269
urlTF.stringValue = lastUrl
6370
}
@@ -77,6 +84,19 @@ class ViewController: NSViewController {
7784
outputFilePath = outFilePath
7885
}
7986

87+
builder.config.codeType = SKCodeBuilderCodeType(rawValue: UserDefaults.standard.integer(forKey: BuildCodeTypeCacheKey)) ?? .OC
88+
codeTypeBtn.selectItem(at: builder.config.codeType.rawValue - 1)
89+
90+
builder.config.jsonType = SKCodeBuilderJSONModelType(rawValue: UserDefaults.standard.integer(forKey: SupportJSONModelTypeCacheKey)) ?? .None
91+
jsonTypeBtn.selectItem(at: builder.config.jsonType.rawValue)
92+
93+
generateFileBtn.state = UserDefaults.standard.bool(forKey: SupportJSONModelTypeCacheKey) ? .on : .off
94+
}
95+
96+
/// save cache
97+
func saveUserInputContent() {
98+
let superClassName = superClassNameTF.stringValue.isBlank ? "NSObject" : superClassNameTF.stringValue
99+
UserDefaults.standard.setValue(superClassName, forKey: SuperClassNameCacheKey)
80100
}
81101

82102

0 commit comments

Comments
 (0)