2 // NotificationObserver.swift
5 // Created by Hori,Masaki on 2018/01/28.
6 // Copyright © 2018年 Hori,Masaki. All rights reserved.
11 /// 開放時にremoveObserver(_:)を実行してくれるクラス
12 final class NotificationObserver {
14 private var tokens: [NSObjectProtocol] = []
16 func addObserver(forName name: Notification.Name, object: Any?, queue: OperationQueue? = nil, using block: @escaping (Notification) -> Void) {
18 tokens += [NotificationCenter.default.addObserver(forName: name, object: object, queue: queue, using: block)]
22 tokens.forEach(NotificationCenter.default.removeObserver)