2 // CombinedCommand.swift
5 // Created by Hori,Masaki on 2017/01/09.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 enum CombineType: Int {
18 extension Notification.Name {
19 static let CombinedDidCange = Notification.Name("com.masakih.KCD.Notification.CombinedDidCange")
22 class CombinedCommand: JSONCommand {
23 static let userInfoKey = "com.masakih.KCD.Notification.CombinedDidCange.CombinedType"
24 override class func canExecuteAPI(_ api: String) -> Bool {
25 if api == "/kcsapi/api_req_hensei/combined" { return true }
29 override func execute() {
30 if api == "/kcsapi/api_port/port" {
31 guard let data = json["api_data"] as? [String: Any]
33 if let t = data["api_combined_flag"] as? Int {
34 CombineType(rawValue: t)
35 .map { postNotification(withType: $0) }
37 postNotification(withType: .cancel)
42 arguments["api_combined_type"]
44 .flatMap { CombineType(rawValue:$0) }
45 .map { postNotification(withType: $0) }
48 private func postNotification(withType type: CombineType) {
49 let userInfo = [CombinedCommand.userInfoKey: type]
52 .post(name: .CombinedDidCange, object: self, userInfo: userInfo)