osx - Swift weak delegate runtime error (bad access). Bug? -


i have problem delegates in swift (osx). have view, connected delegate through weak reference. simplified code this:

protocol myprotocol: class {     func protocolfunc() -> int }  class mycontroller : myprotocol {     func protocolfunc() -> int { return 2 } }  class myview : nsview {     weak var delegate: myprotocol?      func grabdata {         var data = delegate?.protocolfunc()     } } 

when delegate?.protocolfunc() called, app crashes saying "bad access". it's if mycontroller instance had disappeared... has not. mycontroller instance lives in nsdocument subclass; , view's delegate set.

the crash goes away if declare delegate strong. thing want delegate weak. what's going on? eyes, weak reference should work.

at time of writing (xcode 6 beta 5), there's bug weak delegates. time being, can until fixed change protocol myprotocol: class @objc protocol myprotocol , avoid using pure swift classes in protocol.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -