Search code examples
swiftcloudkit

Icloud query results in EXC_BAD_INSTRUCTION error


In an attempt to learn some CloudKit basics, I am building an app that allows a user to post a question and receive and "Up Vote" or "Down Vote". The app runs fine, until I add an entry then reload. Why am I receiving the error EXC_BAD_INSTRUCTION(code=EXC_1386_INVOP, subcode=0x0) when I try to add the up or down value to an array?

        self.pred = NSPredicate(format: "TRUEPREDICATE")
        let query = CKQuery(recordType: "Questions", predicate: NSPredicate(value: true))
        self.queryOperation = CKQueryOperation (query: query)
        self.queryOperation.recordFetchedBlock = {
            record in

            self.recArray.append(record.objectForKey("Question") as! String)
            self.recIdArray.append(record.recordID)

            //Gives me the correct value
            print(record.objectForKey("Up") as! Int64)

            //Errors on these 2 lines
            self.upArray.append(record.objectForKey("Up") as! Int64)
            self.downArray.append(record.objectForKey("Down") as! Int64)

        }

Solution

  • I fixed it by changing the declaration of my arrays from: var upArray = Int64 var downArray = Int64 to: var upArray = AnyObject var downArray = AnyObject

    Hope this helps someone else too