Help! with String Interpolation

Not sure what Im doing wrong here. Says "Cannot convert value of type 'String' to expected argument type 'Int'".


		let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "calCell", for: indexPath) as! CalendarCell

		

		cell.dayOfMonth.text = totalSquares[indexPath.item]

		

		//show the weekend days in different color

		

		switch indexPath.item {

				

			case 0,6,7,13,14,20,21,27,28,34,35,41:

				if Int(cell.dayOfMonth.text = "\(indexPath.item)" > 0 {

					cell.dayOfMonth.textColor = UIColor.lightGray

				}

			default:

				break

		}

		

		return cell

	}

When you paste code, you'd better use Paste and Match Style, to avoid all extra blank lines.

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "calCell", for: indexPath) as! CalendarCell
		cell.dayOfMonth.text = totalSquares[indexPath.item]

		//show the weekend days in different color

		switch indexPath.item {
			case 0,6,7,13,14,20,21,27,28,34,35,41:
				if Int(cell.dayOfMonth.text = "\(indexPath.item)" > 0 {
					cell.dayOfMonth.textColor = UIColor.lightGray
				}

			default:
				break
		}

		return cell
	}

Where do you get the error ? On second line ?

If so, I suspect totalSquares is an array of Int, not array of Strings.

Then you should write:

		cell.dayOfMonth.text = String(totalSquares[indexPath.item])

 

There is probably another error.

What do you want to test here:

if Int(cell.dayOfMonth.text = "\(indexPath.item)" > 0 {

Do you mean:

if Int(cell.dayOfMonth.text) == "\(indexPath.item)" { 

But then what is the > 0 test ?

Do you mean

if Int(cell.dayOfMonth.text) == "\(indexPath.item)" && indexPath.item > 0 {

But then just take 0 out of the case statement ; 0 will be handled in default.

Please clarify

Im testing the (position of cells in a collectionview): case 0,6,7,13,14,20,21,27,28,34,35,41:
But I can't seem to get the string interpolation to equal the cell position.

			case 0,6,7,13,14,20,21,27,28,34,35,41:
				if Int(cell.dayOfMonth.text = "\(indexPath.item)" > 0 {       // <=== I get the error on this line.
					cell.dayOfMonth.textColor = UIColor.lightGray
				}

Im testing against this: case 0,6,7,13,14,20,21,27,28,34,35,41:

The case == the position of cells in collectionview.

I am trying to get the string interpolation to equal the cells position.

			case 0,6,7,13,14,20,21,27,28,34,35,41:
				if Int(cell.dayOfMonth.text = "\(indexPath.item)" > 0 {             //   <===  I get the error on this line
					cell.dayOfMonth.textColor = UIColor.lightGray
				}

The error

"Cannot convert value of type 'String' to expected argument type 'Int'"

means that a String "\(indexPath.item)" should be converted to an Int to be compared to an Int (0). Which cannot be done.

But don't you get a lot more errors? As:

I am trying to get the string interpolation to equal the cells position.

That's not very clear. In particular, what the test > 0 is for in your code.

But as it is a test, I understand you want to test if the month equals the cell position ?

If so, you should test:

if Int(cell.dayOfMonth.text) == indexPath.item { 
Help! with String Interpolation
 
 
Q