swift - Trying to access property of a class which subclasses a cocoa class gives run-time error -
i made customized button type(class) inherits nsbutton
, has additional methods well, when try access methods declared myself, run-time error. here's code:
import cocoa class mcbutton: nsbutton { func testfunc()->bool { return true } } class viewcontroller: nsviewcontroller { @iboutlet weak var button: mcbutton! override func viewdidload() { super.viewdidload() if button.testfunc() { //thread 1: exc_bad_access(code=2, address=0x608000264600) button.title = "hi!" } } }
note don't have problems when use methods declared in superclass(nsbutton
). what's problem? should fix it?
you have correctly set button's class in interfacebuilder. has predefined value set, nsbutton
. have set mcbutton
instead.
only reference correct instance of 1 of mcbutton
s.
Comments
Post a Comment