Argument labels do not match any available overloads

后端 未结 1 719
抹茶落季
抹茶落季 2020-12-11 11:58

I am working on a messaging app using JSQMessagesViewController, and I want to associate another variable, an Integer score, with each message (along with the d

相关标签:
1条回答
  • 2020-12-11 12:37

    Just subclass the JSQMessage object and add your extra variable to your subclassed object. Then it will conform and have all the same methods.

    Edit:

    It looks like I might have miss lead you, the documentation instructs you to conform to the JSQMessageData protocol. I did it like this

    class Message: NSObject, JSQMessageData {
    var text_: String?
    var senderId_: String?
    var date_: NSDate?
    var senderDisplayName_: String?
    var isMediaMessage: Bool?
    var score: Int?               ***** Here is your new Variable
    
    init(text: String?, senderId: String?, senderDisplayName: String?, score: Int?, date: NSDate) {
        self.text_ = text
        self.senderId_ = senderId
        self.isOutBound_ = isOutBound
        self.date_ = date
        self.senderDisplayName_ = senderDisplayName
        self.score_ = score       *****
    }
    
    func text() -> String? {
        return text_
    }
    func score() -> Int? {        *****
        return score_
    }
    
    func senderId() -> String? {
        return senderId_
    }
    
    func date() -> NSDate? {
        return date_
    }
    
    func senderDisplayName() -> String? {
        return senderDisplayName_
    }
    
    func isMediaMessage() -> Bool {
        return isMediaMessage_
    }
    
    func messageHash() -> UInt {
        return UInt(self.hash)
    }
    

    }

    You can still do it the other way but Protocols are the way to go.

    Let me know if that helped I may have just confused you more :) But I will try and clarify. Good Luck

    0 讨论(0)
提交回复
热议问题