Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Previous answer is very comperhensive and good, I'd just thought I'd add an answer explains what it is at its core without involving Cocoa or Objective-C specifically. That is because the concept itself is language agnostic although dynamic languages like Objective-C makes it a <em>lot</em> easier than more static language like C++. </p> <h3>Example</h3> <p>Say you have two objects <strong>M</strong> and <strong>V</strong>. <strong>M</strong> has methods:</p> <pre><code>setX(int x); setY(int y); int getX(); int getY(); </code></pre> <p>While <strong>V</strong> has methods:</p> <pre><code>setA(int x); setB(int y); int getA(); int getB(); </code></pre> <p>One way of looking at this is that <strong>M</strong> has properties <strong>x</strong> and <strong>y</strong> and <strong>V</strong> has properties <strong>a</strong> and <strong>b</strong>. You want a change of property <strong>x</strong> to cause a change in property <strong>b</strong> and a change in <strong>y</strong> to cause a change in <strong>a</strong>.</p> <p>By change in property <strong>x</strong> we mean e.g.:</p> <pre><code>M.setX(10) </code></pre> <p>where previously</p> <pre><code>M.getX() != 10 </code></pre> <p>So we want a call of <em>setX</em> on <strong>M</strong> to cause a call to <em>setA</em> on <strong>V</strong>. </p> <p>What bindings allow you to say is that property <strong>b</strong> on object <strong>V</strong> is bound to property <strong>x</strong> on object <strong>M</strong>. And then this updating is handled automatically. You as a coder don't have to write code that checks if <strong>x</strong> is changed and then call <em>setB</em> on <strong>V</strong>. Bindings takes care of this automatically.</p> <h3>Summary</h3> <p>Bindings allows you to bind two properties together that exist on two different objects, so that changing the value of one of the properties causes the dependant property in the other object to change to the same value.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload