Class: MotionBindable::Strategies::UILabel

Inherits:
MotionBindable::Strategy show all
Defined in:
lib/strategies/ui_label.rb

Constant Summary

Constants inherited from MotionBindable::Strategy

MotionBindable::Strategy::WATCH_TICK

Instance Attribute Summary

Attributes inherited from MotionBindable::Strategy

#attr_name, #bound, #object

Instance Method Summary collapse

Methods inherited from MotionBindable::Strategy

#bind, find_by_reference, #initialize, register_strategy, #unbind

Constructor Details

This class inherits a constructor from MotionBindable::Strategy

Instance Method Details

#observeValueForKeyPath(_, ofObject: _, change: _, context: _) ⇒ Object



20
21
22
# File 'lib/strategies/ui_label.rb', line 20

def observeValueForKeyPath(_, ofObject: _, change: _, context: _)
  on_object_change
end

#on_object_change(new = nil) ⇒ Object



15
16
17
18
# File 'lib/strategies/ui_label.rb', line 15

def on_object_change(new = nil)
  @bound.text = (new || attribute)
  @bound.setNeedsDisplay
end

#start_observing_objectObject



5
6
7
8
9
10
11
12
13
# File 'lib/strategies/ui_label.rb', line 5

def start_observing_object
  # Observe the attribute
  object.addObserver(
    self,
    forKeyPath: attr_name,
    options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld,
    context: nil
  )
end