title: dealloc/deinit called early when using objc_setAssociatedObject in swift
body: <p>It appears that objc_setAssociatedObject causes objects to be released early.</p>
  
  <p>I followed the method mentioned <a href="https://stackoverflow.com/a/24585481/1721611">here</a> to set the association.</p>
  
  <pre><code>import ObjectiveC
  
  // Define a variable whose address we'll use as key.
  // "let" doesn't work here.
  var kSomeKey = "s"
  
  …
  
  func someFunc() {
      var value = MyOtherClass()
      objc_setAssociatedObject(target, &amp;kSomeKey, value, UInt(OBJC_ASSOCIATION_RETAIN))
  
      let assocValue : AnyObject! = objc_getAssociatedObject(target, &amp;kSomeKey)
  }
  </code></pre>
  
  <p>This results in the object being released during the objc_setAssociatedObject call.  As you can see by this stacktrace.</p>
  
  <pre><code>[MyOtherClass dealloc]
  _objc_object::sidetable_release(bool)
  _object_set_associative_reference
  MyApp.MyClass.someFunc()
  </code></pre>
  
  <p>I originally thought it might have had something to do with swift classes so I also tried standard Objective-C classes and deinit or dealloc are called during the objc_setAssociatedObject call.</p>
  
  <p>Further adding to my confusion is that objc_getAssociatedObject appears to return a valid object and I can access it variables without error.</p>
  
  <p>Is this a swift bug or have I used objc_setAssociatedObject incorrectly?</p>
  
  <p>I am using Xcode6 beta5 in case that is relevant.</p>