Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 56 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The official 33Devs Objective-C style guide.
# The official Techery Objective-C style guide.

This style guide outlines the coding conventions for 33Devs organization.
This style guide outlines the coding conventions for Techery organization.

## Introduction

Expand All @@ -10,7 +10,7 @@ This style guide is different from other Objective-C style guides you may see, b

## Credits

We would like to thank the creators of the [New York Times](https://github.com/NYTimes/objective-c-style-guide) and [raywenderlich.com](https://github.com/raywenderlich/objective-c-style-guide) Objective-C Style Guides. These two style guides provided a solid starting point for this guide to be created and based upon.
We would like to thank the creators of the [New York Times](https://github.com/NYTimes/objective-c-style-guide), [raywenderlich.com](https://github.com/raywenderlich/objective-c-style-guide) and [33Devs](https://github.com/33devs/Objective-C-Code-Style-Guide) Objective-C Style Guides. These two style guides provided a solid starting point for this guide to be created and based upon.

## Background

Expand Down Expand Up @@ -189,14 +189,14 @@ UIButton *settingsButton;
UIButton *setBut;
```

A three letter prefix should always be used for class names and constants, however may be omitted for Core Data entity names. For any official 33Devs projects the prefix 'TTD' or 'TEA' should be used.
A three letter prefix should always be used for class names and constants, however may be omitted for Core Data entity names. For any official Techery projects the prefix 'TEC' or 3 letters that can be identify project should be used.

Constants should be camel-case with all words capitalized and prefixed by the related class name for clarity.

**Preferred:**

```objc
static NSTimeInterval const TTDViewControllerNavigationFadeAnimationDuration = 0.3;
static NSTimeInterval const TECViewControllerNavigationFadeAnimationDuration = 0.3;
```

**Not Preferred:**
Expand Down Expand Up @@ -264,7 +264,7 @@ Direct access to instance variables that 'back' properties should be avoided exc
**Preferred:**

```objc
@interface TTDObject : NSObject
@interface TECObject : NSObject

@property (nonatomic, strong) NSString *objectName;

Expand All @@ -274,7 +274,7 @@ Direct access to instance variables that 'back' properties should be avoided exc
**Not Preferred:**

```objc
@interface TTDObject : NSObject {
@interface TECObject : NSObject {
NSString *objectName;
}
```
Expand Down Expand Up @@ -357,20 +357,20 @@ NSNumber *buildingStreetNumber = [NSNumber numberWithInteger:10018];

## Constants

Constants are preferred over in-line string literals or numbers, as they allow for easy reproduction of commonly used variables and can be quickly changed without the need for find and replace. Constants should be declared as `static` constants and not `#define`s unless explicitly being used as a macro.
Constants are preferred over in-line string literals or numbers, as they allow for easy reproduction of commonly used variables and can be quickly changed without the need for find and replace. Constants should be declared as `static` constants and not `#define`s unless explicitly being used as a macro. If `static` constants should be used in other classes they should be predeclared in headers as `extern` constants.

**Preferred:**

```objc
static NSString * const TTDAboutViewControllerCompanyName = @"33Devs";
static NSString * const TECAboutViewControllerCompanyName = @"Techery";

static CGFloat const TTDImageThumbnailHeight = 50.0;
static CGFloat const TECImageThumbnailHeight = 50.0;
```

**Not Preferred:**

```objc
#define CompanyName @"33Devs"
#define CompanyName @"Techery"

#define thumbnailHeight 2
```
Expand All @@ -382,21 +382,21 @@ When using `enum`s, it is recommended to use the new fixed underlying type speci
**For Example:**

```objc
typedef NS_ENUM(NSInteger, TTDLeftMenuTopItemType) {
TTDLeftMenuTopItemMain,
TTDLeftMenuTopItemShows,
TTDLeftMenuTopItemSchedule
typedef NS_ENUM(NSInteger, TECLeftMenuTopItemType) {
TECLeftMenuTopItemMain,
TECLeftMenuTopItemShows,
TECLeftMenuTopItemSchedule
};
```

You can also make explicit value assignments (showing older k-style constant definition):

```objc
typedef NS_ENUM(NSInteger, TTDGlobalConstants) {
TTDPinSizeMin = 1,
TTDPinSizeMax = 5,
TTDPinCountMin = 100,
TTDPinCountMax = 500,
TECPinSizeMin = 1,
TECPinSizeMax = 5,
TECPinCountMin = 100,
TECPinCountMax = 500,
};
```

Expand All @@ -414,25 +414,27 @@ enum GlobalConstants {

## Case Statements

Braces are not required for case statements, unless enforced by the complier.
When a case contains more than one line, braces should be added.
Braces are required for case statements.

```objc
switch (condition) {
case 1:
case 1: {
// ...
break;
}
case 2: {
// ...
// Multi-line example using braces
break;
}
case 3:
case 3: {
// ...
break;
default:
}
default: {
// ...
break;
}
}

```
Expand All @@ -456,16 +458,16 @@ switch (condition) {
When using an enumerated type for a switch, 'default' is not needed. For example:

```objc
TTDLeftMenuTopItemType menuType = TTDLeftMenuTopItemMain;
TECLeftMenuTopItemType menuType = TECLeftMenuTopItemMain;

switch (menuType) {
case TTDLeftMenuTopItemMain:
case TECLeftMenuTopItemMain:
// ...
break;
case TTDLeftMenuTopItemShows:
case TECLeftMenuTopItemShows:
// ...
break;
case TTDLeftMenuTopItemSchedule:
case TECLeftMenuTopItemSchedule:
// ...
break;
}
Expand All @@ -474,12 +476,12 @@ switch (menuType) {

## Private Properties

Private properties should be declared in class extensions (anonymous categories) in the implementation file of a class. Named categories (such as `TTDPrivate` or `private`) should never be used unless extending another class. The Anonymous category can be shared/exposed for testing using the <headerfile>+Private.h file naming convention.
Private properties should be declared in class extensions (anonymous categories) in the implementation file of a class. Named categories (such as `TECPrivate` or `private`) should never be used unless extending another class. The Anonymous category can be shared/exposed for testing using the <headerfile>+Private.h file naming convention.

**For Example:**

```objc
@interface TTDDetailViewController ()
@interface TECDetailViewController ()

@property (nonatomic, strong) GADBannerView *googleAdView;
@property (nonatomic, strong) ADBannerView *iAdView;
Expand Down Expand Up @@ -651,7 +653,8 @@ When methods return an error parameter by reference, switch on the returned valu
**Preferred:**
```objc
NSError *error;
if (![self trySomethingWithError:&error]) {
BOOL tryingResult = [self trySomethingWithError:&error];
if (!tryingResult) {
// Handle Error
}
```
Expand Down Expand Up @@ -700,6 +703,27 @@ self.productsRequest = [[SKProductsRequest alloc]
initWithProductIdentifiers:productIdentifiers];
```

## Method qualifier

It should contain one space after qualifier and *NO* space after method return type

For example:
```objc
- (void)someMethod;
- (NSString *)stringReturnMethod;
+ (id)someStaticMethod;
```
**Not Preferred:**
```objc
-(void)someMethod;
-(void) method;
- (void) anotherMethod;
```

## Project Structure

*TODO*


## Xcode project

Expand All @@ -711,6 +735,7 @@ When possible, always turn on "Treat Warnings as Errors" in the target's Build S

Some other style guides that were used and processed for writing this guide:

* [33Devs](https://github.com/33devs/Objective-C-Code-Style-Guide)
* [raywenderlich.com](https://github.com/raywenderlich/objective-c-style-guide)
* [Robots & Pencils](https://github.com/RobotsAndPencils/objective-c-style-guide)
* [New York Times](https://github.com/NYTimes/objective-c-style-guide)
Expand Down