{"id":3296,"url":"https://github.com/kodecocodes/objective-c-style-guide","last_synced_at":"2026-03-14T13:34:38.722Z","repository":{"id":11692757,"uuid":"14204860","full_name":"kodecocodes/objective-c-style-guide","owner":"kodecocodes","description":"A style guide that outlines the coding conventions for Kodeco","archived":false,"fork":false,"pushed_at":"2017-10-01T12:49:18.000Z","size":639,"stargazers_count":3098,"open_issues_count":22,"forks_count":627,"subscribers_count":187,"default_branch":"master","last_synced_at":"2024-10-30T06:57:35.108Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://www.raywenderlich.com/62570/objective-c-style-guide","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kodecocodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-07T13:48:51.000Z","updated_at":"2024-10-28T18:54:45.000Z","dependencies_parsed_at":"2022-09-01T20:41:19.807Z","dependency_job_id":null,"html_url":"https://github.com/kodecocodes/objective-c-style-guide","commit_stats":null,"previous_names":["raywenderlich/objective-c-style-guide"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fobjective-c-style-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fobjective-c-style-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fobjective-c-style-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kodecocodes%2Fobjective-c-style-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kodecocodes","download_url":"https://codeload.github.com/kodecocodes/objective-c-style-guide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254292043,"owners_count":22046426,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-01-05T20:16:37.391Z","updated_at":"2025-12-17T00:30:18.700Z","avatar_url":"https://github.com/kodecocodes.png","language":null,"funding_links":[],"categories":["Style Guides","Others","HarmonyOS","Recently Updated","Programming Languages"],"sub_categories":["Other Xcode","Windows Manager","[Jul 10, 2024](/content/2024/07/10/README.md)","Objective-C"],"readme":"# The official raywenderlich.com Objective-C style guide.\n\nThis style guide outlines the coding conventions for raywenderlich.com.\n\n## Introduction\n\nThe reason we made this style guide was so that we could keep the code in our books, tutorials, and starter kits nice and consistent - even though we have many different authors working on the books.\n\nThis style guide is different from other Objective-C style guides you may see, because the focus is centered on readability for print and the web. Many of the decisions were made with an eye toward conserving space for print, easy legibility, and tutorial writing.\n\n## Credits\n\nThe creation of this style guide was a collaborative effort from various raywenderlich.com team members under the direction of Nicholas Waynik.  The team includes: [Soheil Moayedi Azarpour](https://github.com/moayes), [Ricardo Rendon Cepeda](https://github.com/ricardo-rendoncepeda), [Tony Dahbura](https://github.com/tdahbura), [Colin Eberhardt](https://github.com/ColinEberhardt), [Matt Galloway](https://github.com/mattjgalloway), [Greg Heo](https://github.com/gregheo), [Matthijs Hollemans](https://github.com/hollance), [Christopher LaPollo](https://github.com/elephantronic), [Saul Mora](https://github.com/casademora), [Andy Pereira](https://github.com/macandyp), [Mic Pringle](https://github.com/micpringle), [Pietro Rea](https://github.com/pietrorea), [Cesare Rocchi](https://github.com/funkyboy), [Marin Todorov](https://github.com/icanzilb), [Nicholas Waynik](https://github.com/ndubbs), and [Ray Wenderlich](https://github.com/raywenderlich)\n\nWe would like to thank the creators of the [New York Times](https://github.com/NYTimes/objective-c-style-guide) and [Robots \u0026 Pencils'](https://github.com/RobotsAndPencils/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.\n\n## Background\n\nHere are some of the documents from Apple that informed the style guide. If something isn't mentioned here, it's probably covered in great detail in one of these:\n\n* [The Objective-C Programming Language](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Introduction/introObjectiveC.html)\n* [Cocoa Fundamentals Guide](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaFundamentals/Introduction/Introduction.html)\n* [Coding Guidelines for Cocoa](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html)\n* [iOS App Programming Guide](http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/Introduction/Introduction.html)\n\n## Table of Contents\n\n* [Language](#language)\n* [Code Organization](#code-organization)\n* [Spacing](#spacing)\n* [Comments](#comments)\n* [Naming](#naming)\n  * [Underscores](#underscores)\n* [Methods](#methods)\n* [Variables](#variables)\n* [Property Attributes](#property-attributes)\n* [Dot-Notation Syntax](#dot-notation-syntax)\n* [Literals](#literals)\n* [Constants](#constants)\n* [Enumerated Types](#enumerated-types)\n* [Case Statements](#case-statements)\n* [Private Properties](#private-properties)\n* [Booleans](#booleans)\n* [Conditionals](#conditionals)\n  * [Ternary Operator](#ternary-operator)\n* [Init Methods](#init-methods)\n* [Class Constructor Methods](#class-constructor-methods)\n* [CGRect Functions](#cgrect-functions)\n* [Golden Path](#golden-path)\n* [Error handling](#error-handling)\n* [Singletons](#singletons)\n* [Line Breaks](#line-breaks)\n* [Smiley Face](#smiley-face)\n* [Xcode Project](#xcode-project)\n\n\n## Language\n\nUS English should be used.\n\n**Preferred:**\n```objc\nUIColor *myColor = [UIColor whiteColor];\n```\n\n**Not Preferred:**\n```objc\nUIColor *myColour = [UIColor whiteColor];\n```\n\n\n## Code Organization\n\nUse `#pragma mark -` to categorize methods in functional groupings and protocol/delegate implementations following this general structure.\n\n```objc\n#pragma mark - Lifecycle\n\n- (instancetype)init {}\n- (void)dealloc {}\n- (void)viewDidLoad {}\n- (void)viewWillAppear:(BOOL)animated {}\n- (void)didReceiveMemoryWarning {}\n\n#pragma mark - Custom Accessors\n\n- (void)setCustomProperty:(id)value {}\n- (id)customProperty {}\n\n#pragma mark - IBActions\n\n- (IBAction)submitData:(id)sender {}\n\n#pragma mark - Public\n\n- (void)publicMethod {}\n\n#pragma mark - Private\n\n- (void)privateMethod {}\n\n#pragma mark - Protocol conformance\n#pragma mark - UITextFieldDelegate\n#pragma mark - UITableViewDataSource\n#pragma mark - UITableViewDelegate\n\n#pragma mark - NSCopying\n\n- (id)copyWithZone:(NSZone *)zone {}\n\n#pragma mark - NSObject\n\n- (NSString *)description {}\n```\n\n## Spacing\n\n* Indent using 2 spaces (this conserves space in print and makes line wrapping less likely). Never indent with tabs. Be sure to set this preference in Xcode.\n* Method braces and other braces (`if`/`else`/`switch`/`while` etc.) always open on the same line as the statement but close on a new line.\n\n**Preferred:**\n```objc\nif (user.isHappy) {\n  //Do something\n} else {\n  //Do something else\n}\n```\n\n**Not Preferred:**\n```objc\nif (user.isHappy)\n{\n    //Do something\n}\nelse {\n    //Do something else\n}\n```\n\n* There should be exactly one blank line between methods to aid in visual clarity and organization. Whitespace within methods should separate functionality, but often there should probably be new methods.\n* Prefer using auto-synthesis. But if necessary, `@synthesize` and `@dynamic` should each be declared on new lines in the implementation.\n* Colon-aligning method invocation should often be avoided.  There are cases where a method signature may have \u003e= 3 colons and colon-aligning makes the code more readable. Please do **NOT** however colon align methods containing blocks because Xcode's indenting makes it illegible.\n\n**Preferred:**\n\n```objc\n// blocks are easily readable\n[UIView animateWithDuration:1.0 animations:^{\n  // something\n} completion:^(BOOL finished) {\n  // something\n}];\n```\n\n**Not Preferred:**\n\n```objc\n// colon-aligning makes the block indentation hard to read\n[UIView animateWithDuration:1.0\n                 animations:^{\n                     // something\n                 }\n                 completion:^(BOOL finished) {\n                     // something\n                 }];\n```\n\n## Comments\n\nWhen they are needed, comments should be used to explain **why** a particular piece of code does something. Any comments that are used must be kept up-to-date or deleted.\n\nBlock comments should generally be avoided, as code should be as self-documenting as possible, with only the need for intermittent, few-line explanations. *Exception: This does not apply to those comments used to generate documentation.*\n\n## Naming\n\nApple naming conventions should be adhered to wherever possible, especially those related to [memory management rules](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html) ([NARC](http://stackoverflow.com/a/2865194/340508)).\n\nLong, descriptive method and variable names are good.\n\n**Preferred:**\n\n```objc\nUIButton *settingsButton;\n```\n\n**Not Preferred:**\n\n```objc\nUIButton *setBut;\n```\n\nA three letter prefix should always be used for class names and constants, however may be omitted for Core Data entity names. For any official raywenderlich.com books, starter kits, or tutorials, the prefix 'RWT' should be used.\n\nConstants should be camel-case with all words capitalized and prefixed by the related class name for clarity.\n\n**Preferred:**\n\n```objc\nstatic NSTimeInterval const RWTTutorialViewControllerNavigationFadeAnimationDuration = 0.3;\n```\n\n**Not Preferred:**\n\n```objc\nstatic NSTimeInterval const fadetime = 1.7;\n```\n\nProperties should be camel-case with the leading word being lowercase. Use auto-synthesis for properties rather than manual @synthesize statements unless you have good reason.\n\n**Preferred:**\n\n```objc\n@property (strong, nonatomic) NSString *descriptiveVariableName;\n```\n\n**Not Preferred:**\n\n```objc\nid varnm;\n```\n\n### Underscores\n\nWhen using properties, instance variables should always be accessed and mutated using `self.`. This means that all properties will be visually distinct, as they will all be prefaced with `self.`. \n\nAn exception to this: inside initializers, the backing instance variable (i.e. _variableName) should be used directly to avoid any potential side effects of the getters/setters.\n\nLocal variables should not contain underscores.\n\n## Methods\n\nIn method signatures, there should be a space after the method type (-/+ symbol). There should be a space between the method segments (matching Apple's style).  Always include a keyword and be descriptive with the word before the argument which describes the argument.\n\nThe usage of the word \"and\" is reserved.  It should not be used for multiple parameters as illustrated in the `initWithWidth:height:` example below.\n\n**Preferred:**\n```objc\n- (void)setExampleText:(NSString *)text image:(UIImage *)image;\n- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag;\n- (id)viewWithTag:(NSInteger)tag;\n- (instancetype)initWithWidth:(CGFloat)width height:(CGFloat)height;\n```\n\n**Not Preferred:**\n\n```objc\n-(void)setT:(NSString *)text i:(UIImage *)image;\n- (void)sendAction:(SEL)aSelector :(id)anObject :(BOOL)flag;\n- (id)taggedView:(NSInteger)tag;\n- (instancetype)initWithWidth:(CGFloat)width andHeight:(CGFloat)height;\n- (instancetype)initWith:(int)width and:(int)height;  // Never do this.\n```\n\n## Variables\n\nVariables should be named as descriptively as possible. Single letter variable names should be avoided except in `for()` loops.\n\nAsterisks indicating pointers belong with the variable, e.g., `NSString *text` not `NSString* text` or `NSString * text`, except in the case of constants.\n\n[Private properties](#private-properties) should be used in place of instance variables whenever possible. Although using instance variables is a valid way of doing things, by agreeing to prefer properties our code will be more consistent. \n\nDirect access to instance variables that 'back' properties should be avoided except in initializer methods (`init`, `initWithCoder:`, etc…), `dealloc` methods and within custom setters and getters. For more information on using Accessor Methods in Initializer Methods and dealloc, see [here](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmPractical.html#//apple_ref/doc/uid/TP40004447-SW6).\n\n**Preferred:**\n\n```objc\n@interface RWTTutorial : NSObject\n\n@property (strong, nonatomic) NSString *tutorialName;\n\n@end\n```\n\n**Not Preferred:**\n\n```objc\n@interface RWTTutorial : NSObject {\n  NSString *tutorialName;\n}\n```\n\n\n## Property Attributes\n\nProperty attributes should be explicitly listed, and will help new programmers when reading the code.  The order of properties should be storage then atomicity, which is consistent with automatically generated code when connecting UI elements from Interface Builder.\n\n**Preferred:**\n\n```objc\n@property (weak, nonatomic) IBOutlet UIView *containerView;\n@property (strong, nonatomic) NSString *tutorialName;\n```\n\n**Not Preferred:**\n\n```objc\n@property (nonatomic, weak) IBOutlet UIView *containerView;\n@property (nonatomic) NSString *tutorialName;\n```\n\nProperties with mutable counterparts (e.g. NSString) should prefer `copy` instead of `strong`. \nWhy? Even if you declared a property as `NSString` somebody might pass in an instance of an `NSMutableString` and then change it without you noticing that.  \n\n**Preferred:**\n\n```objc\n@property (copy, nonatomic) NSString *tutorialName;\n```\n\n**Not Preferred:**\n\n```objc\n@property (strong, nonatomic) NSString *tutorialName;\n```\n\n## Dot-Notation Syntax\n\nDot syntax is purely a convenient wrapper around accessor method calls. When you use dot syntax, the property is still accessed or changed using getter and setter methods.  Read more [here](https://developer.apple.com/library/ios/documentation/cocoa/conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html)\n\nDot-notation should **always** be used for accessing and mutating properties, as it makes code more concise. Bracket notation is preferred in all other instances.\n\n**Preferred:**\n```objc\nNSInteger arrayCount = [self.array count];\nview.backgroundColor = [UIColor orangeColor];\n[UIApplication sharedApplication].delegate;\n```\n\n**Not Preferred:**\n```objc\nNSInteger arrayCount = self.array.count;\n[view setBackgroundColor:[UIColor orangeColor]];\nUIApplication.sharedApplication.delegate;\n```\n\n## Literals\n\n`NSString`, `NSDictionary`, `NSArray`, and `NSNumber` literals should be used whenever creating immutable instances of those objects. Pay special care that `nil` values can not be passed into `NSArray` and `NSDictionary` literals, as this will cause a crash.\n\n**Preferred:**\n\n```objc\nNSArray *names = @[@\"Brian\", @\"Matt\", @\"Chris\", @\"Alex\", @\"Steve\", @\"Paul\"];\nNSDictionary *productManagers = @{@\"iPhone\": @\"Kate\", @\"iPad\": @\"Kamal\", @\"Mobile Web\": @\"Bill\"};\nNSNumber *shouldUseLiterals = @YES;\nNSNumber *buildingStreetNumber = @10018;\n```\n\n**Not Preferred:**\n\n```objc\nNSArray *names = [NSArray arrayWithObjects:@\"Brian\", @\"Matt\", @\"Chris\", @\"Alex\", @\"Steve\", @\"Paul\", nil];\nNSDictionary *productManagers = [NSDictionary dictionaryWithObjectsAndKeys: @\"Kate\", @\"iPhone\", @\"Kamal\", @\"iPad\", @\"Bill\", @\"Mobile Web\", nil];\nNSNumber *shouldUseLiterals = [NSNumber numberWithBool:YES];\nNSNumber *buildingStreetNumber = [NSNumber numberWithInteger:10018];\n```\n\n## Constants\n\nConstants 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.\n\n**Preferred:**\n\n```objc\nstatic NSString * const RWTAboutViewControllerCompanyName = @\"RayWenderlich.com\";\n\nstatic CGFloat const RWTImageThumbnailHeight = 50.0;\n```\n\n**Not Preferred:**\n\n```objc\n#define CompanyName @\"RayWenderlich.com\"\n\n#define thumbnailHeight 2\n```\n\n## Enumerated Types\n\nWhen using `enum`s, it is recommended to use the new fixed underlying type specification because it has stronger type checking and code completion. The SDK now includes a macro to facilitate and encourage use of fixed underlying types: `NS_ENUM()`\n\n**For Example:**\n\n```objc\ntypedef NS_ENUM(NSInteger, RWTLeftMenuTopItemType) {\n  RWTLeftMenuTopItemMain,\n  RWTLeftMenuTopItemShows,\n  RWTLeftMenuTopItemSchedule\n};\n```\n\nYou can also make explicit value assignments (showing older k-style constant definition):\n\n```objc\ntypedef NS_ENUM(NSInteger, RWTGlobalConstants) {\n  RWTPinSizeMin = 1,\n  RWTPinSizeMax = 5,\n  RWTPinCountMin = 100,\n  RWTPinCountMax = 500,\n};\n```\n\nOlder k-style constant definitions should be **avoided** unless writing CoreFoundation C code (unlikely).\n\n**Not Preferred:**\n\n```objc\nenum GlobalConstants {\n  kMaxPinSize = 5,\n  kMaxPinCount = 500,\n};\n```\n\n\n## Case Statements\n\nBraces are not required for case statements, unless enforced by the complier.  \nWhen a case contains more than one line, braces should be added.\n\n```objc\nswitch (condition) {\n  case 1:\n    // ...\n    break;\n  case 2: {\n    // ...\n    // Multi-line example using braces\n    break;\n  }\n  case 3:\n    // ...\n    break;\n  default: \n    // ...\n    break;\n}\n\n```\n\nThere are times when the same code can be used for multiple cases, and a fall-through should be used.  A fall-through is the removal of the 'break' statement for a case thus allowing the flow of execution to pass to the next case value.  A fall-through should be commented for coding clarity.\n\n```objc\nswitch (condition) {\n  case 1:\n    // ** fall-through! **\n  case 2:\n    // code executed for values 1 and 2\n    break;\n  default: \n    // ...\n    break;\n}\n\n```\n\nWhen using an enumerated type for a switch, 'default' is not needed.   For example:\n\n```objc\nRWTLeftMenuTopItemType menuType = RWTLeftMenuTopItemMain;\n\nswitch (menuType) {\n  case RWTLeftMenuTopItemMain:\n    // ...\n    break;\n  case RWTLeftMenuTopItemShows:\n    // ...\n    break;\n  case RWTLeftMenuTopItemSchedule:\n    // ...\n    break;\n}\n```\n\n\n## Private Properties\n\nPrivate properties should be declared in class extensions (anonymous categories) in the implementation file of a class. Named categories (such as `RWTPrivate` or `private`) should never be used unless extending another class.   The Anonymous category can be shared/exposed for testing using the \u003cheaderfile\u003e+Private.h file naming convention.\n\n**For Example:**\n\n```objc\n@interface RWTDetailViewController ()\n\n@property (strong, nonatomic) GADBannerView *googleAdView;\n@property (strong, nonatomic) ADBannerView *iAdView;\n@property (strong, nonatomic) UIWebView *adXWebView;\n\n@end\n```\n\n## Booleans\n\nObjective-C uses `YES` and `NO`.  Therefore `true` and `false` should only be used for CoreFoundation, C or C++ code.  Since `nil` resolves to `NO` it is unnecessary to compare it in conditions. Never compare something directly to `YES`, because `YES` is defined to 1 and a `BOOL` can be up to 8 bits.\n\nThis allows for more consistency across files and greater visual clarity.\n\n**Preferred:**\n\n```objc\nif (someObject) {}\nif (![anotherObject boolValue]) {}\n```\n\n**Not Preferred:**\n\n```objc\nif (someObject == nil) {}\nif ([anotherObject boolValue] == NO) {}\nif (isAwesome == YES) {} // Never do this.\nif (isAwesome == true) {} // Never do this.\n```\n\nIf the name of a `BOOL` property is expressed as an adjective, the property can omit the “is” prefix but specifies the conventional name for the get accessor, for example:\n\n```objc\n@property (assign, getter=isEditable) BOOL editable;\n```\nText and example taken from the [Cocoa Naming Guidelines](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#//apple_ref/doc/uid/20001284-BAJGIIJE).\n\n## Conditionals\n\nConditional bodies should always use braces even when a conditional body could be written without braces (e.g., it is one line only) to prevent errors. These errors include adding a second line and expecting it to be part of the if-statement. Another, [even more dangerous defect](http://programmers.stackexchange.com/a/16530) may happen where the line \"inside\" the if-statement is commented out, and the next line unwittingly becomes part of the if-statement. In addition, this style is more consistent with all other conditionals, and therefore more easily scannable.\n\n**Preferred:**\n```objc\nif (!error) {\n  return success;\n}\n```\n\n**Not Preferred:**\n```objc\nif (!error)\n  return success;\n```\n\nor\n\n```objc\nif (!error) return success;\n```\n\n### Ternary Operator\n\nThe Ternary operator, `?:` , should only be used when it increases clarity or code neatness. A single condition is usually all that should be evaluated. Evaluating multiple conditions is usually more understandable as an `if` statement, or refactored into instance variables. In general, the best use of the ternary operator is during assignment of a variable and deciding which value to use.\n\nNon-boolean variables should be compared against something, and parentheses are added for improved readability.  If the variable being compared is a boolean type, then no parentheses are needed.\n\n**Preferred:**\n```objc\nNSInteger value = 5;\nresult = (value != 0) ? x : y;\n\nBOOL isHorizontal = YES;\nresult = isHorizontal ? x : y;\n```\n\n**Not Preferred:**\n```objc\nresult = a \u003e b ? x = c \u003e d ? c : d : y;\n```\n\n## Init Methods\n\nInit methods should follow the convention provided by Apple's generated code template.  A return type of 'instancetype' should also be used instead of 'id'.\n\n```objc\n- (instancetype)init {\n  self = [super init];\n  if (self) {\n    // ...\n  }\n  return self;\n}\n```\n\nSee [Class Constructor Methods](#class-constructor-methods) for link to article on instancetype.\n\n## Class Constructor Methods\n\nWhere class constructor methods are used, these should always return type of 'instancetype' and never 'id'. This ensures the compiler correctly infers the result type. \n\n```objc\n@interface Airplane\n+ (instancetype)airplaneWithType:(RWTAirplaneType)type;\n@end\n```\n\nMore information on instancetype can be found on [NSHipster.com](http://nshipster.com/instancetype/).\n\n## CGRect Functions\n\nWhen accessing the `x`, `y`, `width`, or `height` of a `CGRect`, always use the [`CGGeometry` functions](http://developer.apple.com/library/ios/#documentation/graphicsimaging/reference/CGGeometry/Reference/reference.html) instead of direct struct member access. From Apple's `CGGeometry` reference:\n\n\u003e All functions described in this reference that take CGRect data structures as inputs implicitly standardize those rectangles before calculating their results. For this reason, your applications should avoid directly reading and writing the data stored in the CGRect data structure. Instead, use the functions described here to manipulate rectangles and to retrieve their characteristics.\n\n**Preferred:**\n\n```objc\nCGRect frame = self.view.frame;\n\nCGFloat x = CGRectGetMinX(frame);\nCGFloat y = CGRectGetMinY(frame);\nCGFloat width = CGRectGetWidth(frame);\nCGFloat height = CGRectGetHeight(frame);\nCGRect frame = CGRectMake(0.0, 0.0, width, height);\n```\n\n**Not Preferred:**\n\n```objc\nCGRect frame = self.view.frame;\n\nCGFloat x = frame.origin.x;\nCGFloat y = frame.origin.y;\nCGFloat width = frame.size.width;\nCGFloat height = frame.size.height;\nCGRect frame = (CGRect){ .origin = CGPointZero, .size = frame.size };\n```\n\n## Golden Path\n\nWhen coding with conditionals, the left hand margin of the code should be the \"golden\" or \"happy\" path.  That is, don't nest `if` statements.  Multiple return statements are OK.\n\n**Preferred:**\n\n```objc\n- (void)someMethod {\n  if (![someOther boolValue]) {\n\treturn;\n  }\n\n  //Do something important\n}\n```\n\n**Not Preferred:**\n\n```objc\n- (void)someMethod {\n  if ([someOther boolValue]) {\n    //Do something important\n  }\n}\n```\n\n## Error handling\n\nWhen methods return an error parameter by reference, switch on the returned value, not the error variable.\n\n**Preferred:**\n```objc\nNSError *error;\nif (![self trySomethingWithError:\u0026error]) {\n  // Handle Error\n}\n```\n\n**Not Preferred:**\n```objc\nNSError *error;\n[self trySomethingWithError:\u0026error];\nif (error) {\n  // Handle Error\n}\n```\n\nSome of Apple’s APIs write garbage values to the error parameter (if non-NULL) in successful cases, so switching on the error can cause false negatives (and subsequently crash).\n\n\n## Singletons\n\nSingleton objects should use a thread-safe pattern for creating their shared instance.\n```objc\n+ (instancetype)sharedInstance {\n  static id sharedInstance = nil;\n\n  static dispatch_once_t onceToken;\n  dispatch_once(\u0026onceToken, ^{\n    sharedInstance = [[self alloc] init];\n  });\n\n  return sharedInstance;\n}\n```\nThis will prevent [possible and sometimes prolific crashes](http://cocoasamurai.blogspot.com/2011/04/singletons-your-doing-them-wrong.html).\n\n\n## Line Breaks\n\nLine breaks are an important topic since this style guide is focused for print and online readability.\n\nFor example:\n```objc\nself.productsRequest = [[SKProductsRequest alloc] initWithProductIdentifiers:productIdentifiers];\n```\nA long line of code like this should be carried on to the second line adhering to this style guide's Spacing section (two spaces).\n```objc\nself.productsRequest = [[SKProductsRequest alloc] \n  initWithProductIdentifiers:productIdentifiers];\n```\n\n\n## Smiley Face\n\nSmiley faces are a very prominent style feature of the raywenderlich.com site!  It is very important to have the correct smile signifying the immense amount of happiness and excitement for the coding topic.  The end square bracket is used because it represents the largest smile able to be captured using ascii art.  A half-hearted smile is represented if an end parenthesis is used, and thus not preferred.\n\n**Preferred:**\n```objc\n:]\n```\n\n**Not Preferred:**\n```objc\n:)\n```  \n\n\n## Xcode project\n\nThe physical files should be kept in sync with the Xcode project files in order to avoid file sprawl. Any Xcode groups created should be reflected by folders in the filesystem. Code should be grouped not only by type, but also by feature for greater clarity.\n\nWhen possible, always turn on \"Treat Warnings as Errors\" in the target's Build Settings and enable as many [additional warnings](http://boredzo.org/blog/archives/2009-11-07/warnings) as possible. If you need to ignore a specific warning, use [Clang's pragma feature](http://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas).\n\n# Other Objective-C Style Guides\n\nIf ours doesn't fit your tastes, have a look at some other style guides:\n\n* [Robots \u0026 Pencils](https://github.com/RobotsAndPencils/objective-c-style-guide)\n* [New York Times](https://github.com/NYTimes/objective-c-style-guide)\n* [Google](http://google-styleguide.googlecode.com/svn/trunk/objcguide.xml)\n* [GitHub](https://github.com/github/objective-c-conventions)\n* [Adium](https://trac.adium.im/wiki/CodingStyle)\n* [Sam Soffes](https://gist.github.com/soffes/812796)\n* [CocoaDevCentral](http://cocoadevcentral.com/articles/000082.php)\n* [Luke Redpath](http://lukeredpath.co.uk/blog/my-objective-c-style-guide.html)\n* [Marcus Zarra](http://www.cimgf.com/zds-code-style-guide/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodecocodes%2Fobjective-c-style-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkodecocodes%2Fobjective-c-style-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkodecocodes%2Fobjective-c-style-guide/lists"}