8
votes

I'm trying to use JSQMessagesVC in my Swift 3 project. It was installed via cocoa pods and everything looks fine. The problem is I can't implement collectionView methods and a keep getting errors. Can anyone help me?

Errors

import UIKit
import JSQMessagesViewController

class ChatViewController: JSQMessagesViewController {

    var messages = [JSQMessage]()

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView!.delegate = self
        collectionView!.dataSource = self

        collectionView!.collectionViewLayout.incomingAvatarViewSize = CGSize.zero
        collectionView!.collectionViewLayout.outgoingAvatarViewSize = CGSize.zero

    }

    override func collectionView(_ collectionView: JSQMessagesCollectionView, messageDataForItemAt indexPath: IndexPath) -> JSQMessageData {
        return messages[indexPath.item]
    }

    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return messages.count
    }

    override func collectionView(_ collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAt indexPath: IndexPath!) -> JSQMessageBubbleImageDataSource! {
        let message = messages[indexPath.item] // 1
        if message.senderId == senderId { // 2
            return outgoingBubbleImageView
        } else { // 3
            return incomingBubbleImageView
        }
    }

    override func collectionView(_ collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAt indexPath: IndexPath!) -> JSQMessageAvatarImageDataSource! {
        return nil
    }


    lazy var outgoingBubbleImageView: JSQMessagesBubbleImage = self.setupOutgoingBubble()
    lazy var incomingBubbleImageView: JSQMessagesBubbleImage = self.setupIncomingBubble()

    private func setupOutgoingBubble() -> JSQMessagesBubbleImage {
        let bubbleImageFactory = JSQMessagesBubbleImageFactory()
        return bubbleImageFactory!.outgoingMessagesBubbleImage(with: UIColor.jsq_messageBubbleBlue())
    }

    private func setupIncomingBubble() -> JSQMessagesBubbleImage {
        let bubbleImageFactory = JSQMessagesBubbleImageFactory()
        return bubbleImageFactory!.incomingMessagesBubbleImage(with: UIColor.jsq_messageBubbleLightGray())
    }




//    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//        //Your Logic here
//    }

}

1
Please show us what error you are gettingVishal Sonawane
even implementing the methods I can't get rid of these messages. I'm trying to follow Raywenderlich tutorial at raywenderlich.com/140836/firebase-tutorial-real-time-chat-2Jasmine Moreira
Are you using latest version of JSQMessagesViewController?Vishal Sonawane
Yes, version 7.3.4, i'm using other tools too: Using Crashlytics (3.8.3) Using Fabric (1.6.11) Using Firebase (3.11.0) Using FirebaseAnalytics (3.6.0) Using FirebaseCore (3.4.6) Using FirebaseDatabase (3.1.1) Using FirebaseInstanceID (1.0.8) Using FirebaseMessaging (1.2.1) Using GoogleInterchangeUtilities (1.2.2) Using GoogleSymbolUtilities (1.1.2) Using GoogleToolboxForMac (2.1.0) Installing JSQMessagesViewController (7.3.4) Installing JSQSystemSoundPlayer (2.0.1)Jasmine Moreira
pod 'JSQMessagesViewController' have you used same pod to install it?Vishal Sonawane

1 Answers

4
votes

I was using a script to detect some tags (TODO, FIXME and ERROR) during compilation. So, I had a combination of wrong method signatures and script wrong detection.

TAGS="TODO:|FIXME:" ERRORTAG="ERROR:" find "${SRCROOT}" ( -name ".h" -or -name ".m" -or -name ".swift" ) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"