Skip to content

Commit 7f868cd

Browse files
author
CodeOcen
committed
feat: 添加导出导入按钮。
1 parent 9fd2fcc commit 7f868cd

File tree

3 files changed

+75
-9
lines changed

3 files changed

+75
-9
lines changed

SwiftJSONModeler For Xcode/Base.lproj/Main.storyboard

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,44 @@
10551055
<action selector="guideButtonTap:" target="5gI-5U-AMq" id="ut3-46-pbJ"/>
10561056
</connections>
10571057
</button>
1058+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="cz6-tK-qLm">
1059+
<rect key="frame" x="447" y="43" width="116" height="32"/>
1060+
<buttonCell key="cell" type="push" title="导出plist配置" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="LgA-1z-kyw">
1061+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
1062+
<font key="font" usesAppearanceFont="YES"/>
1063+
</buttonCell>
1064+
<connections>
1065+
<action selector="exportConfig:" target="5gI-5U-AMq" id="mPS-vD-zxP"/>
1066+
</connections>
1067+
</button>
1068+
<customView translatesAutoresizingMaskIntoConstraints="NO" id="4SI-rq-QS0">
1069+
<rect key="frame" x="104" y="50" width="124" height="20"/>
1070+
<constraints>
1071+
<constraint firstAttribute="height" constant="20" id="ikO-ti-Zup"/>
1072+
</constraints>
1073+
</customView>
1074+
<customView translatesAutoresizingMaskIntoConstraints="NO" id="NnR-Gq-7wW">
1075+
<rect key="frame" x="330" y="50" width="124" height="20"/>
1076+
<constraints>
1077+
<constraint firstAttribute="height" constant="20" id="dHh-EI-q7J"/>
1078+
</constraints>
1079+
</customView>
1080+
<customView translatesAutoresizingMaskIntoConstraints="NO" id="5gt-HB-24E">
1081+
<rect key="frame" x="556" y="50" width="124" height="20"/>
1082+
<constraints>
1083+
<constraint firstAttribute="height" constant="20" id="XMm-iN-Ato"/>
1084+
</constraints>
1085+
</customView>
1086+
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="R45-n9-z1d">
1087+
<rect key="frame" x="221" y="43" width="116" height="32"/>
1088+
<buttonCell key="cell" type="push" title="导入plist配置" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="QR8-zy-W7V">
1089+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
1090+
<font key="font" usesAppearanceFont="YES"/>
1091+
</buttonCell>
1092+
<connections>
1093+
<action selector="importConfig:" target="5gI-5U-AMq" id="2Ts-GO-Kdj"/>
1094+
</connections>
1095+
</button>
10581096
</subviews>
10591097
<constraints>
10601098
<constraint firstItem="cf4-vW-LAT" firstAttribute="top" secondItem="iFK-rh-eoW" secondAttribute="bottom" constant="20" id="0Fy-Bq-4Hz"/>
@@ -1068,26 +1106,37 @@
10681106
<constraint firstItem="CYR-Nv-8jk" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" constant="30" id="7kx-ty-Cce"/>
10691107
<constraint firstItem="iFK-rh-eoW" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" constant="30" id="9Fe-mg-8gt"/>
10701108
<constraint firstItem="vSj-38-HG4" firstAttribute="top" secondItem="FOi-zT-B7B" secondAttribute="bottom" constant="17" id="AXi-SZ-vlS"/>
1109+
<constraint firstItem="5gt-HB-24E" firstAttribute="centerY" secondItem="tHc-az-ITJ" secondAttribute="centerY" id="Bb8-dw-HVe"/>
1110+
<constraint firstItem="4SI-rq-QS0" firstAttribute="leading" secondItem="tHc-az-ITJ" secondAttribute="trailing" id="CFP-Ue-W3I"/>
10711111
<constraint firstItem="wf5-gB-SJa" firstAttribute="top" secondItem="ERx-hH-rdd" secondAttribute="top" constant="50" id="Cru-Pc-WKy"/>
10721112
<constraint firstItem="bDa-kJ-Mhx" firstAttribute="top" secondItem="wf5-gB-SJa" secondAttribute="bottom" constant="40" id="DUG-3B-kQm"/>
10731113
<constraint firstItem="S2C-lh-p4C" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" constant="30" id="EYW-7r-aet"/>
10741114
<constraint firstItem="TgM-de-NPF" firstAttribute="leading" secondItem="bDa-kJ-Mhx" secondAttribute="trailing" constant="8" id="F1p-jz-aRa"/>
10751115
<constraint firstItem="KDI-lJ-ln3" firstAttribute="centerY" secondItem="o35-tq-gm8" secondAttribute="centerY" id="Fz0-5m-ZNX"/>
1116+
<constraint firstItem="cz6-tK-qLm" firstAttribute="centerY" secondItem="tHc-az-ITJ" secondAttribute="centerY" id="G2s-xd-Nbh"/>
1117+
<constraint firstItem="5gt-HB-24E" firstAttribute="width" secondItem="4SI-rq-QS0" secondAttribute="width" id="IYw-20-oLt"/>
10761118
<constraint firstItem="tHc-az-ITJ" firstAttribute="leading" secondItem="FOi-zT-B7B" secondAttribute="leading" id="KTC-Ty-T0u"/>
10771119
<constraint firstItem="TgM-de-NPF" firstAttribute="centerY" secondItem="bDa-kJ-Mhx" secondAttribute="centerY" id="KeH-C1-gk2"/>
10781120
<constraint firstItem="n0v-j5-oIk" firstAttribute="top" secondItem="cf4-vW-LAT" secondAttribute="bottom" constant="20" id="L37-4q-ULx"/>
1121+
<constraint firstItem="R45-n9-z1d" firstAttribute="leading" secondItem="4SI-rq-QS0" secondAttribute="trailing" id="MVM-Az-tT0"/>
1122+
<constraint firstItem="R45-n9-z1d" firstAttribute="centerY" secondItem="tHc-az-ITJ" secondAttribute="centerY" id="N7r-O1-RJ6"/>
10791123
<constraint firstItem="a5h-sk-bjS" firstAttribute="centerY" secondItem="wf5-gB-SJa" secondAttribute="centerY" id="NfI-lb-pf1"/>
10801124
<constraint firstItem="szC-Is-Jzs" firstAttribute="leading" secondItem="cR5-nc-6qZ" secondAttribute="trailing" constant="8" id="R8J-Yg-A1J"/>
10811125
<constraint firstItem="o35-tq-gm8" firstAttribute="leading" secondItem="bDa-kJ-Mhx" secondAttribute="leading" id="RYG-CM-3Sq"/>
1126+
<constraint firstItem="4SI-rq-QS0" firstAttribute="centerY" secondItem="tHc-az-ITJ" secondAttribute="centerY" id="Utv-SB-CSC"/>
1127+
<constraint firstItem="NnR-Gq-7wW" firstAttribute="centerY" secondItem="tHc-az-ITJ" secondAttribute="centerY" id="V8t-zW-9NF"/>
10821128
<constraint firstItem="FOi-zT-B7B" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" constant="30" id="Vow-FC-0iL"/>
10831129
<constraint firstAttribute="trailing" secondItem="CYR-Nv-8jk" secondAttribute="trailing" constant="30" id="VuX-E7-Agq"/>
1130+
<constraint firstItem="vSj-38-HG4" firstAttribute="leading" secondItem="5gt-HB-24E" secondAttribute="trailing" id="XQz-Rj-cSI"/>
10841131
<constraint firstItem="szC-Is-Jzs" firstAttribute="centerY" secondItem="cR5-nc-6qZ" secondAttribute="centerY" id="Xgl-rm-8Ns"/>
10851132
<constraint firstAttribute="trailing" secondItem="vSj-38-HG4" secondAttribute="trailing" constant="30" id="ZLc-N7-aTr"/>
10861133
<constraint firstItem="cR5-nc-6qZ" firstAttribute="leading" secondItem="bDa-kJ-Mhx" secondAttribute="leading" id="bVu-DC-XIX"/>
10871134
<constraint firstAttribute="trailing" secondItem="TgM-de-NPF" secondAttribute="trailing" constant="30" id="ccX-KR-uIA"/>
10881135
<constraint firstAttribute="bottom" secondItem="vSj-38-HG4" secondAttribute="bottom" constant="40" id="efW-1D-QSD"/>
10891136
<constraint firstItem="bDa-kJ-Mhx" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" constant="30" id="efd-GX-YfT"/>
1137+
<constraint firstItem="cz6-tK-qLm" firstAttribute="leading" secondItem="NnR-Gq-7wW" secondAttribute="trailing" id="j5h-5c-tBu"/>
10901138
<constraint firstItem="iFK-rh-eoW" firstAttribute="top" secondItem="CYR-Nv-8jk" secondAttribute="bottom" constant="30" id="jDo-hs-jcy"/>
1139+
<constraint firstItem="NnR-Gq-7wW" firstAttribute="width" secondItem="4SI-rq-QS0" secondAttribute="width" id="jao-yH-P73"/>
10911140
<constraint firstItem="n0v-j5-oIk" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" constant="30" id="jj4-ZX-MCz"/>
10921141
<constraint firstItem="S2C-lh-p4C" firstAttribute="top" secondItem="cR5-nc-6qZ" secondAttribute="bottom" constant="60" id="k0h-Gq-Hui"/>
10931142
<constraint firstAttribute="trailing" secondItem="cf4-vW-LAT" secondAttribute="trailing" constant="30" id="o7Q-Xd-TsJ"/>
@@ -1096,7 +1145,9 @@
10961145
<constraint firstItem="vSj-38-HG4" firstAttribute="centerY" secondItem="tHc-az-ITJ" secondAttribute="centerY" id="sOs-BC-B9c"/>
10971146
<constraint firstItem="wf5-gB-SJa" firstAttribute="leading" secondItem="ERx-hH-rdd" secondAttribute="leading" constant="30" id="tWd-eT-x7t"/>
10981147
<constraint firstItem="szC-Is-Jzs" firstAttribute="trailing" secondItem="KDI-lJ-ln3" secondAttribute="trailing" id="uJj-V6-xvc"/>
1148+
<constraint firstItem="5gt-HB-24E" firstAttribute="leading" secondItem="cz6-tK-qLm" secondAttribute="trailing" id="zNQ-cj-Dro"/>
10991149
<constraint firstItem="cR5-nc-6qZ" firstAttribute="top" secondItem="o35-tq-gm8" secondAttribute="bottom" constant="40" id="zjR-Nn-pvG"/>
1150+
<constraint firstItem="NnR-Gq-7wW" firstAttribute="leading" secondItem="R45-n9-z1d" secondAttribute="trailing" id="zwT-lT-YvE"/>
11001151
</constraints>
11011152
</view>
11021153
<connections>
@@ -1275,7 +1326,7 @@
12751326
</viewController>
12761327
<customObject id="d6U-Sm-fOC" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
12771328
</objects>
1278-
<point key="canvasLocation" x="1138" y="1487.5"/>
1329+
<point key="canvasLocation" x="1145" y="1182"/>
12791330
</scene>
12801331
</scenes>
12811332
</document>

SwiftJSONModeler For Xcode/Controller/ConfigViewController.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ class ConfigViewController: NSViewController {
107107
}
108108

109109
@IBAction func saveButtonTap(_ sender: NSButton) {
110-
// let panel = OpenSavePanel()
111-
// panel.importFile { (error) in
112-
// print(error)
113-
// }
110+
//
114111
config.conform = confromTextField.stringValue
115112
config.module = moduleTextField.stringValue
116113
config.prefix = prefixTextField.stringValue
@@ -140,4 +137,18 @@ class ConfigViewController: NSViewController {
140137
config.isShowYApiMock = sender.state == .on
141138
configCenter.save()
142139
}
140+
@IBAction func importConfig(_ sender: NSButton) {
141+
let panel = OpenSavePanel()
142+
panel.importFile { (error) in
143+
if error == nil {
144+
self.updateFromUserDefault()
145+
}
146+
}
147+
}
148+
@IBAction func exportConfig(_ sender: NSButton) {
149+
let panel = OpenSavePanel()
150+
panel.exportFile { (error) in
151+
print(error)
152+
}
153+
}
143154
}

SwiftJSONModeler For Xcode/YApi/YApiCreator.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,12 @@ class YApiCreator {
129129
}
130130
var line = "var \(object.key!): \(swiftType)"
131131
let isOptional = config.isOptional
132+
let isStringdefaultEmpty = config.isStringDefaultEmpty
132133
if isOptional {
133134
if type == .array, config.isArrayDefaultEmpty {
134135
line.append(contentsOf: " = []")
136+
} else if type == .string, isStringdefaultEmpty {
137+
line.append(contentsOf: #" = """#)
135138
} else {
136139
let optionalStr = config.isImplicitlyOptional ? "!" : "?"
137140
line.append(contentsOf: optionalStr)
@@ -140,11 +143,12 @@ class YApiCreator {
140143
if type == .array, config.isArrayDefaultEmpty {
141144
line.append(contentsOf: " = []")
142145
}
146+
if type == .string, isStringdefaultEmpty {
147+
line.append(contentsOf: #" = """#)
148+
}
143149
}
144-
let isStringdefaultEmpty = config.isStringDefaultEmpty
145-
if type == .string, isStringdefaultEmpty {
146-
line.append(contentsOf: #" = """#)
147-
}
150+
151+
148152
return [comment,line]
149153
}
150154
func getModels() -> [String] {

0 commit comments

Comments
 (0)