2 // CombinedCommand.swift
5 // Created by Hori,Masaki on 2017/01/09.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 enum CombineType: Int {
19 extension Notification.Name {
21 static let CombinedDidCange = Notification.Name("com.masakih.KCD.Notification.CombinedDidCange")
24 final class CombinedCommand: JSONCommand {
26 static let userInfoKey = "com.masakih.KCD.Notification.CombinedDidCange.CombinedType"
28 override class func canExecuteAPI(_ api: API) -> Bool {
30 return api.endpoint == .henseiCombined
33 override func execute() {
35 if api.endpoint == .port {
37 if let t = data["api_combined_flag"].int {
39 CombineType(rawValue: t).map(postNotification(withType:))
43 postNotification(withType: .cancel)
49 parameter["api_combined_type"]
51 .flatMap { CombineType(rawValue: $0) }
52 .map(postNotification(withType:))
55 private func postNotification(withType type: CombineType) {
57 let userInfo = [CombinedCommand.userInfoKey: type]
59 NotificationCenter.default.post(name: .CombinedDidCange, object: self, userInfo: userInfo)