Can't implement required methods of JSQMessagesViewController Swift 3
Asked Answered
C

1

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

}

Chantey answered 14/12, 2016 at 12:24 Comment(13)
Please show us what error you are gettingShowiness
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-2Chantey
Are you using latest version of JSQMessagesViewController?Showiness
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)Chantey
pod 'JSQMessagesViewController' have you used same pod to install it?Showiness
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' endChantey
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.Showiness
Yes, i did, using old and new method signatures.Chantey
If you can share your code with me, I can have a look at the problem.Showiness
Sure, the code is above.Chantey
i think you are missing 1) collectionView!.delegate = self 2) collectionView!.dataSource = selfShowiness
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.Chantey
hmm actually I have implemented the JSQMessagesViewController with swift 3 and its working at my end. Your error now seems to be really weird.Showiness
C
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/"

Chantey answered 15/12, 2016 at 14:31 Comment(4)
The problem is fixed.Chantey
Hello, How have you fixed your problem.Trinitrophenol
I have rewrite the TODO script without ERRORTAG. TAGS="TODO:|FIXME:" find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"Chantey
Would you Ming closing this question.Echikson

© 2022 - 2024 — McMap. All rights reserved.