OSDN Git Service

艦隊の簡略表示がおかしい問題を修正
[kcd/KCD.git] / KCD / NotificationCenterExtension.swift
1 //
2 //  NotificationCenterExtension.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/10/29.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Foundation
10
11 extension NotificationCenter {
12     
13     func addObserverOnce(forName name: NSNotification.Name?, object obj: Any?, queue: OperationQueue?, using block: @escaping (Notification) -> Void) {
14         
15         weak var token: NSObjectProtocol?
16         token = addObserver(forName: name, object: obj, queue: queue) { [weak self] notification in
17             
18             self.map { me in token.map(me.removeObserver) }
19             block(notification)
20         }
21     }
22 }