Skip to content

Commit beabc94

Browse files
author
CodeOcen
committed
feat: 准备替换config
1 parent 9d55459 commit beabc94

File tree

3 files changed

+50
-7
lines changed

3 files changed

+50
-7
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,37 @@
180180
landmarkType = "7">
181181
</BreakpointContent>
182182
</BreakpointProxy>
183+
<BreakpointProxy
184+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
185+
<BreakpointContent
186+
uuid = "FBB3965E-FAF3-47AF-A2E1-88A0A8B61F70"
187+
shouldBeEnabled = "Yes"
188+
ignoreCount = "0"
189+
continueAfterRunningActions = "No"
190+
filePath = "SwiftJSONModeler For Xcode/Controller/ConfigViewController.swift"
191+
startingColumnNumber = "9223372036854775807"
192+
endingColumnNumber = "9223372036854775807"
193+
startingLineNumber = "110"
194+
endingLineNumber = "110"
195+
landmarkName = "saveButtonTap(_:)"
196+
landmarkType = "7">
197+
</BreakpointContent>
198+
</BreakpointProxy>
199+
<BreakpointProxy
200+
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
201+
<BreakpointContent
202+
uuid = "85E9C064-2E1F-4E79-9C30-B8A576B2887F"
203+
shouldBeEnabled = "Yes"
204+
ignoreCount = "0"
205+
continueAfterRunningActions = "No"
206+
filePath = "SwiftJSONModeler For Xcode/Config/ConfigCenter.swift"
207+
startingColumnNumber = "9223372036854775807"
208+
endingColumnNumber = "9223372036854775807"
209+
startingLineNumber = "18"
210+
endingLineNumber = "18"
211+
landmarkName = "config"
212+
landmarkType = "24">
213+
</BreakpointContent>
214+
</BreakpointProxy>
183215
</Breakpoints>
184216
</Bucket>

SwiftJSONModeler For Xcode/Config/ConfigCenter.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ let configPath = (NSHomeDirectory() as NSString).appendingPathComponent("Config
1313

1414
class ConfigCenter {
1515
static let `default` = ConfigCenter()
16-
var config: ConfigModel
16+
var config: ConfigModel {
17+
didSet { // 类赋值调用, 结构体直接改变属性也会调用
18+
Self.writeConfig(config)
19+
}
20+
}
1721

1822
init() {
1923
config = Self.readConfig()
2024
}
2125

26+
2227
}
2328
// MARK: - Private Static Method
2429

@@ -38,11 +43,16 @@ private extension ConfigCenter {
3843

3944
static func writeDefaultConfig() -> ConfigModel {
4045
let defaultConfig = ConfigModel()
46+
writeConfig(defaultConfig)
47+
return defaultConfig
48+
}
49+
@discardableResult
50+
static func writeConfig(_ config: ConfigModel) -> Bool {
4151
let propertyListEncoder = PropertyListEncoder()
4252
propertyListEncoder.outputFormat = .xml
4353

44-
let plistData = try? propertyListEncoder.encode(defaultConfig)
45-
_ = FileManager.default.createFile(atPath: configPath, contents: plistData, attributes: nil)
46-
return defaultConfig
54+
let plistData = try? propertyListEncoder.encode(config)
55+
let isSuccess = FileManager.default.createFile(atPath: configPath, contents: plistData, attributes: nil)
56+
return isSuccess
4757
}
4858
}

SwiftJSONModeler For Xcode/Controller/ConfigViewController.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
import Cocoa
1010

11-
12-
1311
class ConfigViewController: NSViewController {
1412

1513
private let config = Config()
@@ -108,7 +106,10 @@ class ConfigViewController: NSViewController {
108106
}
109107

110108
@IBAction func saveButtonTap(_ sender: NSButton) {
111-
109+
let config = ConfigCenter.default
110+
var c = config.config
111+
c.appVersion = "2.1.0"
112+
config.config = c
112113
// config.conform = confromTextField.stringValue
113114
// config.module = moduleTextField.stringValue
114115
// config.prefix = prefixTextField.stringValue

0 commit comments

Comments
 (0)