title: Swift delegate and Objective-C delegator: EXC_BAD_ACCESS
body: <p>I am writing a Swift application that must use an Objective-C library and adopt an Objective-C protocol as a delegate. I instantiate the delegate class and set it to be the delegate of the Objective-C delegator. When I run the application and the delegator tries to reference the delegate, I receive "EXC_BAD_ACCESS (code=1, address=0xc)".</p>
  
  <p>Through Xcode debugging I have enabled Zombies, set a breakpoint, and watched the memory address of the Swift delegate. I found that the application is changing the memory address location of the Swift delegate and the Objective-C delegator references the old memory location causing the application to crash with the EXC_BAD_ACCESS error.</p>
  
  <p>The Objective-C library is pre-compiled without ARC and does not use bitcode. I cannot figure out how to either make my app stop changing the memory location of the delegate, or tell the delegator to update the memory location when it does change. See my code below.</p>
  
  <p>Objective-C Delegator .h file</p>
  
  <pre><code>@protocol Library_Delegate;
  
  @interface Library : NSObject{
      id&lt;Library_Delegate&gt; delegate;
  }
  
  @property(nonatomic, assign) id&lt;Library_Delegate&gt; delegate;
  </code></pre>
  
  <p>Objective-C Protocol .h file</p>
  
  <pre><code>@class Library;
  
  @protocol Library_Delegate &lt;NSObject&gt;
  
  
  -(void) Library_CallbackFunction;
  
  @end
  </code></pre>
  
  <p>Swift Delegate</p>
  
  <pre><code>class LibraryAPIWrapper: NSObject, Library_Delegate {
  
      let library = Library()
  
      override init() {
          super.init()
          Library.delegate = self
      }
  
      func Library_CallbackFunction() {
          print("Success")
      }
  }
  </code></pre>
  
  <p>Swift ViewController</p>
  
  <pre><code>override func viewDidLoad() {
      let libraryAPIWrapper = LibraryAPIWrapper()
  }
  </code></pre>