WKInterfaceTable is not getting populated with Codable data

83 views Asked by At

My JSON object is not getting sent to my WKInterfaceTable.

UITableView is populating correctly. Last step is to populate the WKInterfaceTable. The code is not throwing an errors in Xcode but there is a runtime crash because the cast is failing.

Edit: Thanks to Dale I fixed an error handling line so the run-time message is gone, but the same problem persists.

printing loadedData: Optional(<5b7b2273 7065616b 6572223a 224a6f68 6e222c22 7469746c 65223a22 486f7720 61726520 796f753f 222c2274 6f223a22 323a3030 222c2266 726f6d22 3a22313a 3030227d ...>)

    override func willActivate() {
         super.willActivate()

        if(WCSession.default.isReachable) {

            let message = ["getMsgData" : [:]]

            WCSession.default.sendMessage(message, replyHandler:

                { (result) -> Void in

                    print("Requesting data from phone")
                    print("printing message: \(message)")
                    print("printing messageObjects: \(self.messageObjects)")

                    if result["messageData"] != nil { 
                        let loadedData = result["messageData"]

                        NSKeyedUnarchiver.setClass(MessageObject.self, forClassName: "MessageObject")

                        do {
                            let loadedPerson = try? JSONDecoder().decode(MessageObject.self, from: loadedData as! Data)

                            self.messageObjects = [loadedPerson]
                            self.progTable.setNumberOfRows(self.messageObjects.count, withRowType: "MsgRowController")

               //code...
    }
1

There are 1 answers

0
TokyoToo On

Through the process of updating to using the Codable protocol I didn't realize I had to remove previous instances of NSKeyedArchiver/Unarchiver.