0

hello I am using JSQMessagesViewcontroller to make a chatapp, I need to add an extra property to JSQMessages to give each message an ID. and I also need to override the first convenience init to use this function:

self.JSQmessages.append(JSQCell(senderId: self.senderId,displayName: self.senderDisplayName, text: message.text))

this is what their message cell looks like

public class JSQMessage : NSObject, JSQMessageData, NSCoding, NSCopying {
    public var senderId: String! { get }
    public var senderDisplayName: String! { get }
    @NSCopying public var date: NSDate! { get }
    public var isMediaMessage: Bool { get }
    public var text: String! { get }
    @NSCopying public var media: JSQMessageMediaData! { get }
    
public convenience init!(senderId: String!, displayName: String!, text: String!)
   
public init!(senderId: String!, senderDisplayName: String!, date: NSDate!, text: String!)
    
public convenience init!(senderId: String!, displayName: String!, media: JSQMessageMediaData!)
  
public init!(senderId: String!, senderDisplayName: String!, date: NSDate!, media: JSQMessageMediaData!)
}

I tried subclassing, but I'm really new to ios development and can never get it right. this is what I have so far.

class JSQCell : JSQMessage {
var MessageId: String?
 required init(senderId: String!, displayName: String!, text: String!, MessageId: String!)



required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

Any help would be greatly appreciated.

slimboy
  • 1,633
  • 2
  • 22
  • 45

1 Answers1

1

All you need 'to do is conform your message object to the 'JSQMessageData' protocol and then you can add as many custom variables as you would like. I outline it in this question. https://stackoverflow.com/a/38884743/5894123

Community
  • 1
  • 1
Dan Leonard
  • 3,325
  • 1
  • 20
  • 32