blob: cd74cdc74c4ffd5e3adc66c06a9c5965d1db4721 [file] [log] [blame] [view]
marq4a377b82017-02-16 18:40:191# Chromium Objective-C and Objective-C++ style guide
2
3_For other languages, please see the [Chromium style guides](https://chromium.googlesource.com/chromium/src/+/master/styleguide/styleguide.md)._
4
marq26473402017-02-23 15:12:275Chromium follows the
Mark Coganc8613042017-10-18 10:58:496[Google Objective-C style guide](https://github.com/google/styleguide/blob/gh-pages/objcguide.md)
marq26473402017-02-23 15:12:277unless an exception is listed below.
marq4a377b82017-02-16 18:40:198
9A checkout should give you
10[clang-format](https://chromium.googlesource.com/chromium/src/+/master/docs/clang_format.md)
11to automatically format Objective-C and Objective-C++ code. By policy, Clang's
12formatting of code should always be accepted in code reviews. If Clang's
13formatting doesn't follow this style guide, file a bug.
14
15## Line length
16
17For consistency with the 80 character line length used in Chromium C++ code,
18Objective-C and Objective-C++ code also has an 80 character line length.
19
20## Chromium C++ style
21
Mark Coganc8613042017-10-18 10:58:4922Where appropriate, the [Chromium C++ style](../c++/c++.md) style guide applies
23to Chromium Objective-C and (especially) Objective-C++
marq4a377b82017-02-16 18:40:1924
25## Code Formatting
26
27Use `nil` for null pointers to Objective-C objects, and `nullptr` for C++
28objects.
29
30## Objective-C++ style matches the language
31
32Within an Objective-C++ source file, follow the style for the language of the
33function or method you're implementing.
34
35In order to minimize clashes between the differing naming styles when mixing
36Cocoa/Objective-C and C++, follow the style of the method being implemented.
37
38For code in an `@implementation` block, use the Objective-C naming rules. For
39code in a method of a C++ class, use the C++ naming rules.
40
41For C functions and constants defined in a namespace, use C++ style, even if
42most of the file is Objective-C.
43
44`TEST` and `TEST_F` macros expand to C++ methods, so even if a unit test is
45mostly testing Objective-C objects and methods, the test should be written using
46C++ style.
47
Eugene Butf2df2932018-12-10 23:28:3648## #import and #include in the `ios/` directory
49
50#import directive can be used to import C++ and Objective-C headers for all
51source code in the `ios/` directory. This differs from Google Objective-C Style
52Guide, which requires using #include directive for C++ headers.