lib/strategies/ui_label.rb in motion_bindable-0.2.5 vs lib/strategies/ui_label.rb in motion_bindable-0.3.0
- old
+ new
@@ -1,17 +1,11 @@
module MotionBindable::Strategies
-
class UILabel < ::MotionBindable::Strategy
+ include MotionBindable::StrategyHelpers
def start_observing_object
- # Observe the attribute
- object.addObserver(
- self,
- forKeyPath: attr_name,
- options: NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld,
- context: nil
- )
+ observe_object { |_, new| on_object_change(new) }
end
def on_object_change(new = nil)
@bound.text = (new || attribute)
@bound.setNeedsDisplay
@@ -20,12 +14,10 @@
def observeValueForKeyPath(_, ofObject: _, change: _, context: _)
on_object_change
end
def unbind
- object.removeObserver(self, forKeyPath: attr_name)
+ stop_observe_object
super
end
-
end
-
end