title: Can I initialize a variable using a custom assignment operator?
body: <p>Recently I was experimenting with assignment operators in Swift and came across a problem, which I couldn't find the solution for.</p>
  
  <p>Consider the following architecture:</p>
  
  <pre><code>struct Box&lt;T&gt; {
  
      let value: T
  
  }
  
  struct MyStruct {
  
      let myProperty: String
  
      init(boxedProperty: Box&lt;String&gt;) {
          self.myProperty = boxedProperty.value
      }
  
  }
  </code></pre>
  
  <p>Seems pretty straightforward, but imagine that <code>MyStruct</code> accepts 20 boxed properties – each of them requires "unboxing" by accessing the <code>value</code> property of a <code>Box</code> instance. Now imagine having 20 versions of <code>MyStruct</code>.</p>
  
  <p>That would lead to hundreds of <code>.value</code> lines, which is quite a lot. Instead, to reduce the code mess, I would like to use a custom assignment operator, which implicitly "unboxes" a <code>Box</code> and assigns its value to a variable.</p>
  
  <p>Consider this simple example (with no optionality support, etc.):</p>
  
  <pre><code>infix operator &lt;|= {
      associativity right
      precedence 90
      assignment
  }
  
  func &lt;|= &lt;T&gt;(inout lhs: T, rhs: Box&lt;T&gt;) {
      lhs = rhs.value
  }
  </code></pre>
  
  <p>Ideally, I would like to use <code>&lt;|=</code> operator right away, like this:</p>
  
  <pre><code>init(boxedProperty: Box&lt;String&gt;) {
      self.myProperty &lt;|= boxedProperty
  }
  </code></pre>
  
  <p>But unfortunately (and quite predictably?), this doesn't work, as <code>myProperty</code> variable is not initalized before used in a function:</p>
  
  <pre class="lang-none prettyprint-override"><code>error: variable 'self.myProperty' passed by reference before being initialized
      self.myProperty &lt;|= boxedProperty
                      ^
  </code></pre>
  
  <p>Can I ensure the compiler that my <code>assignment</code> operator function always initializes the variable (a.k.a. its <code>lhs</code> operand)? Also, if you have an idea of a different approach, feel free to comment.</p>
  
  <hr>
  
  <p><em>Note: The actual case is more complicated and requires more "unboxing" than just accessing a <code>value</code> propterty of a <code>Box</code> structure.</em></p>