As coding gets more involved it is very important to get into good practice which will save you a lot of time from finding out what went wrong. I myself spent many hours going through code line by line with some basic school boy errors. In my last blog I wrote about how Swift as a forgiving language. This week I found there were a few things it was not so forgiving about.
In the third app Is it Prime a lot of the back end code is done in Playgrounds and most of my frustrations were from there.
“Statement cannot begin with a closure expression”. What?! When I get a problem I do what most people do. I use Google! But putting this error message into Google wasn’t too helpful, there were many results but nothing very helpful.
The second most frustrating problem I had was “Prefix/postfix ‘=’ is reserved”, again I thought I could Google the answer, again Google came up short but this problem was quicker to fix.
In most programming languages such condition would be valid but in Swift having an exclamation mark at the end of a variable name means you want to unwrap it (telling Xcode the variable definitely has a valid value). So while I had “if number!=2 &&…” it should have been “if number !=2 &&…” all from missing a space! Such simple mistakes which causes such long delays.
In Rob’s iOS and Swift video tutorials he encourages you to pause the video, have a go and come back to see how his solution. So although he may take 7 or 8 minutes in a video lecture and you maybe spending an hour or 2. I can assure you that this is not out of the ordinary. And it is part if the learning process. And remember, if you get stuck the forums are available!
Keep coding! – Tak.