Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
MacJsonToModelFile
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈业泓
MacJsonToModelFile
Commits
fce77b15
Commit
fce77b15
authored
Feb 22, 2022
by
陈业泓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
6305b4d2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
26 deletions
+98
-26
UserInterfaceState.xcuserstate
...ata/chenyehong.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
Main.storyboard
MacJsonToModelFile/Base.lproj/Main.storyboard
+43
-11
FileUtil.swift
MacJsonToModelFile/FileManager/FileUtil.swift
+14
-8
ViewController.swift
MacJsonToModelFile/ViewController.swift
+41
-7
No files found.
MacJsonToModelFile.xcodeproj/project.xcworkspace/xcuserdata/chenyehong.xcuserdatad/UserInterfaceState.xcuserstate
View file @
fce77b15
No preview for this file type
MacJsonToModelFile/Base.lproj/Main.storyboard
View file @
fce77b15
...
@@ -707,24 +707,24 @@
...
@@ -707,24 +707,24 @@
<objects>
<objects>
<viewController
id=
"XfG-lQ-9wD"
customClass=
"ViewController"
customModule=
"MacJsonToModelFile"
customModuleProvider=
"target"
sceneMemberID=
"viewController"
>
<viewController
id=
"XfG-lQ-9wD"
customClass=
"ViewController"
customModule=
"MacJsonToModelFile"
customModuleProvider=
"target"
sceneMemberID=
"viewController"
>
<view
key=
"view"
id=
"m2S-Jp-Qdl"
>
<view
key=
"view"
id=
"m2S-Jp-Qdl"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"480"
height=
"
500
"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"480"
height=
"
643
"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<subviews>
<subviews>
<stackView
distribution=
"fill"
orientation=
"vertical"
alignment=
"leading"
horizontalStackHuggingPriority=
"249.99998474121094"
verticalStackHuggingPriority=
"249.99998474121094"
detachesHiddenViews=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"4Ln-IX-BL7"
>
<stackView
distribution=
"fill"
orientation=
"vertical"
alignment=
"leading"
horizontalStackHuggingPriority=
"249.99998474121094"
verticalStackHuggingPriority=
"249.99998474121094"
detachesHiddenViews=
"YES"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"4Ln-IX-BL7"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"480"
height=
"
500
"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"480"
height=
"
643
"
/>
<subviews>
<subviews>
<scrollView
borderType=
"
no
ne"
horizontalLineScroll=
"10"
horizontalPageScroll=
"10"
verticalLineScroll=
"10"
verticalPageScroll=
"10"
hasHorizontalScroller=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"VB7-9f-CUM"
>
<scrollView
borderType=
"
li
ne"
horizontalLineScroll=
"10"
horizontalPageScroll=
"10"
verticalLineScroll=
"10"
verticalPageScroll=
"10"
hasHorizontalScroller=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"VB7-9f-CUM"
>
<rect
key=
"frame"
x=
"0.0"
y=
"
28
"
width=
"480"
height=
"472"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"
171
"
width=
"480"
height=
"472"
/>
<clipView
key=
"contentView"
drawsBackground=
"NO"
id=
"ybR-c0-jSJ"
>
<clipView
key=
"contentView"
drawsBackground=
"NO"
id=
"ybR-c0-jSJ"
>
<rect
key=
"frame"
x=
"
0.0"
y=
"0.0"
width=
"480"
height=
"472
"
/>
<rect
key=
"frame"
x=
"
1"
y=
"1"
width=
"478"
height=
"470
"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<subviews>
<subviews>
<textView
importsGraphics=
"NO"
richText=
"NO"
verticallyResizable=
"YES"
spellingCorrection=
"YES"
smartInsertDelete=
"YES"
id=
"5Za-Kf-uIa"
>
<textView
importsGraphics=
"NO"
richText=
"NO"
verticallyResizable=
"YES"
spellingCorrection=
"YES"
smartInsertDelete=
"YES"
id=
"5Za-Kf-uIa"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"4
80"
height=
"472
"
/>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"4
78"
height=
"470
"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<color
key=
"textColor"
name=
"textColor"
catalog=
"System"
colorSpace=
"catalog"
/>
<color
key=
"textColor"
name=
"textColor"
catalog=
"System"
colorSpace=
"catalog"
/>
<color
key=
"backgroundColor"
name=
"textBackgroundColor"
catalog=
"System"
colorSpace=
"catalog"
/>
<color
key=
"backgroundColor"
name=
"textBackgroundColor"
catalog=
"System"
colorSpace=
"catalog"
/>
<size
key=
"minSize"
width=
"4
80"
height=
"472
"
/>
<size
key=
"minSize"
width=
"4
78"
height=
"470
"
/>
<size
key=
"maxSize"
width=
"480"
height=
"10000000"
/>
<size
key=
"maxSize"
width=
"480"
height=
"10000000"
/>
<color
key=
"insertionPointColor"
name=
"textColor"
catalog=
"System"
colorSpace=
"catalog"
/>
<color
key=
"insertionPointColor"
name=
"textColor"
catalog=
"System"
colorSpace=
"catalog"
/>
</textView>
</textView>
...
@@ -735,13 +735,13 @@
...
@@ -735,13 +735,13 @@
<autoresizingMask
key=
"autoresizingMask"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
</scroller>
</scroller>
<scroller
key=
"verticalScroller"
wantsLayer=
"YES"
verticalHuggingPriority=
"750"
horizontal=
"NO"
id=
"EUK-g5-e0k"
>
<scroller
key=
"verticalScroller"
wantsLayer=
"YES"
verticalHuggingPriority=
"750"
horizontal=
"NO"
id=
"EUK-g5-e0k"
>
<rect
key=
"frame"
x=
"46
4"
y=
"0.0"
width=
"16"
height=
"472
"
/>
<rect
key=
"frame"
x=
"46
3"
y=
"1"
width=
"16"
height=
"470
"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
</scroller>
</scroller>
</scrollView>
</scrollView>
<button
verticalHuggingPriority=
"750"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"T0m-pb-6aN"
>
<button
verticalHuggingPriority=
"750"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"T0m-pb-6aN"
>
<rect
key=
"frame"
x=
"-7"
y=
"
-7"
width=
"75
"
height=
"32"
/>
<rect
key=
"frame"
x=
"-7"
y=
"
136"
width=
"88
"
height=
"32"
/>
<buttonCell
key=
"cell"
type=
"push"
title=
"
Button
"
bezelStyle=
"rounded"
alignment=
"center"
borderStyle=
"border"
imageScaling=
"proportionallyDown"
inset=
"2"
id=
"a5c-fG-IpU"
>
<buttonCell
key=
"cell"
type=
"push"
title=
"
开始转换
"
bezelStyle=
"rounded"
alignment=
"center"
borderStyle=
"border"
imageScaling=
"proportionallyDown"
inset=
"2"
id=
"a5c-fG-IpU"
>
<behavior
key=
"behavior"
pushIn=
"YES"
lightByBackground=
"YES"
lightByGray=
"YES"
/>
<behavior
key=
"behavior"
pushIn=
"YES"
lightByBackground=
"YES"
lightByGray=
"YES"
/>
<font
key=
"font"
metaFont=
"system"
/>
<font
key=
"font"
metaFont=
"system"
/>
</buttonCell>
</buttonCell>
...
@@ -749,14 +749,45 @@
...
@@ -749,14 +749,45 @@
<action
selector=
"clickStart:"
target=
"XfG-lQ-9wD"
id=
"2mN-f0-39a"
/>
<action
selector=
"clickStart:"
target=
"XfG-lQ-9wD"
id=
"2mN-f0-39a"
/>
</connections>
</connections>
</button>
</button>
<scrollView
borderType=
"line"
horizontalLineScroll=
"10"
horizontalPageScroll=
"10"
verticalLineScroll=
"10"
verticalPageScroll=
"10"
hasHorizontalScroller=
"NO"
translatesAutoresizingMaskIntoConstraints=
"NO"
id=
"XfK-ud-qQm"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"480"
height=
"135"
/>
<clipView
key=
"contentView"
drawsBackground=
"NO"
id=
"xvZ-As-Zbf"
>
<rect
key=
"frame"
x=
"1"
y=
"1"
width=
"478"
height=
"133"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<subviews>
<textView
editable=
"NO"
importsGraphics=
"NO"
richText=
"NO"
verticallyResizable=
"YES"
spellingCorrection=
"YES"
smartInsertDelete=
"YES"
id=
"za4-RS-o2S"
>
<rect
key=
"frame"
x=
"0.0"
y=
"0.0"
width=
"478"
height=
"133"
/>
<autoresizingMask
key=
"autoresizingMask"
widthSizable=
"YES"
heightSizable=
"YES"
/>
<color
key=
"textColor"
red=
"1"
green=
"1"
blue=
"1"
alpha=
"1"
colorSpace=
"custom"
customColorSpace=
"sRGB"
/>
<color
key=
"backgroundColor"
name=
"textBackgroundColor"
catalog=
"System"
colorSpace=
"catalog"
/>
<size
key=
"minSize"
width=
"478"
height=
"133"
/>
<size
key=
"maxSize"
width=
"480"
height=
"10000000"
/>
<color
key=
"insertionPointColor"
name=
"textColor"
catalog=
"System"
colorSpace=
"catalog"
/>
</textView>
</subviews>
</clipView>
<constraints>
<constraint
firstAttribute=
"height"
constant=
"135"
id=
"9nQ-3o-X8c"
/>
</constraints>
<scroller
key=
"horizontalScroller"
hidden=
"YES"
wantsLayer=
"YES"
verticalHuggingPriority=
"750"
horizontal=
"YES"
id=
"2Nk-mU-xhI"
>
<rect
key=
"frame"
x=
"-100"
y=
"-100"
width=
"240"
height=
"16"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
</scroller>
<scroller
key=
"verticalScroller"
wantsLayer=
"YES"
verticalHuggingPriority=
"750"
horizontal=
"NO"
id=
"kxR-et-CYP"
>
<rect
key=
"frame"
x=
"463"
y=
"1"
width=
"16"
height=
"133"
/>
<autoresizingMask
key=
"autoresizingMask"
/>
</scroller>
</scrollView>
</subviews>
</subviews>
<visibilityPriorities>
<visibilityPriorities>
<integer
value=
"1000"
/>
<integer
value=
"1000"
/>
<integer
value=
"1000"
/>
<integer
value=
"1000"
/>
<integer
value=
"1000"
/>
</visibilityPriorities>
</visibilityPriorities>
<customSpacing>
<customSpacing>
<real
value=
"3.4028234663852886e+38"
/>
<real
value=
"3.4028234663852886e+38"
/>
<real
value=
"3.4028234663852886e+38"
/>
<real
value=
"3.4028234663852886e+38"
/>
<real
value=
"3.4028234663852886e+38"
/>
</customSpacing>
</customSpacing>
</stackView>
</stackView>
</subviews>
</subviews>
...
@@ -768,12 +799,13 @@
...
@@ -768,12 +799,13 @@
</constraints>
</constraints>
</view>
</view>
<connections>
<connections>
<outlet
property=
"msgTextView"
destination=
"za4-RS-o2S"
id=
"obW-li-wxA"
/>
<outlet
property=
"myScrollView"
destination=
"VB7-9f-CUM"
id=
"Ip0-aa-204"
/>
<outlet
property=
"myScrollView"
destination=
"VB7-9f-CUM"
id=
"Ip0-aa-204"
/>
</connections>
</connections>
</viewController>
</viewController>
<customObject
id=
"rPt-NT-nkU"
userLabel=
"First Responder"
customClass=
"NSResponder"
sceneMemberID=
"firstResponder"
/>
<customObject
id=
"rPt-NT-nkU"
userLabel=
"First Responder"
customClass=
"NSResponder"
sceneMemberID=
"firstResponder"
/>
</objects>
</objects>
<point
key=
"canvasLocation"
x=
"65"
y=
"63
9
"
/>
<point
key=
"canvasLocation"
x=
"65"
y=
"63
8.5
"
/>
</scene>
</scene>
</scenes>
</scenes>
</document>
</document>
MacJsonToModelFile/FileManager/FileUtil.swift
View file @
fce77b15
...
@@ -11,7 +11,7 @@ class FileUtil: NSObject {
...
@@ -11,7 +11,7 @@ class FileUtil: NSObject {
let
manager
=
FileManager
.
default
let
manager
=
FileManager
.
default
func
clearFile
(){
func
clearFile
()
->
String
?
{
let
exist
=
manager
.
fileExists
(
atPath
:
fileDir
.
path
)
let
exist
=
manager
.
fileExists
(
atPath
:
fileDir
.
path
)
if
exist
{
if
exist
{
do
{
do
{
...
@@ -19,6 +19,7 @@ class FileUtil: NSObject {
...
@@ -19,6 +19,7 @@ class FileUtil: NSObject {
print
(
"已存在,删除成功"
)
print
(
"已存在,删除成功"
)
}
catch
{
}
catch
{
print
(
"已存在,删除失败"
)
print
(
"已存在,删除失败"
)
return
"没有文件操作权限,请到系统设置开通,并重新启动程序"
}
}
}
}
do
{
do
{
...
@@ -26,29 +27,34 @@ class FileUtil: NSObject {
...
@@ -26,29 +27,34 @@ class FileUtil: NSObject {
print
(
"创建文件夹成功"
)
print
(
"创建文件夹成功"
)
}
catch
{
}
catch
{
print
(
"创建文件夹失败"
)
print
(
"创建文件夹失败"
)
return
"没有文件操作权限,请到系统设置开通,并重新启动程序"
}
}
return
nil
}
}
func
createOcFile
(
_
model
:
FileModel
){
func
createOcFile
(
_
model
:
FileModel
,
_
callback
:
((
_
msg
:
String
)
->
Void
)
){
let
header
=
ObjcUtil
.
headerTextByModel
(
model
)
let
header
=
ObjcUtil
.
headerTextByModel
(
model
)
createFile
(
"
\(
model
.
fileName
!
)
.h"
,
header
)
createFile
(
"
\(
model
.
fileName
!
)
.h"
,
header
,
callback
)
let
implement
=
ObjcUtil
.
implementByModel
(
model
)
let
implement
=
ObjcUtil
.
implementByModel
(
model
)
createFile
(
"
\(
model
.
fileName
!
)
.m"
,
implement
)
createFile
(
"
\(
model
.
fileName
!
)
.m"
,
implement
,
callback
)
}
}
func
createFile
(
_
fileName
:
String
,
_
content
:
String
){
func
createFile
(
_
fileName
:
String
,
_
content
:
String
,
_
callback
:
((
_
msg
:
String
)
->
Void
)
){
let
file
=
fileDir
.
appendingPathComponent
(
fileName
)
let
file
=
fileDir
.
appendingPathComponent
(
fileName
)
print
(
"文件:
\(
file
)
"
)
let
exist
=
manager
.
fileExists
(
atPath
:
file
.
path
)
let
exist
=
manager
.
fileExists
(
atPath
:
file
.
path
)
if
!
exist
{
if
!
exist
{
let
createSuccess
=
manager
.
createFile
(
atPath
:
file
.
path
,
contents
:
content
.
data
(
using
:
String
.
Encoding
.
utf8
),
attributes
:
nil
)
let
createSuccess
=
manager
.
createFile
(
atPath
:
file
.
path
,
contents
:
content
.
data
(
using
:
String
.
Encoding
.
utf8
),
attributes
:
nil
)
print
(
"文件创建结果:
\(
createSuccess
)
"
)
if
createSuccess
{
callback
(
"导出
\(
file
)
"
)
}
else
{
callback
(
"导出
\(
file
)
失败"
)
}
}
}
}
}
lazy
var
fileDir
:
URL
=
{
lazy
var
fileDir
:
URL
=
{
let
manager
=
FileManager
.
default
let
manager
=
FileManager
.
default
let
urlForDocument
=
manager
.
urls
(
for
:
.
d
esktop
Directory
,
let
urlForDocument
=
manager
.
urls
(
for
:
.
d
ownloads
Directory
,
in
:
.
userDomainMask
)
in
:
.
userDomainMask
)
let
url
=
urlForDocument
[
0
]
.
appendingPathComponent
(
"__ModelResult"
,
isDirectory
:
true
)
let
url
=
urlForDocument
[
0
]
.
appendingPathComponent
(
"__ModelResult"
,
isDirectory
:
true
)
return
url
return
url
...
...
MacJsonToModelFile/ViewController.swift
View file @
fce77b15
...
@@ -13,10 +13,12 @@ class ViewController: NSViewController {
...
@@ -13,10 +13,12 @@ class ViewController: NSViewController {
super
.
viewDidLoad
()
super
.
viewDidLoad
()
// Do any additional setup after loading the view.
// Do any additional setup after loading the view.
}
}
@IBOutlet
weak
var
myScrollView
:
NSScrollView
!
@IBOutlet
weak
var
myScrollView
:
NSScrollView
!
let
fileUtil
=
FileUtil
.
init
()
let
fileUtil
=
FileUtil
.
init
()
@IBOutlet
var
msgTextView
:
NSTextView
!
override
var
representedObject
:
Any
?
{
override
var
representedObject
:
Any
?
{
didSet
{
didSet
{
...
@@ -25,23 +27,39 @@ class ViewController: NSViewController {
...
@@ -25,23 +27,39 @@ class ViewController: NSViewController {
}
}
@IBAction
func
clickStart
(
_
sender
:
Any
)
{
@IBAction
func
clickStart
(
_
sender
:
Any
)
{
msgTextView
.
textStorage
?
.
setAttributedString
(
NSAttributedString
.
init
(
string
:
""
))
if
let
error
=
fileUtil
.
clearFile
()
{
appendMessage
(
error
)
return
}
let
myTextView
:
NSTextView
=
myScrollView
.
documentView
!
as!
NSTextView
let
myTextView
:
NSTextView
=
myScrollView
.
documentView
!
as!
NSTextView
let
myText
:
String
=
myTextView
.
string
let
myText
:
String
=
myTextView
.
string
appendMessage
(
"开始解析json字符串"
)
let
data
=
myText
.
data
(
using
:
String
.
Encoding
.
utf8
)
let
data
=
myText
.
data
(
using
:
String
.
Encoding
.
utf8
)
if
let
dict
=
try
?
JSONSerialization
.
jsonObject
(
with
:
data
!
,
options
:
JSONSerialization
.
ReadingOptions
.
mutableContainers
)
as?
[
String
:
Any
]
{
if
let
dict
=
try
?
JSONSerialization
.
jsonObject
(
with
:
data
!
,
options
:
JSONSerialization
.
ReadingOptions
.
mutableContainers
)
as?
[
String
:
Any
]
{
print
(
"转换成功"
)
fileMap
=
[:]
fileMap
=
[:]
fileUtil
.
clearFile
()
handleDic
(
"Result"
,
dict
as
NSDictionary
)
handleDic
(
"Result"
,
dict
as
NSDictionary
)
for
(
key
,
value
)
in
fileMap
{
for
(
_
,
value
)
in
fileMap
{
fileUtil
.
createOcFile
(
value
)
fileUtil
.
createOcFile
(
value
)
{
msg
in
appendMessage
(
msg
)
}
}
}
// return dict
appendMessage
(
"转换完成!"
)
shell
(
command
:
"open
\(
fileUtil
.
fileDir
.
path
)
"
)
}
else
{
}
else
{
print
(
"请输入正确的json字符串"
)
appendMessage
(
"解析失败,请输入正确的json字符串!"
)
}
}
func
appendMessage
(
_
message
:
String
){
let
scroll
=
(
NSMaxY
(
msgTextView
.
visibleRect
)
==
NSMaxY
(
msgTextView
.
bounds
))
msgTextView
.
textStorage
?
.
append
(
NSAttributedString
.
init
(
string
:
"
\(
message
)\n
"
,
attributes
:
[
NSAttributedString
.
Key
.
foregroundColor
:
NSColor
.
white
]))
if
scroll
{
msgTextView
.
scrollRangeToVisible
(
NSRange
.
init
(
location
:
msgTextView
.
string
.
count
,
length
:
0
))
}
}
}
}
...
@@ -114,5 +132,21 @@ class ViewController: NSViewController {
...
@@ -114,5 +132,21 @@ class ViewController: NSViewController {
return
.
id
return
.
id
}
}
@discardableResult
func
shell
(
command
:
String
)
->
String
{
let
task
=
Process
()
task
.
launchPath
=
"/bin/bash"
task
.
arguments
=
[
"-c"
,
command
]
let
pipe
=
Pipe
()
task
.
standardOutput
=
pipe
task
.
launch
()
let
data
=
pipe
.
fileHandleForReading
.
readDataToEndOfFile
()
let
output
:
String
=
NSString
(
data
:
data
,
encoding
:
String
.
Encoding
.
utf8
.
rawValue
)
!
as
String
return
output
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment