Tables and arrays

Continuing with the iOS8 and Swift tutorials I’m at a level where I can make practical use of some of the knowledge I’ve acquired from these iOS 8 and Swift video tutorials. Lecture 45 provides a task to create an app to display the times table of a number selected from a slider bar. The thing to remember about all programming is good practice to avoid any errors and to be able to interpret errors to create a solution. Sometimes, though it is just the logic that needs to be evaluated if something isn’t behaving as expected.

tableresultBuilding up to this we learn about tables in Swift and how to display items in a table from an array of items. Rob filled his array with members of his family and out put them to each row. I filled my array with the names of my siblings. Unfortunately, when the app ran the display wasn’t what I wanted. The intention was to have each name on each row.

Luckily, this was not too difficult to fix. With a lot of programming languages certain characters are reserved and needs to be escaped if it is intended to be included in a string but not with Swift.

cellcontentMy array declaration had the commas within double quotes. So Swift treated the contents as a single string item for one array element. A simple mistake but something to bear in mind.

array_errorAnother novice mistake involves the error message “Array index out of range” which occurs when you try to refer to an array element which doesn’t exist. So if your array has nine elements (not counting 0!) and you refer to the tenth e.g. array[10] then Swift won’t be happy with it.

Attention to detail is key. The less simple mistakes you make, the more time you save with debugging. - Tak

 

 

Sales and marketing executive.
3rd degree black belt in Taekwon-Do.
Lives at the gym.
Enjoys burgers and cake.
Likes fast cars and lie-ins.

Leave a Reply