1.. title:: clang-tidy - google-objc-global-variable-declaration
2
3google-objc-global-variable-declaration
4=======================================
5
6Finds global variable declarations in Objective-C files that do not follow the
7pattern of variable names in Google's Objective-C Style Guide.
8
9The corresponding style guide rule:
10https://google.github.io/styleguide/objcguide.html#variable-names
11
12All the global variables should follow the pattern of ``g[A-Z].*`` (variables) or
13``k[A-Z].*`` (constants). The check will suggest a variable name that follows the
14pattern if it can be inferred from the original name.
15
16For code:
17
18.. code-block:: objc
19
20  static NSString* myString = @"hello";
21
22The fix will be:
23
24.. code-block:: objc
25
26  static NSString* gMyString = @"hello";
27
28Another example of constant:
29
30.. code-block:: objc
31
32  static NSString* const myConstString = @"hello";
33
34The fix will be:
35
36.. code-block:: objc
37
38  static NSString* const kMyConstString = @"hello";
39
40However for code that prefixed with non-alphabetical characters like:
41
42.. code-block:: objc
43
44  static NSString* __anotherString = @"world";
45
46The check will give a warning message but will not be able to suggest a fix. The
47user needs to fix it on their own.
48