OSDN Git Service

Swiftネイティブなクラスを使用するように変更
authormasakih <masakih@users.sourceforge.jp>
Sun, 12 Mar 2017 15:26:20 +0000 (00:26 +0900)
committermasakih <masakih@users.sourceforge.jp>
Sun, 12 Mar 2017 15:26:20 +0000 (00:26 +0900)
KCD/AppDelegate.swift
KCD/JSONViewCommand.swift
KCD/JSONViewWindowController.swift

index 389e981..d5f3781 100644 (file)
@@ -256,9 +256,11 @@ class AppDelegate: NSObject {
             do {
                 let data = try Data(contentsOf: url)
                 let array = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data as NSData)
+                guard let commands = array as? [[String: Any]]
+                    else { return }
                 
                 self.logedJSONViewWindowController = JSONViewWindowController()
-                self.logedJSONViewWindowController?.commands = array as! NSMutableArray
+                self.logedJSONViewWindowController?.commands = commands
                 self.logedJSONViewWindowController?.window?.title = "SAVED LOG FILE VIEWER"
                 self.logedJSONViewWindowController?.showWindow(nil)
             }
index f4b7efa..6e2cd35 100644 (file)
@@ -42,14 +42,14 @@ class JSONViewCommand: JSONCommand {
         guard let _ = recieveDate else { return print("recieveDate is nil.") }
         
         DispatchQueue.main.async {
-            let commands: [String:Any] = [
+            let commands: [String: Any] = [
                 "api": self.api,
                 "argument": self.parameterList,
                 "json": self.jsonTree ?? [],
                 "recieveDate": self.recieveDate ?? Date(),
                 "date": Date()
              ]
-            AppDelegate.shared.jsonViewWindowController?.setCommand(commands as NSDictionary)
+            AppDelegate.shared.jsonViewWindowController?.setCommand(commands)
         }
     }
 }
index 3c3bd3f..6eb43ee 100644 (file)
@@ -24,7 +24,7 @@ class JSONViewWindowController: NSWindowController {
     
     var arguments: NSArray?
     var json: AnyObject?
-    var commands: NSMutableArray = []
+    var commands: [[String: Any]] = []
     
     override func windowDidLoad() {
         super.windowDidLoad()
@@ -33,20 +33,20 @@ class JSONViewWindowController: NSWindowController {
         bind("json", to: apis, withKeyPath: "selection.json")
     }
     
-    func setCommand(_ command: NSDictionary) {
+    func setCommand(_ command: [String: Any]) {
         willChangeValue(forKey: "commands")
-        commands.add(command)
-        didChangeValue(forKey: "commands")
-    }
-    func setCommandArray(_ commands: NSArray) {
-        willChangeValue(forKey: "commands")
-        self.commands.addObjects(from: commands as! [Any])
+        commands += [command]
         didChangeValue(forKey: "commands")
     }
+//    func setCommandArray(_ commands: NSArray) {
+//        willChangeValue(forKey: "commands")
+//        self.commands.addObjects(from: commands as! [Any])
+//        didChangeValue(forKey: "commands")
+//    }
     
     @IBAction func clearLog(_ sender: AnyObject?) {
         willChangeValue(forKey: "commands")
-        commands.removeAllObjects()
+        commands = []
         didChangeValue(forKey: "commands")
     }
 }