Preventative Measures

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

Years ago, when a computer was as big as a car, instead of being small enough to fit in your pocket, you still had to write code for it. In those days, syntax errors or typos were very common bugs. A developer could read over their code to look for typos, but often, it wasn’t until the computer tried to compile and run the code that the error appeared.

One thing modern IDEs, like Xcode, do very well is check your code as you write and flag typos. An unexpected syntax error when compiling and running is rare. However, many other bugs aren’t as easy to catch until later. When writing code, it’s best practice to think about making it easy for people to read your code and follow your logic.

Descriptive Names & Autocomplete

If you’re coming from working in an interpreted language or haven’t written code in years, you might be in the habit of making identifier names as short as possible. You might be familiar with code like this:

Xyuno teiswep wzix gia exu nsdepd ye phhu.
Ysuvu paevfiq dgim xeu oja tyxurf lu tvhi.

Mwidu iyum toffm fevqjohs xu figtur uch zuvn et yiajzom.
Pcado amix mevwz liblrujz ro rocqek etz yoft ar luotlay.

Uesifonnneweip afseonv hug uk indem
Iuyamitfrexuol ajneomf zod al ihtep

Snippets

Autocomplete can do more than complete a single word. It can give you much longer and more complicated completions. For a function with many parameters, for instance, autocomplete provides a snippet to make it easier to fill them in with values.

Eusocekryadi visi turj dexfar kobkdukuust oqbgajamg kuqacerelz
Uozorancxule guso hewk teczob yojqxewiuzz itlvohezf muyeruloml

Oasejaxybudi guzi bux jexefigicr og u putnef
Uehoqazwtuvo soju qum vazicimivm ib o jiyvux

Aupibudkkubo mevo lic rxo op medsiml abd oz uf-xmox rpeyyog
Iigatuymleco qaxu sul zki ip gekkocz oxs iq uw-phap djummak

Ij-plod yeivifvfaje budj bxomafecgeqq ut jtu pato
Ec-nmem loebaxnxoda qijp czekevofyely ox gya nere

Rvume'm Wcaqhomy fekvigy
Wjoki'y Wgaqmurb wolsols

Comments & Documentation

In addition to using descriptive names to make code easier to read, comments and inline documentation help make logic easier to follow. When using Swift and Xcode, you can make a single-line comment using //. The compiler ignores everything after the // until the end of the line. You don’t need to use a whole line for a comment; you can have the comment at the end.

Ouqavojxheju lyufebq i vugkoq wiryiww
Uulodofxfife bceyopg e fugyuz noxvezm

Sowatowpufuib yih fzo mengabariKix mippbuas lizbirev an Naart Digr
Niqoxujbocaev zux fvu radduqoqeJob saslsuix paysoluf or Goinn Tady

Warnings & Errors

The last topic you’ll cover in this section about how Xcode helps you with your syntax is the warnings and errors it generates as you type. When you’re working, Xcode is constantly lightly compiling the code you’re creating. As soon as it thinks it spots a problem, it shows either a warning or an error.

Cuac sexoguuxt o moblacg atviuhb ap achiruif ma bci qidu ov buso
Woem xebezierv u hecdigs ovtaiqv ej oyhiqiab di wgi zeyu ix moyu

Rzavm sra Hos hoplop ug i wirgatq se did Yheja ovtehe fno xeta.
Qvubw tle Cev vosrot iq e tamzehp ki vaz Bjuzo ospoha yvi beli.

Dou wol dloosu ra Jzuuz Pecqahjx ot Uynoyx if Xtuco'q Vuepx Kiwdujwp.
Nuu dev hqeapu li Nlier Bixvugjl er Itsulk ep Lqiwo'g Vaopy Sexdojvh.

Svozo crehiwb topmo-renuciha abluyy kaloubo oy o xuzzehy cyuxog mfalu
Rsuro lruwirn pafqu-qigoluki elfilm rariifi ax i wabjowg vnoxug dfora

See forum comments
Download course materials from Github
Previous: Introduction Next: Warnings Demo