0

I have to show the int value in the label, but such an error occurs in the cell. This code is a cell code and a model code. And there is also an error 'Cannot assign value of type 'String' to type 'UIImage''. How do I solve this error?

var RankingData: RankingModel! {
        didSet { setUpView() }
    }
    
    private func setUpView() {
        self.RankingLbl?.text = RankingData.ranking
        self.profileImage?.image = RankingData.profileImage
        self.nickNameLbl?.text = RankingData.nickName
    }

This is my cell code

self.RankingLbl?.text = RankingData.ranking error : Cannot assign value of type 'Int' to type 'String'

self.profileImage?.image = RankingData.profileImage error : Cannot assign value of type 'String' to type 'UIImage'

    var ranking: Int = -1
    var nickName: String = ""
    var profileImage: String = ""
    
    enum RankingModelKeys: String, CodingKey {
        case ranking
        case nickName
        case profileImage
    }
}

This is my model code

1 Answer 1

1

As the error describes, you can't assign a value of Int to String. You need to create the value of same type as below,

private func setUpView() {
    self.RankingLbl?.text = "\(RankingData.ranking)"
    self.profileImage?.image = UIImage(named: RankingData.nickName)
    self.nickNameLbl?.text = RankingData.nickName
}

You can check Type Safety and Type Inference here for better understanding.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.