Skip to content

Instantly share code, notes, and snippets.

@perezpaya
Last active March 7, 2022 01:20
Show Gist options
  • Save perezpaya/e02df7d853292e52ce6b to your computer and use it in GitHub Desktop.
Save perezpaya/e02df7d853292e52ce6b to your computer and use it in GitHub Desktop.

How to iOS

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.

Please remember

  • 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

Git flow is an extension to the Git CLI to make your life easier when following a successful branching model

Recommended read.

There's a bunch of different branches that will help you organize your code:

Master branch

Code running in production, tag version when merging.

Release branch

Branch where the release is prepared to be merged into master.

Integration branch

Stable branch that we use as the parent of multiple feature/bug/support branches, eventually merging it into release.

Feature/bug/support branch

Branch that will be merged with the integration branch or another child of the integration branch after code review.

Hotfix branch

Branch with hotfix- prefix name. It can be merged directly into master and tagged as a new version.

Storyboards

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.

Related read.

rockSOLIDness

Object oriented design pattern.

Basic concept: https://en.wikipedia.org/wiki/SOLID_(object-oriented_design)

Principles:

No more MVC (Massive View Controllers), use VIPER

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.

VIPER

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

Testing: TDD, CI and more

Test Driven Development

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.

Unit testing

  • 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.

Dependency injection

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:

You might need to use an injector. Some popular choices are:

UI Testing

Bad and good practices, why writing tests saves you time and makes your code more maintainable

https://www.objc.io/issues/15-testing/bad-testing-practices/

Continuous Integration

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

Automation

Fastlane

  • Tests
  • Screenshots
  • Certificates
  • Provisioning Profiles
  • Testflight
  • Much more...

Code signing

Avoid using Xcode codesigning help tools, especially that [Fix Issues] button.

Here's a recommended read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment