5 tips your future self will thank you for…
2 min readMar 8, 2016
In the last years of developing for iPhone I’ve learned from my mistakes. I want to share the Top 5 (very trendy, I know…) things you should do in order for your future self not to build a time machine just to come and punch yourself in the face (I will do this, I am working on it, just miss the flux capacitor)!
- No Singleton. Just No. You don’t have ONE navigation controller. Yes you might have one instance of it running at a specific time maybe, but there is no need to keep the same one in memory. If one of your view controllers is a singleton, you have a serious problem. Never in 7 years of iOS Development have I said to myself: “Oh my! I am so glad I made this class a Singleton”.
- Lightweight UIViewControllers. Do not put the parsing / data processing logic in your View Controller, keep it in a dedicated class. When you need to change your view for the iPad 5 3D, you will be glad just to implement a new UI using a separate class that provides the data. Also you get a mega bonus: unit testing is super easy! Think of it this way: Every time your view controller is longer than 300 lines, a baby seal dies in terrible pain.
- Tests. Tests, tests. When you optimized your AwesomeParser2000 using the GPU to speed it up, some unit tests will help you to make sure you didn’t break anything else.
- Do not over-engineer, make things easy to change. Ok this is a tricky one. Let’s say that you code something where you know the implementation can change in the future. Refrain from making an abstract class that needs to be implemented etc (I’m looking at you Java/C++ people). Just use a protocol. Easy! Look at the UITableViewDatasource for example. Also on this note, avoid too many dependencies (more on this in a future article).
- Auto layout & Interface Builder. I hated Interface Builder (IB)… Really. That was with Xcode 3. Nothing much has changed since then except that it crashes less. I guess I changed. I stopped trying to fight it and instead I am going with it. It taught me something I believe is a life saver: separate UI from Code. IB + Auto Layout (kinda) forces you to do that. I read some of my old projects where I didn’t use XIBs and I want to punch my past-self.
I am waiting my future self to come at any moment to punch me for the dumb things I am still doing. Meanwhile I am still learning.
If you enjoyed this post, please recommend it (by clicking the ❤ button), it means a lot!