Your Second Swift 4 & iOS 11 App - Part 9: | Ray Wenderlich

Your challenge is to provide custom text to a cell based on the index path of the row.

This is a companion discussion topic for the original entry at

I think switch instead else if would be more suitable.

This topic was automatically closed after 166 days. New replies are no longer allowed.

Could you tell me why you use% 5 in ifs? It would not be enough to just use indexPath.row == 0
indexPath.row == 1 and so on

Tks for your help.

@trambalda You are right. I think the author actually used the if-else-if approach and pattern in this case though because it’s easier to understand for beginners after all.

@rpaganini Your solution would be correct if you had only 5 rows from 0 to 4.

In this case you have 100 rows, so you check for the remainder of the row number and 5, which is always a number between 0 and 4. In this way, you repeat the 5 different messages for 20 times.

Please let me know if you have any other questions or issues regarding the whole thing. Thank you!