Class: MotionBindable::Strategies::UILabel

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

Instance Attribute Summary

Attributes inherited from MotionBindable::Strategy

#attr_name, #bound, #object

Instance Method Summary collapse

Methods included from MotionBindable::StrategyHelpers

#observe_object, #stop_observe_object

Methods inherited from MotionBindable::Strategy

#bind, #bound_value, find_by_reference, #initialize, #object_value, register_strategy

Constructor Details

This class inherits a constructor from MotionBindable::Strategy

Instance Method Details

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



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

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

#on_object_change(new = nil) ⇒ Object



9
10
11
12
# File 'lib/strategies/ui_label.rb', line 9

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

#start_observing_objectObject



5
6
7
# File 'lib/strategies/ui_label.rb', line 5

def start_observing_object
  observe_object { |_, new| on_object_change(new) }
end

#unbindObject



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

def unbind
  stop_observe_object
  super
end