Top 10 Ground Rules for iOS Developers

What I’ve learned so far | Update on May 14th, 2017

Bob Lee
Bob the Developer

--

The most sold book in the world by the Guinness World Records.

You’ve been around with Swift for a couple of weeks. But, you feel like you aren’t sure whether you produce decent stuff. You ask these questions, “Are they good looking? Readable? How do others go about?” Certainly, there are a couple unspoken/spoken rules. So, I wrote this tutorial for you.☝️ I’ve attached my YouTube lessons and articles here and there, so check them out if you need to.

Disclaimer: This list purely comes from my brain. It’s about what it feels like to be an okay Swift developer. I’m biased. This is what I’ve found after having read the Swift documentation and WWDC videos while preparing my courses and making apps.

1. Indentation, not Swifty enough.

I’ve seen too many developers writing code like this below,

func neverDoThis() 
{
let fuglyCode = true
if (fuglyCode == true)
{
print("This is atrocious")
}
}

If I see the type of code above, I judge real hard.🤔 I assume that he/she has never read the API guideline/documentation or anyone’s Swift code before. Let’s take a look at how Apple engineers at WWDC would write.

// How Swift engineers would write
func swiftyWay() {
let isLegit = true
if isLegit {
print("This is fine")
}
}

If you spot anyone using the atrocious way, smack him in the head (gently)

Resources

Swift 3 Styling Guide Lesson (YouTube)

2016 WWDC Swift API Design Guidelines (YouTube)

2, Never Use Try!, as!, String! Unless %100 Sure

If you’ve been around, make sure you understand the differences between,

as as! as?

try try! try?

Int Int! Int?

If you don’t know what the heck you are doing and you resort to those 😡s on the left side of Xcode, you are bound to see that, “Found unexpected nil” message. Stop being passive. Move your butt and understand what they mean. Especially for those who took beginner courses on Udemy (including myself), you need to figure out your own.

Resources

Learn Swift with Bob (Udemy)

3. Never make function more than 20 lines

My friend asked me to review his code yesterday. One function had 50 lines. It covered the entire Xcode black screen. I was like, this shit isn’t going anywhere. I told him, “I don’t want to read your code because your code is fucking ugly”. I told him to break it into pieces and modularize. The truth hurts but he is my friend and I needed to be real and clear. No bullshit trying to please him.

For example, instead of writing something like this, although the below is not too crazy,

An example of GCD Code

Break it down into pieces.

Nice and Neat

4. UI Main Thread, Networking Background Thread

The concept of mult-threatding (a group of tasks done by CPU) is daunting. I don’t blame you. I don’t have a computer engineering background, and I still don’t know much of it.

I wrote two articles why you need to use the main thread for UI updates and the background threads for networking. So, I will skip this part.

Resources

Intro to Grand Dispatch Central with Bob (Medium)

UI and Networking like a Boss in Swift 3 (Part 2) (Medium)

The content has been migrated from Medium to the personal blog. If you wish to finish reading this article about 10 ground rules, feel free to visit here.

--

--