WatchKit has a presenter method that presents a QuickReplyButton with predetermined text replies and those replies can be sent to a UI element such as a label in a cell/row.
I have inserted the row into the last position however each subsequent call inserts the new reply above the previous reply not below.
I attempted to append the text selection choice to the end of the chat model's message array using self.chats.append(text as AnyObject)
, but the choice is a string and I am unable to append a string to the chat model array. Value of type 'String' does not conform to 'AnyObject'
. If I completely omit self.chats.append(text as AnyObject)
it works as shown.
ChatDetailController
// ...
// start of @IBAction
// ...
self.chats.append(text as AnyObject) // how do I write this?
let newIndex = self.chats.count - 1
//...
})
Model
public struct ChatModel: Codable {
public var message: String
// more properties
enum CodingKeys: String, CodingKey {
case message = "messageText"
// more properties
}
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.message = try container.decode(String.self, forKey: .message)
// more properties
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.message, forKey: .message)
// more properties
}
}
json
[
{
"fromId": "wx1234skjksmsjdfwe234",
"toId": "wx43922sdkfjsfmmxdfmx",
"messageText": "Have you hopped on the bus Gus?",
"imageUrl": "https://i.imgur.com/PJcyle7.jpg",
"read": "true"
},
// more objects.
]