Simple Swift class does not compile

后端 未结 3 589
挽巷
挽巷 2021-01-21 06:43

My simple class, ClassWithOneArray, produces this error:

Bitcast requires both operands to be pointer or neither %19 = bitcast i64 %18 to %objc_object

3条回答
  •  独厮守ぢ
    2021-01-21 07:09

    It looks like your syntax is a bit off for what you're trying to accomplish - something like this should work:

    class ClassWithOneInt {
        var myInt: Int
        init(myInt: Int) {
            self.myInt = myInt
        }
        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 = myArray
        }
        func encodeWithCoder(aCoder: NSCoder) {
            aCoder.encodeObject(myArray, forKey: "myArray")
        }
        init(coder aDecoder: NSCoder) {
            self.myArray = aDecoder.decodeObjectForKey("myArray") as String[]
        }
    }
    

提交回复
热议问题