Dear iOS Developer,
These are the things you might take into account when developing rock-solid iOS apps.
Writing better code makes you happy and will make your employer, teammates, and even customers happier in the mid-long term.
- You are not working alone.
- You should respect other people's work.
- Be kind whenever someone makes a mistake and try to make them understand their error.
- objc.io is your bro.
Git flow is an extension to the Git CLI to make your life easier when following a successful branching model
There's a bunch of different branches that will help you organize your code:
Code running in production, tag version when merging.
Branch where the release is prepared to be merged into master.
Stable branch that we use as the parent of multiple feature/bug/support branches, eventually merging it into release.
Branch that will be merged with the integration branch or another child of the integration branch after code review.
Branch with hotfix-
prefix name. It can be merged directly into master and tagged as a new version.
Using Interface Builder is cool, but having a single storyboard with 300 View Controllers and arrows all over the place is pretty messy and unmaintainable. In addition to that, you'll most likely get a Git conflict when someone makes a change in the storyboard file (probably every time you merge a branch).
Make your life easier:
- If you are a storyboard guy, and you prefer to keep using them, you could try to use multiple storyboards and use one storyboard for each user story, grouping just screens regarding a feature or multiple related actions. You can also use a nested storyboard via storyboard references (since iOS 9 SDK) to avoid monolithic storyboards.
- If you are an IB fan you can use xib files. Create a xib file for your View/View Controller and keep enjoying the tools.
- Otherwise, you can build your views programatically. If you choose this way please use an Auto Layout wrapper. 800 lines of vanilla view constraints are so unmaintainable.
Object oriented design pattern.
Basic concept: https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)
Principles:
- Single Responsibility Principle Slideshare -> Simple as Fuck
- Open/closed
- Liskov substitution
- Interface segregation
- Dependency inversion
Every framework/platform has its bad practices. If you've ever worked with Rails, you've probably ended up with monolithic models, with all the business logic and code mixed up in the same place. If you've done MVC in iOS, you might have ended up with Massive View Controllers, accessing DB, making requests, drawing interfaces, and presenting data all at once.
Why VIPER?
- It is easy.
- It respects SRP.
- It is TDD friendly.
Read before: https://www.objc.io/issues/13-architecture/viper/
- View
- Interactor
- Presenter
- Entity
- Routing
Write tests and then write the code to make them pass.
Write unit tests, UI tests and make sure you fix your code to make your branch pass successfully through all the tests.
You should implement CI in your repository to make sure you are not merging any broken code. Please, run tests locally to make sure you are not making your code-reviewer lose time.
Here's a interesting blog covering this topic.
- Write tests for a single class, not its dependencies.
- Make sure your class is working correctly.
- Every single method should be tested, but that's not a problem because you are doing TDD the right way :P
But wait a minute... I can't write unit tests, my dependencies are walking all around the code! Well, that's because you are doing dependency injection incorrectly or you are simply not doing it.
Some tools like Quick or Nimble might help you. We all know XCTests suck.
We are unit testing, right? So you are testing a single class, not all it's dependencies. You should be using dependency injection to modify dependencies so you can test your class in different scenarios and modify the state of its dependencies.
In fact, you might be doing dependency injection without knowing it.
Deep explanation and examples:
- https://www.objc.io/issues/15-testing/dependency-injection/
- http://natashatherobot.com/unit-testing-swift-dependency-injection/
You might need to use an injector. Some popular choices are:
https://www.objc.io/issues/15-testing/bad-testing-practices/
Make sure your tests pass so you can avoid most of integration causes bugs. When code reviewing, make sure your code works and that new feature won't break your app.
- TravisCI
- CircleCI
- Many others
- Tests
- Screenshots
- Certificates
- Provisioning Profiles
- Testflight
- Much more...
Avoid using Xcode codesigning help tools, especially that [Fix Issues] button.
Here's a recommended read.