Contents
  1. 1. Architecture
  2. 2. Name it right
  3. 3. Project structure
  4. 4. Functional Reactive Programming
  5. 5. Unidirectional data flow
  6. 6. Data manipulation
  7. 7. Prefer decoration over extension
  8. 8. Mixin
  9. 9. IoC container
  10. 10. Single Responsibility Principle
  11. 11. Performance
  12. 12. Main thread
  13. 13. Overlay app icon with build information
  14. 14. Show TODO FIXME as warnings
  15. 15. Breakpoints
  16. 16. Code snippets
  17. 17. Utility class
  18. 18. Xcode plugins
  19. 19. Xcode keyboard shortcuts
  20. 20. xcconfig
  21. 21. Strongly typed resource
  22. 22. Continuous learning
  23. 23. Reference

Here are practices I found useful when developing iOS.
They can be tools or framework that greatly affect your style. Sometimes, it applies to other platform as well

Architecture

We’re always looking for ways to structure our apps better, I collect some cool stuffs in ios-architecture

Name it right

Naming is hard. But we can start by naming correctly and with correct spelling. The best way is to stick with the platform naming convention

Project structure

Some prefer to group their projects by object role, like Model, View, View Controller. But I prefer to group by feature or use case, learning from Clean Architecture

  • When you look at a software system, and all you see is MCV in a web configuration, then the architecture of that system is hiding the use cases of that system and exposing the delivery mechanism.

I often group my code like this

  • Share: Contains code that can be useful to other project. Not related to any project. Can be extract to a Pod
  • Engine: Contains code that is specific to this project. Like UserManager, ViewAnimator, …
  • Modules: Separate each screen into module. In each module, there are view, view model and wireframe

There are some architectures like MVC, MVVM, VIPER, VIP, … and you may want to leverage some templates to help creating projects faster, like

And learn how to make them

  • Custom Xcode File Templates

There are also some scripts to bootstrap your project

  • crafter Crafter - Xcode project configuration CLI made easy
  • xcake Create your Xcode projects automatically using a stupid simple DSL.
  • liftoff CLI for creating and configuring new Xcode projects

Functional Reactive Programming

The Reactive Extension inspired libraries are cool, and they greatly changes the way you develop, especially signal chaining

Unidirectional data flow

Another trend is React inspired libraries, which encourage Unidirectional data flow

Data manipulation

Leverage some functional style for better data manipulation

  • Swiftz It defines functional data structures, functions, idioms, and extensions that augment the Swift standard library.
  • Dollar.swift A functional tool-belt for Swift Language similar to Lo-Dash or Underscore.js in Javascript

Prefer decoration over extension

This maybe subjective. But in some case decoration wins

Often when we want to add custom color, font or animate a view, or custom NSDateFormatter, we often make categories on UIColor, UIFont, UIView, NSDateFormatter, …

But most of the case, we can group them inside class, like ColorBucket, FontBucket, ViewAnimator, DateFormatterBucket, …

So, instead of

1
2
3
4
5
@interface UIColor (Additions)

- (UIColor *)customColor;

@end

We can have ColorBucket

1
2
3
4
5
@interface ColorBucket

+ (UIColor *)customColor;

@end

Mixin

  • Mixins and Traits in Swift 2.0

Another way to add functionality to an entity is mixin, which is cool

IoC container

Usage of IoC container can greatly change the app workflow, which praises Dependency Injection

Single Responsibility Principle

Always keep this in mind :]

Performance

Understanding of performance issue, especially some common uses like tableview pre rendering, helps

Main thread

It’s good to care about our main thread so see if it is blocked

Overlay app icon with build information

Show TODO FIXME as warnings

Use this script in Run Script Build Phase

1
2
KEYWORDS="TODO:|VERIFY:|FIXME:|\?\?\?:|\!\!\!:"
find "${SRCROOT}" -name "*.h" -or -name "*.m" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($KEYWORDS).*\$" | perl -p -e "s/($KEYWORDS)/ warning: \$1/"

Breakpoints

There are some common needed breakpoints, like Breakpoints_v2.xcbkptlist

Code snippets

Code snippets auto generate common code

Utility class

We can avoid duplicated helper classes in projects by using some cool frameworks

  • Sugar Sugar is a sweetener for your Cocoa implementations.

Xcode plugins

Using Xcode plugins can boost your productivity

And learning to write your own can assist you with more tasks

Xcode keyboard shortcuts

Navigate faster

xcconfig

Build yourself some predefined xcconfig

Strongly typed resource

There’s some scripts that generate strongly typed resource classes

  • SwiftGen A collection of Swift tools to generate Swift code (enums for your assets, storyboards, Localizable.strings, …)
  • R.swift Get strong typed, autocompleted resources like images, fonts and segues in Swift projects

Continuous learning

Technologies move really fast. We must learn continuously. I have ios-resources to keep track of all the cool stuffs

Also, I leverage Github as my notes ios-issues

Reference

Contents
  1. 1. Architecture
  2. 2. Name it right
  3. 3. Project structure
  4. 4. Functional Reactive Programming
  5. 5. Unidirectional data flow
  6. 6. Data manipulation
  7. 7. Prefer decoration over extension
  8. 8. Mixin
  9. 9. IoC container
  10. 10. Single Responsibility Principle
  11. 11. Performance
  12. 12. Main thread
  13. 13. Overlay app icon with build information
  14. 14. Show TODO FIXME as warnings
  15. 15. Breakpoints
  16. 16. Code snippets
  17. 17. Utility class
  18. 18. Xcode plugins
  19. 19. Xcode keyboard shortcuts
  20. 20. xcconfig
  21. 21. Strongly typed resource
  22. 22. Continuous learning
  23. 23. Reference