Commit 4765b3ee authored by 陈业泓's avatar 陈业泓

update

parent fce77b15
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -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 {
}
}
}
} }
...@@ -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)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment