<commit_before>//
//  MessageBus.swift
//  Pods
//
//  Created by <NAME> on 14/11/2016.
//
//

import Foundation

private struct Observation {
    weak var observer: AnyObject?
    let block: (_ info: Any)->Void
}

public class MessageBus: NSObject {
    private var observations = [String: [Observation]]()
    private let lock: AnyObject = UUID().uuidString as AnyObject
    
    public func addObserver(_ observer: AnyObject, events: [PKEvent.Type], block: @escaping (_ info: Any)->Void) {
        sync {
            events.forEach { (et) in
                let typeId = NSStringFromClass(et)
                var array: [Observation]? = observations[typeId]
                
                if array == nil {
                    array = []
                }
                array!.append(Observation(observer: observer, block: block))
                observations[typeId] = array
            }
        }
    }
    
    public func removeObserver(_ observer: AnyObject, events: [PKEvent.Type]) {
        sync {
            events.forEach { (et) in
                let typeId = NSStringFromClass(et)
                if let array = observations[typeId] {
                    observations[typeId] = array!.filter { $0.observer! !== observer }
                } else {
                    print("removeObserver:: array is empty")<commit_msg>fix compilation error<commit_after>//
//  MessageBus.swift
//  Pods
//
//  Created by <NAME> on 14/11/2016.
//
//

import Foundation

private struct Observation {
    weak var observer: AnyObject?
    let block: (_ info: Any)->Void
}

public class MessageBus: NSObject {
    private var observations = [String: [Observation]]()
    private let lock: AnyObject = UUID().uuidString as AnyObject
    
    public func addObserver(_ observer: AnyObject, events: [PKEvent.Type], block: @escaping (_ info: Any)->Void) {
        sync {
            events.forEach { (et) in
                let typeId = NSStringFromClass(et)
                var array: [Observation]? = observations[typeId]
                
                if array == nil {
                    array = []
                }
                array!.append(Observation(observer: observer, block: block))
                observations[typeId] = array
            }
        }
    }
    
    public func removeObserver(_ observer: AnyObject, events: [PKEvent.Type]) {
        sync {
            events.forEach { (et) in
                let typeId = NSStringFromClass(et)
                if let array = observations[typeId] {
                    observations[typeId] = array.filter { $0.observer! !== observer }
                } else {
                    print("removeObserver:: array is empty")
{'fraction_non_alphanumeric': 0.1068901303538175, 'fraction_numerical': 0.0067039106145251395, 'mean_word_length': 1.7492323439099284, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1646759', 'n_tokens_mistral': 738, 'n_tokens_neox': 696, 'n_words': 193}