My simple class, ClassWithOneArray, produces this error:
Bitcast requires both operands to be pointer or neither %19 = bitcast i64 %18 to %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 with exit code 1
However, my class, ClassWithOneInt, does 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") as 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") as String[]
}
}
As I point out in comments, your example seems to compile fine on beta 2, although it still won't work for a couple of reasons, for
encoderWithCoder
to be of any use,ClassWithOneArray
needs to:All told, that means:
Also it seems as if the simple methods of testing archiving aren't available in the playground, probably because the classes don't get properly registered.
In my experience simply declaring the Protocol "NSCoding" to your class should do the trick. Hope this helps someone.
It looks like your syntax is a bit off for what you're trying to accomplish - something like this should work: