Even though Android applications were downloaded two times more often than iOS apps in 2017, the latter are also widely popular. Nevertheless, the popularity of Apple devices is growing, and so is the demand for iOS developers. If you are or want to be one of them, this article is for you, because I will show you the best iOS practices. They will help you to develop better applications. Ready?
I have divided the practices mentioned above into the following sections:
- General Technological Concepts
- Code Quality
- Other useful tips and tricks
General Technological Concepts
In this section, I have just three words for you:
- SOLID – Single responsibility principle, Open/closed principle, Liskov substitution principle, Interface segregation principle, Dependency Inversion principle
- KISS – Keep It Simple, Stupid
- DRY – Don’t Repeat Yourself
First of all, you should follow code styling guides prepared for Swift and Objective-C. This matters a lot, especially when only a few programmers are developing the same application. It’s like starting a music band – if everybody does their own thing, they won’t succeed, and the same goes for developer teams.
If you can repeat advice from these guides in the middle of the night, you can move on to the next step – automating your builds. Use Fastlane to configure every project to build automatically, and then upload it to HockeyApp.
Finally, avoid a vast amount of code in a single view controller. You can use either VIPER or MVVM architecture to accomplish this.
Performance and maintainability
Although iOS devices are pretty fast and they work great no matter how old they are, your application can’t slow them down.
You can improve performance and maintainability of your application by:
- Trying to avoid external UI libraries
- Deciding on the minimum iOS version early on – remember to check if new iOS APIs are being handled properly on older systems
- Integrating crash reporting tools
Use these frameworks to make your work easier, faster and better.
Start your project by structuring it logically. Its structure should reflect the directory structure in your repository. Regarding folder names – they should be lowercase, and spaces should be replaced with “_”.
Make the project’s hierarchy reflect your architecture, i.e.:
- UI: contains references to custom UIViews, UIViewControllers and containers:
- Views: Custom UIViews, UITableViewCells, …
- View_controllers: UIViewControllers
- Application: AppDelegate
- Supporting_files: info.plist and other files describing the application
- Resources: fonts, images, videos
- 3rd_party: library that can’t be added as pod
- Connection: to your web service
- Managers: link between UI and Connection layers
- Parsers: data parsers
- Utils: utility classes that are being used throughout the project
Dependency Injection is the next useful and crucial thing. One of its definitions states that it’s a technique whereby one object supplies the dependencies of another object. One more thing to remember – any required objects should be passed as parameters.
If you want to manage an external dependency, use an explicit version of CocoaPods or Carthage, and update it only if necessary. And if you decide to use Pods, don’t add its folder to .gitignore.
Other useful tips and tricks
The final section and four simple tips and tricks to improve your applications even more:
- Avoid using Storyboards
- Use Workflows or FlowControllers to handle View Controllers
- Any text that is visible to the user should be localized
- Treat warnings as errors