Skip to content

Add NSNotificationObserver implementation #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions Foundation/NSNotification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ extension NSNotification {
}

public class NSNotificationCenter : NSObject {
private var _observers = [NSNotificationObserver]()


/* Returns the default singleton instance.
*/
internal static let defaultInstance = NSNotificationCenter()
public class func defaultCenter() -> NSNotificationCenter {
NSUnimplemented()
return defaultInstance
}

public func postNotification(notification: NSNotification) {
Expand All @@ -78,8 +83,26 @@ public class NSNotificationCenter : NSObject {


public func addObserverForName(name: String?, object obj: AnyObject?, queue: NSOperationQueue?, usingBlock block: (NSNotification) -> Void) -> NSObjectProtocol {
NSUnimplemented()
// Create observer object and store it
let observer = NSNotificationObserver(name: name, object: obj, queue: queue, usingBlock: block)
_observers.append(observer)
return observer
}
}

extension NSNotificationCenter {

private class NSNotificationObserver : NSObject {
let name: String?
let object: AnyObject?
let queue: NSOperationQueue?
let block: (NSNotification) -> Void
init(name: String?, object obj: AnyObject?, queue: NSOperationQueue?, usingBlock block: (NSNotification) -> Void) {
self.name = name
self.object = obj
self.queue = queue
self.block = block
}
}
}