Here is my code. I am a beginner using Swift and my code does not work.
Error in view controller was shown:
Cannot assign value of type 'Int' to type 'String'
And:
Could not cast value of type '__NSCFNumber' (0x104061840) to 'NSString' (0x1031324a8). 2019-09-30 01:46:05.056249+0900 Community[20037:815002] Could not cast value of type '__NSCFNumber' (0x104061840) to 'NSString' (0x1031324a8).
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// getting index of the cell wherein comments button has been pressed
let indexPathRow = (sender as! UIButton).tag
// accessing segue we need -> CommentsVC
if segue.identifier == "CommentsVC" {
// accessing destination ViewController -> CommentsVC
let vc = segue.destination as! CommentsVC
// assigning values to the vars of CommentsVC
vc.avaImage = avaImageView.image!
vc.fullnameString = fullnameLable.text!
vc.dateString = posts[indexPathRow]!["date_created"] as! String
vc.textString = posts[indexPathRow]!["text"] as! String
////////////
// sending id of the post
vc.post_id = posts[indexPathRow]!["id"] as! Int
// sending the image to the CommentsVC
let indexPath = IndexPath(item: indexPathRow, section: 0)
guard let cell = tableView.cellForRow(at: indexPath) as? PicCell else {
return
}
vc.pictureImage = cell.pictureImageView.image!
}
Cannot assign value of type 'Int' to type 'String'
on:
vc.post_id = posts[indexPathRow]!["id"] as! Int