Lines Matching +full:objective +full:- +full:c
1 # Google Objective-C Style Guide
4 > Objective-C is a dynamic, object-oriented extension of C. It's designed to be
5 > easy to use and read, while enabling sophisticated object-oriented design. It
10 > for Objective-C. Please read it in addition to this guide.
13 > The purpose of this document is to describe the Objective-C (and
14 > Objective-C++) coding guidelines and practices that should be used for iOS and
17 > Open-source projects developed by Google conform to the requirements in this guide.
19 > Note that this guide is not an Objective-C tutorial. We assume that the reader
20 > is familiar with the language. If you are new to Objective-C or need a
22 > Objective-C](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ProgrammingW…
49 Consistency with the way Apple SDKs use Objective-C has value for the same
50 reasons as consistency within our code base. If an Objective-C feature solves a
82 * A sample class demonstrating good Objective-C style. All interfaces,
83 * categories, and protocols (read: all non-trivial top-level declarations
97 * See -initWithBar: for details about @c bar.
109 - (instancetype)initWithBar:(Bar *)bar;
112 * Does some work with @c blah.
117 - (BOOL)doWorkWithBlah:(NSString *)blah;
139 - (instancetype)init {
145 - (instancetype)initWithBar:(Bar *)bar {
158 - (BOOL)doWorkWithBlah:(NSString *)blah {
178 The maximum line length for Objective-C files is 100 columns.
185 One space should be used between the `-` or `+` and the return type, and no
193 - (void)doSomethingWithString:(NSString *)theString {
208 - (void)doSomethingWithFoo:(GTMFoo *)theFoo
221 - (void)short:(GTMFoo *)theFoo
289 Intentional fall-through to the next case should be documented with a comment
323 v = -y * (x + z);
387 left-aligned at a four space indent.
395 opening parenthesis, or may have a four-space indent.
430 Objective-C exceptions, format them as follows. However, see Avoid Throwing
474 [Objective-C naming
477 Avoid non-standard abbreviations. Don't worry about saving horizontal space as
511 Names of C functions and typedefs should be capitalized and use camel case as
523 --------- | ---------------------------------
524 .h | C/C++/Objective-C header file
525 .m | Objective-C implementation file
526 .mm | Objective-C++ implementation file
527 .cc | Pure C++ implementation file
528 .c | C implementation file
558 Objective-C's global namespace.
568 - (NSString *)gtm_parsedString;
572 ### Objective-C Method Names
585 choose parameter names that flow with the method name. Objective-C method names
596 - (void)addTarget:(id)target action:(SEL)action; // GOOD; no conjunction n…
597 - (CGPoint)convertPoint:(CGPoint)point fromView:(UIView *)view; // GOOD; conjunction clar…
598 - (void)replaceCharactersInRange:(NSRange)aRange
608 - (Sandwich *)sandwich; // GOOD.
614 - (Sandwich *)makeSandwich; // AVOID.
623 - (id)delegate; // GOOD.
629 - (id)getDelegate; // AVOID.
641 - (BOOL)isGlorious;
667 …ocoa/Conceptual/CodingGuidelines/Articles/NamingMethods.html#//apple_ref/doc/uid/20001282-BCIGIJJF)
668 for more details on Objective-C naming.
670 These guidelines are for Objective-C methods only. C++ method names continue to
671 follow the rules set in the C++ style guide.
688 Because Objective-C does not provide namespacing, non-static functions should
727 NOTE: Google's previous convention for Objective-C ivars was a trailing
746 GTLServiceErrorQueryResultMissing = -3000,
747 GTLServiceErrorWaitTimedOut = -3001,
751 Because Objective-C does not provide namespacing, constants with external
807 Under Automatic Reference Counting, pointers to Objective-C objects are by
823 for (NSInteger counter = numberOfObjects - 1; counter > 0; --counter)
829 for (NSUInteger counter = numberOfObjects - 1; counter > 0; --counter) // AVOID.
837 Due to sizes that differ in 32- and 64-bit builds, avoid types long, NSInteger,
840 Types long, NSInteger, NSUInteger, and CGFloat vary in size between 32- and
841 64-bit builds. Use of these types is appropriate when handling values exposed by
862 File and buffer sizes often exceed 32-bit limits, so they should be declared
869 important, the best code is self-documenting. Giving sensible names to types and
874 well-written comments than badly written ones.
896 Every non-trivial interface, public and private, should have an accompanying
923 Doxygen-style comments are encouraged for interfaces as they are parsed by Xcode
934 immediately preceding the method for non-trivial private methods.
944 Any sentinel values for properties and ivars, such as `NULL` or `-1`, should be
969 End-of-line comments should be separated from the code by at least 2 spaces. If
986 In Doxygen-style comments, prefer demarcating symbols with a monospace text
987 command, such as `@c`.
1007 Backticks or vertical bars are not needed when a symbol is self-apparent.
1020 /** @param maximum The highest value for @c count. */
1026 possible when it falls outside the most common Objective-C usage idioms.
1030 Instance variables for NSObject-derived objects are presumed to be retained; if
1037 Where instance variables are pointers to Core Foundation, C++, and other
1038 non-Objective-C objects, they should always be declared with strong and weak
1040 and other non-Objective-C object pointers require explicit memory management,
1062 // non-NSObject pointers...
1063 CWackyCPPClass *_wacky; // Strong, some cross-platform object
1074 ## C Language Features
1078 Avoid macros, especially where `const` variables, enums, XCode snippets, or C
1081 Macros make the code you see different from the code the compiler sees. Modern C
1091 underscores between words. Function-like macros may use C function naming
1092 practices. Do not define macros that appear to be C or Objective-C keywords.
1114 Avoid macros that expand to unbalanced C or Objective-C constructs. Avoid macros
1129 -(void)add ## CLASS ## :(CLASS *)obj toArray:(NSMutableArray *)array
1132 if (array.count > 5) { // AVOID -- where is 'array' defined?
1144 Nonstandard extensions to C/Objective-C may not be used unless otherwise
1147 Compilers support various extensions that are not part of standard C. Examples
1149 and variable-length arrays.
1151 `__attribute__` is an approved exception, as it is used in Objective-C API
1156 ## Cocoa and Objective-C Features
1199 `0` (except for isa), so don't clutter up the init method by re-initializing
1205 auto-synthesized by properties. When ivars are declared in a header file, they
1223 Modern Objective-C code explicitly calls `alloc` and an `init` method to create
1229 Keep your class simple; avoid "kitchen-sink" APIs. If a method doesn't need to
1232 Unlike C++, Objective-C doesn't differentiate between public and private
1246 `#import` Objective-C and Objective-C++ headers, and `#include` C/C++ headers.
1252 When including a header that uses Objective-C or Objective-C++, use `#import`.
1253 When including a standard C or C++ header, use `#include`.
1295 include the top-level root framework. The root framework is generally
1296 pre-compiled and can be loaded much more quickly. In addition, remember to use
1297 `@import` or `#import` rather than `#include` for Objective-C frameworks.
1314 ### Avoid Messaging the Current Object Within Initializers and `-dealloc`
1316 Code in initializers and `-dealloc` should avoid invoking instance methods.
1323 A similar issue exists for `-dealloc`, where a method invocation may cause a
1328 and release ivars in initializers and `-dealloc`, rather than rely on accessors.
1333 - (instancetype)init {
1344 - Methods can be overridden in subclasses, either deliberately, or
1346 - When editing a helper method, it may not be obvious that the code is being
1352 - (instancetype)init {
1365 - (void)dealloc {
1373 - (void)dealloc {
1395 - (void)setZigfoos:(NSArray<Zigfoo *> *)zigfoos {
1404 Objective-C lightweight generics notation to type contained objects.
1418 If the fully-annotated types become complex, consider using a typedef to
1440 Don't `@throw` Objective-C exceptions, but you should be prepared to catch them
1441 from third-party or OS calls.
1447 We do compile with `-fobjc-exceptions` (mainly so we get `@synchronized`), but
1459 `nil` as a pointer, zero as an integer or floating-point value, structs
1465 Note too that this is distinct from checking C/C++ pointers and block pointers
1475 `BOOL` in OS X and in 32-bit iOS builds is defined as a signed `char`, so it may
1485 You can safely interchange and convert `BOOL`, `_Bool` and `bool` (see C++ Std
1486 4.7.4, 4.12 and C99 Std 6.3.1.2). Use `BOOL` in Objective-C method signatures.
1495 - (BOOL)isBold {
1498 - (BOOL)isValid {
1506 - (BOOL)isBold {
1509 - (BOOL)isValid {
1512 - (BOOL)isEnabled {
1518 it harder to read for those well-versed in C, but the first point above
1549 - (void)fooBarBam;
1559 - (void)fooBarBam;
1582 ## Objective-C++
1586 Within an Objective-C++ source file, follow the style for the language of the
1588 differing naming styles when mixing Cocoa/Objective-C and C++, follow the style
1591 For code in an `@implementation` block, use the Objective-C naming rules. For
1592 code in a method of a C++ class, use the C++ naming rules.
1594 For code in an Objective-C++ file outside of a class implementation, be
1613 // A typical Objective-C class, using Objective-C naming.
1620 - (void)respondToSomething:(id)something;
1626 - (void)respondToSomething:(id)something {
1627 // bridge from Cocoa through our C++ backend
1628 _instanceVar = _backEndObject->DoSomethingPlatformSpecific();
1635 // The platform-specific implementation of the C++ class, using
1636 // C++ naming.
1645 Google's C++ style guide.
1647 ## Objective-C Style Exceptions
1653 the previous line. Sometimes it is required that parts of Objective-C code must