iOS Best Practices. Part 1: Objective-C Code Style

Maksim Vialykh
2 min readNov 15, 2017

--

Don’t scold the code — make it better.

Every day more and more people become developers.

Of course, iOS development is a trend now:).

The common sense in programming is that we should write readable code. After us, the code we left should be easily understandable and supportable by each and every programmer.

1. The first important thing is Code Style

Start from Code Style

I started with Objective-C.

At the moment, less and less projects use this language, but let’s go through the style for Objective-C.

Do not stretch the code vertically — for a long time monitors are able to fit readable horizontal lines.

dot notation, spaceing, conditions

Use ternary operator only for a single condition, don’t stretch for 2 and more conditions.

Add space after the scope in method signature.

ternary operator, methods, variables

Naming: Don’t spare letters and use distinct names.

Create Category for strong segmented functionality.

Write the code that is easy to understand.

naming, categories

Comments, in my mind, are unnecessary. Decompose code into small separated modules with single responsibility.

Use literals when you work with collections.

Collect all global values in Constants file.

no comments, constants

Use boolean variables reasonably.
Monitor the list of imports, do not overload the code with surpluses.

booleans, imports

Of course, it isn’t something new in code style, just a collection of best pieces of advice.

To be continued…

Part 2: Swift Code Style

--

--