Saturday, 15 June 2013

xcode6 - Simple Swift class does not compile -



xcode6 - Simple Swift class does not compile -

my simple class, classwithonearray, produces error:

bitcast requires both operands pointer or neither %19 = bitcast i64 %18 %objc_object*, !dbg !470 llvm error: broken function found, compilation aborted! command /applications/xcode6-beta.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/swift failed exit code 1

however, class, classwithoneint, not. why?

class classwithoneint { var myint = int() init(myint: int) { self.myint = int() } func encodewithcoder(acoder: nscoder) { acoder.encodeobject(myint, forkey: "myint") } init(coder adecoder: nscoder) { self.myint = adecoder.decodeobjectforkey("myint") int } } class classwithonearray { var myarray = string[]() init(myarray: string[]) { self.myarray = string[]() } func encodewithcoder(acoder: nscoder) { acoder.encodeobject(myarray, forkey: "myarray") } init(coder adecoder: nscoder) { self.myarray = adecoder.decodeobjectforkey("myarray") string[] } }

as point out in comments, illustration seems compile fine on beta 2, although still won't work couple of reasons, encoderwithcoder of use, classwithonearray needs to:

declare conformance nscoding, implement nscoding, inherit nsobject or implement nsobjectprotocol, and, use non-mangled name.

all told, means:

@objc(classwithonearray) class classwithonearray:nsobject, nscoding { var myarray: string[] init(myarray: string[]) { self.myarray = myarray } func encodewithcoder(acoder: nscoder) { acoder.encodeobject(myarray, forkey: "myarray") } init(coder adecoder: nscoder) { self.myarray = adecoder.decodeobjectforkey("myarray") string[] } }

also seems if simple methods of testing archiving aren't available in playground, because classes don't registered.

let foo = classwithonearray(myarray:["a"]) allow info = nskeyedarchiver.archiveddatawithrootobject(foo) allow unarchiver = nskeyedunarchiver(forreadingwithdata:data) unarchiver.setclass(classwithonearray.self, forclassname: "classwithonearray") allow bar = unarchiver.decodeobjectforkey("root") classwithonearray

swift xcode6 nscoder

No comments:

Post a Comment