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
4765b3ee
Commit
4765b3ee
authored
Feb 22, 2022
by
陈业泓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
fce77b15
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
42 deletions
+22
-42
UserInterfaceState.xcuserstate
...ata/chenyehong.xcuserdatad/UserInterfaceState.xcuserstate
+0
-0
Main.storyboard
MacJsonToModelFile/Base.lproj/Main.storyboard
+0
-0
FileUtil.swift
MacJsonToModelFile/FileManager/FileUtil.swift
+0
-32
ViewController.swift
MacJsonToModelFile/ViewController.swift
+22
-10
No files found.
MacJsonToModelFile.xcodeproj/project.xcworkspace/xcuserdata/chenyehong.xcuserdatad/UserInterfaceState.xcuserstate
View file @
4765b3ee
No preview for this file type
MacJsonToModelFile/Base.lproj/Main.storyboard
View file @
4765b3ee
This source diff could not be displayed because it is too large. You can
view the blob
instead.
MacJsonToModelFile/FileManager/FileUtil.swift
View file @
4765b3ee
...
@@ -59,36 +59,4 @@ class FileUtil: NSObject {
...
@@ -59,36 +59,4 @@ class FileUtil: NSObject {
let
url
=
urlForDocument
[
0
]
.
appendingPathComponent
(
"__ModelResult"
,
isDirectory
:
true
)
let
url
=
urlForDocument
[
0
]
.
appendingPathComponent
(
"__ModelResult"
,
isDirectory
:
true
)
return
url
return
url
}()
}()
func
test
(){
//在桌面上创建一个文件
let
manager
=
FileManager
.
default
let
urlForDocument
=
manager
.
urls
(
for
:
.
desktopDirectory
,
in
:
.
userDomainMask
)
let
url
=
urlForDocument
[
0
]
createFile
(
name
:
"test.txt"
,
fileBaseUrl
:
url
)
}
//根据文件名和路径创建文件
func
createFile
(
name
:
String
,
fileBaseUrl
:
URL
){
let
manager
=
FileManager
.
default
let
file
=
fileBaseUrl
.
appendingPathComponent
(
name
)
print
(
"文件:
\(
file
)
"
)
let
exist
=
manager
.
fileExists
(
atPath
:
file
.
path
)
if
!
exist
{
//在文件中随便写入一些内容
let
str
=
"hello json"
let
createSuccess
=
manager
.
createFile
(
atPath
:
file
.
path
,
contents
:
str
.
data
(
using
:
String
.
Encoding
.
utf8
),
attributes
:
nil
)
print
(
"文件创建结果:
\(
createSuccess
)
"
)
}
else
{
//删除操作
do
{
try
manager
.
removeItem
(
atPath
:
file
.
path
)
}
catch
{
}
}
}
}
}
MacJsonToModelFile/ViewController.swift
View file @
4765b3ee
...
@@ -19,16 +19,28 @@ class ViewController: NSViewController {
...
@@ -19,16 +19,28 @@ class ViewController: NSViewController {
@IBOutlet
weak
var
myScrollView
:
NSScrollView
!
@IBOutlet
weak
var
myScrollView
:
NSScrollView
!
let
fileUtil
=
FileUtil
.
init
()
let
fileUtil
=
FileUtil
.
init
()
@IBOutlet
var
msgTextView
:
NSTextView
!
@IBOutlet
var
msgTextView
:
NSTextView
!
override
var
representedObject
:
Any
?
{
didSet
{
// Update the view, if already loaded.
}
}
@IBOutlet
var
tfPrefix
:
NSTextField
!
@IBOutlet
var
tfClassName
:
NSTextField
!
@IBOutlet
weak
var
menuItemMJ
:
NSMenuItem
!
@IBOutlet
weak
var
menuItemHandJson
:
NSMenuItem
!
@IBAction
func
clickStart
(
_
sender
:
Any
)
{
@IBAction
func
clickStart
(
_
sender
:
Any
)
{
msgTextView
.
textStorage
?
.
setAttributedString
(
NSAttributedString
.
init
(
string
:
""
))
msgTextView
.
textStorage
?
.
setAttributedString
(
NSAttributedString
.
init
(
string
:
""
))
if
menuItemHandJson
.
state
==
.
on
{
appendMessage
(
"HandyJSON模板(.swift),功能未完成,敬请期待"
)
return
}
let
classname
=
tfClassName
.
stringValue
.
trimmingCharacters
(
in
:
CharacterSet
.
whitespacesAndNewlines
)
guard
classname
.
count
>
0
else
{
appendMessage
(
"请输入类名"
)
return
}
if
let
error
=
fileUtil
.
clearFile
()
{
if
let
error
=
fileUtil
.
clearFile
()
{
appendMessage
(
error
)
appendMessage
(
error
)
return
return
...
@@ -40,7 +52,7 @@ class ViewController: NSViewController {
...
@@ -40,7 +52,7 @@ class ViewController: NSViewController {
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
]
{
fileMap
=
[:]
fileMap
=
[:]
handleDic
(
"Result"
,
dict
as
NSDictionary
)
_
=
handleDic
(
classname
,
dict
as
NSDictionary
)
for
(
_
,
value
)
in
fileMap
{
for
(
_
,
value
)
in
fileMap
{
fileUtil
.
createOcFile
(
value
)
{
msg
in
fileUtil
.
createOcFile
(
value
)
{
msg
in
...
@@ -63,11 +75,11 @@ class ViewController: NSViewController {
...
@@ -63,11 +75,11 @@ class ViewController: NSViewController {
}
}
}
}
var
prefix
=
"SLM"
var
fileMap
:
[
String
:
FileModel
]
=
[:]
var
fileMap
:
[
String
:
FileModel
]
=
[:]
func
handleDic
(
_
name
:
String
,
_
dic
:
NSDictionary
)
->
String
{
func
handleDic
(
_
name
:
String
,
_
dic
:
NSDictionary
)
->
String
{
let
prefix
=
tfPrefix
.
stringValue
var
fileName
=
"
\(
prefix
)\(
name
.
capitalized
)
"
var
fileName
=
"
\(
prefix
)\(
name
.
capitalized
)
"
var
count
=
0
var
count
=
0
while
fileMap
.
contains
(
where
:
{
(
key
:
String
,
value
:
FileModel
)
in
while
fileMap
.
contains
(
where
:
{
(
key
:
String
,
value
:
FileModel
)
in
...
@@ -82,7 +94,7 @@ class ViewController: NSViewController {
...
@@ -82,7 +94,7 @@ class ViewController: NSViewController {
for
(
key
,
value
)
in
dic
{
for
(
key
,
value
)
in
dic
{
let
pt
=
FileProperty
.
init
()
let
pt
=
FileProperty
.
init
()
pt
.
propertyName
=
key
as!
String
pt
.
propertyName
=
(
key
as!
String
)
pt
.
propertyType
=
calPropertyType
(
pt
.
propertyName
!
,
value
)
pt
.
propertyType
=
calPropertyType
(
pt
.
propertyName
!
,
value
)
fileModel
.
propertys
.
append
(
pt
)
fileModel
.
propertys
.
append
(
pt
)
}
}
...
...
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