Ahad Sheriff Ahad Sheriff - 1 year ago 444
Swift Question

Argument labels do not match any available overloads

I am working on a messaging app using JSQMessagesViewController, and I want to associate another variable, an Integer

, with each message (along with the defaults such as
, and
). This is how I attempt to implement this:

func addMessage(id: String, text: String, displayName: String, score: Int) {

// Make sure the character count is between 10 and 140, then add message to message list to display
if (text.characters.count <= 10 || text.characters.count >= 140) {

else {
let message = JSQMessage(senderId: id, displayName: displayName, text: text, score: score)


However I am getting the following error message:

Argument labels '(senderId:, displayName:, text:, score:)' do not match any available overloads

I can only assume that this is because there is some pre-set definition as to what data the JSQMessage object can hold, I am just unsure how to override it so that I can associate an additional variable with my messages.

Note: I tried to directly change the code in the JSQMessagesViewController framework itself (within the
files) to add an extra variable but this just causes more errors and I am afraid I will mess something up.

Any solutions?

Thanks in advance.


I think I figured out how to do it! `import UIKit
import JSQMessagesViewController

class CustomMessage: JSQMessage {
var score : Int

init(senderId:String, displayName:String, text:String, score:Int) {
self.score = score
super.init(senderId:senderId, displayName:displayName, text:text)

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


However I am now getting an error after
as such:
must call a designated initializer of the superclass 'JSQMessage'

Answer Source

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


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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download