Sunday, 15 June 2014

xcode - Failable och non-failable initializers prevents me to extend NSView and implement NSCoding -



xcode - Failable och non-failable initializers prevents me to extend NSView and implement NSCoding -

i'm having problems implementing subclass nsview implements nscoding.

it seems declarations of init(coder: nscoder) conflicting in nsview , nscoding. nsview nowadays says it's failable, nscoding still says it's non-failable.

when seek override init(coder: nscoder) , custom initialisation, xcode 6.1 gives me error message:

a non-failable initializer cannot chain failable initializer 'init(coder:)' written 'init?'

how supposed custom init of class?

here's silly illustration extend view , want persist additional click counter view.

import cocoa import foundation class myview: nsview, nscoding { var clickcounter:int = 0 required init(coder: nscoder) { super.init(coder: coder) coder.encodeobject(self.clickcounter, forkey: "clickcounter") } override func encodewithcoder(coder: nscoder) { super.encodewithcoder(coder) coder.encodeobject(self.clickcounter, forkey: "clickcounter") } override func mousedown(theevent: nsevent) { clickcounter++ } }

you don't have explicitly conform nscoding, because nsresponder (superclass of nsview) conforms it.

required init?(coder: nscoder) { super.init(coder: coder) self.clickcounter = coder.decodeobjectforkey("clickcounter") int }

xcode osx cocoa swift nscoding

No comments:

Post a Comment