Skip to content

Commit d6051f9

Browse files
author
CodeOcen
committed
feat: 文件导入导出
1 parent 1e58203 commit d6051f9

File tree

7 files changed

+273
-2
lines changed

7 files changed

+273
-2
lines changed

Diff for: SwiftJSONModeler For Xcode.xcodeproj/project.pbxproj

+52-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 52;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -27,12 +27,15 @@
2727
C9CB2480241F559C00F4D5CE /* ErrorCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CB247F241F559C00F4D5CE /* ErrorCenter.swift */; };
2828
C9CEE26D242B382900A04EA9 /* YApiCreator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9CEE26C242B382900A04EA9 /* YApiCreator.swift */; };
2929
C9D04F2B242F218200843DC4 /* SwiftJSONModeler_For_XcodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D04F2A242F218200843DC4 /* SwiftJSONModeler_For_XcodeTests.swift */; };
30+
C9D9905325E742D800258865 /* CleanJSON in Frameworks */ = {isa = PBXBuildFile; productRef = C9D9905225E742D800258865 /* CleanJSON */; };
3031
C9DD88322431C630004E420F /* YApiRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9D04F20242EF99F00843DC4 /* YApiRequest.swift */; };
3132
C9DE045F242C8535008A0070 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DE045E242C8535008A0070 /* Config.swift */; };
3233
C9DE0460242C853F008A0070 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9DE045E242C8535008A0070 /* Config.swift */; };
3334
C9E393E424EE248500D80B28 /* TokenView.xib in Resources */ = {isa = PBXBuildFile; fileRef = C9E393E324EE248500D80B28 /* TokenView.xib */; };
3435
C9E393E824EE255900D80B28 /* TokenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E393E724EE255900D80B28 /* TokenView.swift */; };
3536
C9E393EA24EE47D300D80B28 /* TokenViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E393E924EE47D300D80B28 /* TokenViewController.swift */; };
37+
C9E9C08925CF907A00CD767D /* PanelManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E9C08825CF907A00CD767D /* PanelManager.swift */; };
38+
C9E9C09225CFD94E00CD767D /* ConfigModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9E9C09125CFD94E00CD767D /* ConfigModel.swift */; };
3639
C9ED9CC623D7F9B3004567A1 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ED9CC523D7F9B3004567A1 /* AppDelegate.swift */; };
3740
C9ED9CCA23D7F9B3004567A1 /* Document.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9ED9CC923D7F9B3004567A1 /* Document.swift */; };
3841
C9ED9CCC23D7F9B4004567A1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C9ED9CCB23D7F9B4004567A1 /* Assets.xcassets */; };
@@ -105,6 +108,8 @@
105108
C9E393E324EE248500D80B28 /* TokenView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TokenView.xib; sourceTree = "<group>"; };
106109
C9E393E724EE255900D80B28 /* TokenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenView.swift; sourceTree = "<group>"; };
107110
C9E393E924EE47D300D80B28 /* TokenViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenViewController.swift; sourceTree = "<group>"; };
111+
C9E9C08825CF907A00CD767D /* PanelManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PanelManager.swift; sourceTree = "<group>"; };
112+
C9E9C09125CFD94E00CD767D /* ConfigModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigModel.swift; sourceTree = "<group>"; };
108113
C9ED9CC223D7F9B3004567A1 /* SwiftJSONModeler For Xcode.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "SwiftJSONModeler For Xcode.app"; sourceTree = BUILT_PRODUCTS_DIR; };
109114
C9ED9CC523D7F9B3004567A1 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
110115
C9ED9CC923D7F9B3004567A1 /* Document.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Document.swift; sourceTree = "<group>"; };
@@ -132,6 +137,7 @@
132137
isa = PBXFrameworksBuildPhase;
133138
buildActionMask = 2147483647;
134139
files = (
140+
C9D9905325E742D800258865 /* CleanJSON in Frameworks */,
135141
);
136142
runOnlyForDeploymentPostprocessing = 0;
137143
};
@@ -203,6 +209,22 @@
203209
path = Controller;
204210
sourceTree = "<group>";
205211
};
212+
C9E9C08725CF905400CD767D /* Utils */ = {
213+
isa = PBXGroup;
214+
children = (
215+
C9E9C08825CF907A00CD767D /* PanelManager.swift */,
216+
);
217+
path = Utils;
218+
sourceTree = "<group>";
219+
};
220+
C9E9C09025CFD93900CD767D /* Model */ = {
221+
isa = PBXGroup;
222+
children = (
223+
C9E9C09125CFD94E00CD767D /* ConfigModel.swift */,
224+
);
225+
path = Model;
226+
sourceTree = "<group>";
227+
};
206228
C9ED9CB923D7F9B3004567A1 = {
207229
isa = PBXGroup;
208230
children = (
@@ -227,6 +249,8 @@
227249
C9ED9CC423D7F9B3004567A1 /* SwiftJSONModeler For Xcode */ = {
228250
isa = PBXGroup;
229251
children = (
252+
C9E9C09025CFD93900CD767D /* Model */,
253+
C9E9C08725CF905400CD767D /* Utils */,
230254
C9E393EB24EF68E900D80B28 /* Controller */,
231255
C9E393E224EE245D00D80B28 /* View */,
232256
C92A971B24E514D700C87CCD /* Constants */,
@@ -301,6 +325,9 @@
301325
C9ED9CE723D7F9D0004567A1 /* PBXTargetDependency */,
302326
);
303327
name = "SwiftJSONModeler For Xcode";
328+
packageProductDependencies = (
329+
C9D9905225E742D800258865 /* CleanJSON */,
330+
);
304331
productName = JSONSwiftModelApp;
305332
productReference = C9ED9CC223D7F9B3004567A1 /* SwiftJSONModeler For Xcode.app */;
306333
productType = "com.apple.product-type.application";
@@ -354,6 +381,9 @@
354381
Base,
355382
);
356383
mainGroup = C9ED9CB923D7F9B3004567A1;
384+
packageReferences = (
385+
C9D9905125E742D800258865 /* XCRemoteSwiftPackageReference "CleanJSON" */,
386+
);
357387
productRefGroup = C9ED9CC323D7F9B3004567A1 /* Products */;
358388
projectDirPath = "";
359389
projectRoot = "";
@@ -410,6 +440,7 @@
410440
C92A971724E513EA00C87CCD /* YApiRequest.swift in Sources */,
411441
C97A431324EF7954002F6065 /* Token.swift in Sources */,
412442
C92A971824E513F900C87CCD /* ErrorCenter.swift in Sources */,
443+
C9E9C09225CFD94E00CD767D /* ConfigModel.swift in Sources */,
413444
C9E393E824EE255900D80B28 /* TokenView.swift in Sources */,
414445
C9ED9CC623D7F9B3004567A1 /* AppDelegate.swift in Sources */,
415446
C9E393EA24EE47D300D80B28 /* TokenViewController.swift in Sources */,
@@ -418,6 +449,7 @@
418449
C92A971D24E514FB00C87CCD /* Constants.swift in Sources */,
419450
C92A971424E513EA00C87CCD /* YApiHelper.swift in Sources */,
420451
C9ED9CCA23D7F9B3004567A1 /* Document.swift in Sources */,
452+
C9E9C08925CF907A00CD767D /* PanelManager.swift in Sources */,
421453
C935B49C24EA24BE00E48231 /* JSONHelper.swift in Sources */,
422454
C961C1DE23D82A8D008D0DE6 /* ConfigViewController.swift in Sources */,
423455
C92A971524E513EA00C87CCD /* YApiObject.swift in Sources */,
@@ -753,6 +785,25 @@
753785
defaultConfigurationName = Release;
754786
};
755787
/* End XCConfigurationList section */
788+
789+
/* Begin XCRemoteSwiftPackageReference section */
790+
C9D9905125E742D800258865 /* XCRemoteSwiftPackageReference "CleanJSON" */ = {
791+
isa = XCRemoteSwiftPackageReference;
792+
repositoryURL = "https://github.com/Pircate/CleanJSON.git";
793+
requirement = {
794+
kind = upToNextMajorVersion;
795+
minimumVersion = 1.0.8;
796+
};
797+
};
798+
/* End XCRemoteSwiftPackageReference section */
799+
800+
/* Begin XCSwiftPackageProductDependency section */
801+
C9D9905225E742D800258865 /* CleanJSON */ = {
802+
isa = XCSwiftPackageProductDependency;
803+
package = C9D9905125E742D800258865 /* XCRemoteSwiftPackageReference "CleanJSON" */;
804+
productName = CleanJSON;
805+
};
806+
/* End XCSwiftPackageProductDependency section */
756807
};
757808
rootObject = C9ED9CBA23D7F9B3004567A1 /* Project object */;
758809
}

Diff for: SwiftJSONModeler For Xcode.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

+32
Original file line numberDiff line numberDiff line change
@@ -148,5 +148,37 @@
148148
landmarkType = "7">
149149
</BreakpointContent>
150150
</BreakpointProxy>
151+
<BreakpointProxy
152+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
153+
<BreakpointContent
154+
uuid = "FC03139A-A7F5-4C4D-977C-FD480514FFA6"
155+
shouldBeEnabled = "Yes"
156+
ignoreCount = "0"
157+
continueAfterRunningActions = "No"
158+
filePath = "SwiftJSONModeler For Xcode/Utils/PanelManager.swift"
159+
startingColumnNumber = "9223372036854775807"
160+
endingColumnNumber = "9223372036854775807"
161+
startingLineNumber = "91"
162+
endingLineNumber = "91"
163+
landmarkName = "saveFile(url:)"
164+
landmarkType = "7">
165+
</BreakpointContent>
166+
</BreakpointProxy>
167+
<BreakpointProxy
168+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
169+
<BreakpointContent
170+
uuid = "07C8DB9E-5F35-4316-ADB8-7292B8745933"
171+
shouldBeEnabled = "Yes"
172+
ignoreCount = "0"
173+
continueAfterRunningActions = "No"
174+
filePath = "SwiftJSONModeler For Xcode/Utils/PanelManager.swift"
175+
startingColumnNumber = "9223372036854775807"
176+
endingColumnNumber = "9223372036854775807"
177+
startingLineNumber = "78"
178+
endingLineNumber = "78"
179+
landmarkName = "read(url:)"
180+
landmarkType = "7">
181+
</BreakpointContent>
182+
</BreakpointProxy>
151183
</Breakpoints>
152184
</Bucket>

Diff for: SwiftJSONModeler For Xcode/Model/ConfigModel.swift

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// ConfigModel.swift
3+
// SwiftJSONModeler For Xcode
4+
//
5+
// Created by Sven on 2021/2/7.
6+
// Copyright © 2021 Sven. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
struct ConfigModel: Codable {
12+
var appVersion: String = ""
13+
var conform: String = ""
14+
var module: String = ""
15+
var prefix: String = ""
16+
var subffix = ""
17+
var isOptional: Bool = true
18+
/// 是否为隐式可选, 即 `Any!`
19+
var isImplicitlyOptional: Bool = false
20+
var isArrayDefaultEmpty: Bool = true
21+
/// 是否字符串类型默认为空 即 `""`
22+
var isStringDefaultEmpty: Bool = false
23+
var isShowYApiMock = false
24+
var yapiPath = ""
25+
/// 当前 token
26+
var yapiToken = ""
27+
var yapiHost = ""
28+
/// 备注
29+
var remark: String?
30+
/// 配置的多个 token
31+
var yapiTokenList: [YApiTokenModel] = []
32+
}
33+
34+
struct YApiTokenModel: Codable {
35+
/// 项目名称
36+
var name: String = ""
37+
/// 项目 token
38+
var token: String = ""
39+
}

Diff for: SwiftJSONModeler For Xcode/Utils/PanelManager.swift

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
//
2+
// Panel.swift
3+
// SwiftJSONModeler For Xcode
4+
//
5+
// Created by Sven on 2021/2/7.
6+
// Copyright © 2021 Sven. All rights reserved.
7+
//
8+
/// 文件导入和导出
9+
10+
import AppKit
11+
/// 配置存在路径
12+
let configPath = (NSHomeDirectory() as NSString).appendingPathComponent("Config.plist")
13+
struct PanelManager {
14+
// static let `default` = PanelManager()
15+
// private init() {}
16+
/// 导入文件
17+
func openPanelImportFile(completion: @escaping (_ url: URL?) -> Void) -> Void {
18+
let panel = NSOpenPanel()
19+
panel.prompt = "确定"
20+
panel.message = "选择配置"
21+
panel.canChooseDirectories = false
22+
panel.canCreateDirectories = false
23+
panel.allowedFileTypes = ["plist"]
24+
panel.allowsMultipleSelection = false
25+
//panel.directoryURL =
26+
panel.beginSheetModal(for: NSApp.mainWindow ?? NSWindow() ) { (response) in
27+
if response == .OK {
28+
let url = panel.url
29+
read(url: url)
30+
completion(url)
31+
} else {
32+
//取消
33+
completion(nil)
34+
}
35+
}
36+
}
37+
38+
/// 导出文件
39+
func openPanelExportFile() -> Void {
40+
let savePanel = NSSavePanel()
41+
savePanel.nameFieldStringValue = "Config.plist"
42+
savePanel.message = "请选择路径保存配置"
43+
savePanel.allowedFileTypes = ["plist"]
44+
savePanel.isExtensionHidden = false
45+
savePanel.canCreateDirectories = true
46+
//savePanel.directoryURL =
47+
savePanel.beginSheetModal(for: NSApp.mainWindow ?? NSWindow()) { (response) in
48+
if response == .OK {
49+
if let path = savePanel.url {
50+
saveFile(url: path)
51+
}
52+
} else {
53+
54+
}
55+
}
56+
}
57+
58+
private func read(url: URL?) {
59+
// guard let url = url else {
60+
// return
61+
// }
62+
// let plistFile = NSDictionary.init(contentsOf: url)
63+
// print(plistFile)
64+
// let data = try? Data(contentsOf: url) // 可能 datameiyou
65+
// let decoder = PropertyListDecoder()
66+
// do {
67+
// let config = try decoder.decode(ConfigModel.self, from: data!)
68+
// } catch let error {
69+
// print(error)
70+
// }
71+
72+
73+
let configModel = ConfigModel()
74+
let propertyListEncoder = PropertyListEncoder()
75+
propertyListEncoder.outputFormat = .xml
76+
77+
let plistData = try? propertyListEncoder.encode(configModel)
78+
let fileManager = FileManager.default
79+
let isSuccess = fileManager.createFile(atPath: configPath, contents: plistData, attributes: nil) // 全覆盖写入
80+
if isSuccess {
81+
print("保存成功")
82+
} else {
83+
print("保存失败")
84+
}
85+
}
86+
87+
/// 保存文件
88+
func saveFile( url: URL) -> Void {
89+
let fileManager = FileManager.default
90+
let contents = fileManager.contents(atPath: configPath)
91+
let isSuccess = fileManager.createFile(atPath: url.path, contents: contents, attributes: [FileAttributeKey.appendOnly : false, FileAttributeKey.extensionHidden: false])
92+
if isSuccess {
93+
print("保存成功")
94+
} else {
95+
print("保存失败")
96+
}
97+
}
98+
}

Diff for: SwiftJSONModelerDemo/SwiftJSONModelerDemo.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
C964811F242D8FB900EFFCB6 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C964811D242D8FB900EFFCB6 /* LaunchScreen.storyboard */; };
1616
C964812B242D9B0D00EFFCB6 /* TestJSONModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C964812A242D9B0D00EFFCB6 /* TestJSONModel.swift */; };
1717
C964812D242D9B2700EFFCB6 /* TestYapiRAWModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C964812C242D9B2700EFFCB6 /* TestYapiRAWModel.swift */; };
18+
C9E9C08225CF81E900CD767D /* Config.plist in Resources */ = {isa = PBXBuildFile; fileRef = C9E9C08125CF81E900CD767D /* Config.plist */; };
1819
/* End PBXBuildFile section */
1920

2021
/* Begin PBXFileReference section */
@@ -28,6 +29,7 @@
2829
C9648120242D8FB900EFFCB6 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2930
C964812A242D9B0D00EFFCB6 /* TestJSONModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestJSONModel.swift; sourceTree = "<group>"; };
3031
C964812C242D9B2700EFFCB6 /* TestYapiRAWModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestYapiRAWModel.swift; sourceTree = "<group>"; };
32+
C9E9C08125CF81E900CD767D /* Config.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Config.plist; sourceTree = "<group>"; };
3133
/* End PBXFileReference section */
3234

3335
/* Begin PBXFrameworksBuildPhase section */
@@ -69,6 +71,7 @@
6971
C9648120242D8FB900EFFCB6 /* Info.plist */,
7072
C964812A242D9B0D00EFFCB6 /* TestJSONModel.swift */,
7173
C964812C242D9B2700EFFCB6 /* TestYapiRAWModel.swift */,
74+
C9E9C08125CF81E900CD767D /* Config.plist */,
7275
);
7376
path = SwiftJSONModelerDemo;
7477
sourceTree = "<group>";
@@ -131,6 +134,7 @@
131134
isa = PBXResourcesBuildPhase;
132135
buildActionMask = 2147483647;
133136
files = (
137+
C9E9C08225CF81E900CD767D /* Config.plist in Resources */,
134138
C964811F242D8FB900EFFCB6 /* LaunchScreen.storyboard in Resources */,
135139
C964811C242D8FB900EFFCB6 /* Assets.xcassets in Resources */,
136140
C964811A242D8FB800EFFCB6 /* Main.storyboard in Resources */,

0 commit comments

Comments
 (0)