10 Tips to become a better Swift Developer

Type less, read less, produce more | Update on May 14th, 2017

Bob Lee
Bob the Developer
3 min readNov 16, 2016

--

Not my desk

So, you’ve been around with Swift for a couple of months. Now, you want to become a better Swift Developer? DRY, KISS, and not WET? I’ve got golden nuggets here and there for you.

Excuse me for the formatting, I tried to have as fewer lines as possible for conciseness. Feel free to copy and paste into Playground to check if everything works. 👊 If not, please comment below. I will fix them asap.

I have also embedded YouTube lessons under each part for an explanation.

I talked too much. Let’s get started.

1. Extension

Ex) Square a number

The useless variable was created to double square 5— we need not enjoy typing.

Extension Lesson

2. Generics

Ex) Print all elements in an array

Too many useless functions. Let’s create just one.

Generic Lesson

3. For Loop vs While Loop

Ex) Print “Count” 5 times

You made the variable “i” to make sure your computer doesn’t break by printing limited numbers

Listen, more variables → more memorization → more headache → more bugs → more life problems.

Remember the Butterfly effect.

“Gorgeous” — Bob

For Loop Lesson

4. Optional Unwrapping

Ex) Gaurd let vs if let

Let’s make a program for welcoming a new user.

Do you see the pyramid of doom? Those are nasty nested code. Never. Destroy the bad, bring the good.

The difference is trendemous. If username or password has a nil value, the pretty code will early-exit the function by calling “return”. If not, it will print the welcoming message. No Pyramid. 🤘

The content has been migrated from Medium to personal platform. You can read the rest of the content about the other 6 Swift tips here

--

--