Class: NSNotificationCenter

Inherits:
Object
  • Object
show all
Defined in:
motion/core/ns_notification_center.rb

Instance Method Summary collapse

Instance Method Details

#observe(name, object = nil, &proc) ⇒ Object



6
7
8
9
10
11
# File 'motion/core/ns_notification_center.rb', line 6

def observe(name, object=nil, &proc)
  proc.weak! if proc && BubbleWrap.use_weak_callbacks?
  observer = self.addObserverForName(name, object:object, queue:NSOperationQueue.mainQueue, usingBlock:proc)
  observers << observer
  observer
end

#observersObject



2
3
4
# File 'motion/core/ns_notification_center.rb', line 2

def observers
  @observers ||= []
end

#post(name, object = nil, info = nil) ⇒ Object



19
20
21
# File 'motion/core/ns_notification_center.rb', line 19

def post(name, object=nil, info=nil)
  self.postNotificationName(name, object: object, userInfo: info)
end

#unobserve(observer) ⇒ Object



13
14
15
16
17
# File 'motion/core/ns_notification_center.rb', line 13

def unobserve(observer)
  return unless observers.include?(observer)
  removeObserver(observer)
  observers.delete(observer)
end