<commit_before>//
//  GZNotificationCenter.swift
//  MyWatch
//
//  Created by <NAME> on 4/15/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

enum GZNotificationCenterAgentType {
    /// Core Foundation
    case CFNotificationCenter
}

/// The encapsulated implementation of CFNotificationCenter by bridge to NSNotificationCenter.
public class GZNotificationCenter {
    
    static let singleton = GZNotificationCenter()
    
    public class func defaultCenter()->GZNotificationCenter {
        return singleton
    }
    
    init(){
        
        NSNotificationCenter.defaultCenter().addObserverForName(GZCFNotificationCallBackConvertorNotificationName, object: nil, queue: NSOperationQueue.mainQueue()) { (note:NSNotification!) -> Void in
            
            var name = (note.userInfo?[GZCFNotificationCallBackConvertorNotificationOriginalNameKey] as? String) ?? ""
            
            NSNotificationCenter.defaultCenter().postNotificationName(name, object: nil)
            
        }
    }
    
    /// Add an observer for receive notifications from CFNotificationCenter.
    public func addObserver(observer: AnyObject, selector aSelector: Selector, name aName: String){
        self.addObserver(.CFNotificationCenter, observer: observer, selector: aSelector, name: aName)
    }
    
    func addObserver(agentType:GZNotificationCenterAgentType, observer: AnyObject, selector aSelector: Selector, name aName: String){

        switch agentType {
            
        case .CFNotificationCenter:
            
            let center = CFNotificationCenterGetDarwinNotifyCenter()
            CFNotificationCenterAddObserver(center, nil, GZCFNotificationCallBackBlock, aName, nil, CFNotificationSuspensionBehavior.DeliverImmediately)
            
            NSNotificationCenter.defaultCenter().addObserver(observer, selector: aSelector, name: aName, object: nil)
        }
        
    }
    
    /// Post an notification to observer that has been registered as an observer through CFNotificationCenter.
    public func postNotification(name aName: String){
        
        self.postNotification(.CFNotificationCenter, name: aName)
    }
    
    func postNotification(agentType:GZNotificationCenterAgentType, name aName: String){
        
        switch agentType {
            
        case .CFNotificationCenter:

            let center = CFNotificationCenterGetDarwinNotifyCenter()
            CFNotificationCenterPostNotification(center, aName, nil, nil, 1)
            
        }
        
    }
    
    
}<commit_msg>1. add method : removeObserver:name:<commit_after>//
//  GZNotificationCenter.swift
//  MyWatch
//
//  Created by <NAME> on 4/15/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

enum GZNotificationCenterAgentType {
    /// Core Foundation
    case CFNotificationCenter
}

/// The encapsulated implementation of CFNotificationCenter by bridge to NSNotificationCenter.
public class GZNotificationCenter {
    
    static let singleton = GZNotificationCenter()
    
    public class func defaultCenter()->GZNotificationCenter {
        return singleton
    }
    
    init(){
        
        NSNotificationCenter.defaultCenter().addObserverForName(GZCFNotificationCallBackConvertorNotificationName, object: nil, queue: NSOperationQueue.mainQueue()) { (note:NSNotification!) -> Void in
            
            var name = (note.userInfo?[GZCFNotificationCallBackConvertorNotificationOriginalNameKey] as? String) ?? ""
            
            NSNotificationCenter.defaultCenter().postNotificationName(name, object: nil)
            
        }
    }
    
    /// Add an observer for receive notifications from CFNotificationCenter.
    public func addObserver(observer: AnyObject, selector aSelector: Selector, name aName: String){
        self.addObserver(.CFNotificationCenter, observer: observer, selector: aSelector, name: aName)
    }
    
    func addObserver(agentType:GZNotificationCenterAgentType, observer: AnyObject, selector aSelector: Selector, name aName: String){

        switch agentType {
            
        case .CFNotificationCenter:
            
            let center = CFNotificationCenterGetDarwinNotifyCenter()
            CFNotificationCenterAddObserver(center, unsafeAddressOf(observer), GZCFNotificationCallBackBlock, aName, nil, CFNotificationSuspensionBehavior.DeliverImmediately)
            
            NSNotificationCenter.defaultCenter().addObserver(observer, selector: aSelector, name: aName, object: nil)
        }
        
    }
    
    /// Post an notification to observer that has been registered as an observer through CFNotificationCenter.
    public func postNotification(name aName: String){
        
        self.postNotification(.CFNotificationCenter, name: aName)
    }
    
    func postNotification(agentType:GZNotificationCenterAgentType, name aName: String){
        
        switch agentType {
            
        case .CFNotificationCenter:

            let center = CFNotificationCenterGetDarwinNotifyCenter()
            CFNotificationCenterPostNotification(center, aName, nil, nil, 1)
            
        }
        
    }
    
    
    func removeObserver(agentType:GZNotificationCenterAgentType, observer: AnyObject, name aName:String){
        
        switch agentType {
            
        case .CFNotificationCenter:
            
            let center = CFNotificationCenterGetDarwinNotifyCenter()
            CFNotificationCenterRemoveObserver(center, unsafeAddressOf(observer), aName, nil)
            
            NSNotificationCenter.defaultCenter().removeObserver(observer)
        }
        
    }
    
}
{'fraction_non_alphanumeric': 0.0730762458179257, 'fraction_numerical': 0.0036978341257263604, 'mean_word_length': 2.7148463047743623, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '5928442', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1362, 'n_words': 333}