9

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 getting – Vishal Sonawane Dec 14 '16 at 12:28
  • even implementing the methods I can't get rid of these messages. I'm trying to follow Raywenderlich tutorial at https://www.raywenderlich.com/140836/firebase-tutorial-real-time-chat-2 – Jasmine Moreira Dec 14 '16 at 12:41
  • Are you using latest version of JSQMessagesViewController? – Vishal Sonawane Dec 14 '16 at 12:43
  • 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 Dec 14 '16 at 12:47
  • pod 'JSQMessagesViewController' have you used same pod to install it? – Vishal Sonawane Dec 14 '16 at 12:49
  • Yes, this is my podfile: target 'SnowBear' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! # Pods for SnowBear pod 'Firebase/Core' pod 'Firebase/Messaging' pod 'Firebase/Database' pod 'Fabric' pod 'Crashlytics' pod 'JSQMessagesViewController' end – Jasmine Moreira Dec 14 '16 at 12:51
  • Have you implemented all the required methods in your swift class??You will have to implement all the required methods in your class where you are importing JSQMessagesViewController. – Vishal Sonawane Dec 14 '16 at 13:01
  • Yes, i did, using old and new method signatures. – Jasmine Moreira Dec 14 '16 at 13:04
  • If you can share your code with me, I can have a look at the problem. – Vishal Sonawane Dec 14 '16 at 13:05
  • Sure, the code is above. – Jasmine Moreira Dec 14 '16 at 13:29
  • i think you are missing 1) collectionView!.delegate = self 2) collectionView!.dataSource = self – Vishal Sonawane Dec 14 '16 at 13:31
  • Sure, I added, but that was not the cause. It seem's compilator can't see my methods or associate them to the JSQMessagesViewController.m signatures. Very weird. – Jasmine Moreira Dec 14 '16 at 13:41
  • hmm actually I have implemented the JSQMessagesViewController with swift 3 and its working at my end. Your error now seems to be really weird. – Vishal Sonawane Dec 14 '16 at 13:45

1 Answers1

4

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/"