0

I'm getting this weird error. My Project was working fine and all of a sudden I got these errors. The errors indicated by Xcode:

Cannot override with a stored property 'leadingConstraint'

Overriding non-open var outside of its defining module

I've defined a constraint variable in UITableViewCell, on which it's giving error.

I tried

  • clean the build folder.

  • Restarted the Xcode but it's still giving me that error.

Error enter image description here

Cell:

import UIKit
class ReceiverChatImageCell: UITableViewCell {

    let bubbleBackgroundView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor.darkGray
        v.layer.cornerRadius = 5
        v.layer.masksToBounds = true
        v.translatesAutoresizingMaskIntoConstraints = false
        return v
    }()

    public let chatImage: UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleAspectFill
        v.translatesAutoresizingMaskIntoConstraints = false
        v.clipsToBounds = true
        return v
    }()

    var maxMessageLength: CGFloat = 250
    var leadingConstraint: NSLayoutConstraint?

    var chatMessage: ChatModel! {
        didSet {
            profileImageView.loadImage(string: chatMessage.imageUrl)
            chatImage.loadImage(string: chatMessage.chatImageUrl)
        }
    }

    public let profileImageView: UIImageView = {
        let v = UIImageView()
        v.image = #imageLiteral(resourceName: "babs")
        v.translatesAutoresizingMaskIntoConstraints = false
        v.contentMode = .scaleAspectFill
        v.clipsToBounds = true
        v.layer.cornerRadius = 20
        return v
    }()

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        commonInit()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }

    func commonInit(){
        backgroundColor = .clear


        addSubview(profileImageView)
        addSubview(bubbleBackgroundView)
        addSubview(chatImage)
        let available: CGFloat = UIScreen.main.bounds.width - 100
        if maxMessageLength  > available{
            maxMessageLength = available  -  50
            print("Available Space \(maxMessageLength)")
        }

        // lets set up some constraints for our image
        let constraints = [

            profileImageView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 0),
            profileImageView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -8),
            profileImageView.widthAnchor.constraint(equalToConstant: 40),
            profileImageView.heightAnchor.constraint(equalToConstant: 40),

            chatImage.topAnchor.constraint(equalTo: topAnchor, constant: 8),
            chatImage.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -24),
            chatImage.widthAnchor.constraint(lessThanOrEqualToConstant: maxMessageLength),
            chatImage.heightAnchor.constraint(lessThanOrEqualToConstant: 250),

            bubbleBackgroundView.topAnchor.constraint(equalTo: chatImage.topAnchor, constant: -8),
            bubbleBackgroundView.leadingAnchor.constraint(equalTo: chatImage.leadingAnchor, constant: -16),
            bubbleBackgroundView.bottomAnchor.constraint(equalTo: chatImage.bottomAnchor, constant: 8),
            bubbleBackgroundView.trailingAnchor.constraint(equalTo: chatImage.trailingAnchor, constant: 16),
            ]
        NSLayoutConstraint.activate(constraints)

        leadingConstraint = chatImage.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 60)
        leadingConstraint?.isActive = true
    }
}

I haven't used this variable outside the cell.

enter image description here

How can I solve this problem?

Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89

0 Answers0