micyukcha micyukcha - 8 days ago 6
Swift Question

Swift override method didPressSend

I am using Swift 3.0 and Xcode 8.0 and JSQMessages 7.3.4.

I am trying to implement JSQMessagesViewController and specifically, I am trying to override the didPressSend function yet it keep complaining that the method does not override any method from its superclass.

override func didPressSend(_ button: UIButton, withMessageText text: String, senderId: String, senderDisplayName: String, date: Date) {
print("working")
}


Any thoughts on why this might be?

It also complains method cannot be an @obj override because type of parameter 5 cannot be represented in Objective-C.

Answer
override func didPressSend(_ button: UIButton?, withMessageText text: String?, senderId: String?, senderDisplayName: String?, date: Date?) {
    guard let number = conversation?.smsNumber, let text = text else {
        assertionFailure("The conversation number or text is nil")
        return
    }
    print("working")
}

practice safe code out there.