| 1 |
.. title:: clang-tidy - google-objc-avoid-nsobject-new |
| 2 |
|
| 3 |
google-objc-avoid-nsobject-new |
| 4 |
============================== |
| 5 |
|
| 6 |
Finds calls to ``+new`` or overrides of it, which are prohibited by the |
| 7 |
Google Objective-C style guide. |
| 8 |
|
| 9 |
The Google Objective-C style guide forbids calling ``+new`` or overriding it in |
| 10 |
class implementations, preferring ``+alloc`` and ``-init`` methods to |
| 11 |
instantiate objects. |
| 12 |
|
| 13 |
An example: |
| 14 |
|
| 15 |
.. code-block:: objc |
| 16 |
|
| 17 |
NSDate *now = [NSDate new]; |
| 18 |
Foo *bar = [Foo new]; |
| 19 |
|
| 20 |
Instead, code should use ``+alloc``/``-init`` or class factory methods. |
| 21 |
|
| 22 |
.. code-block:: objc |
| 23 |
|
| 24 |
NSDate *now = [NSDate date]; |
| 25 |
Foo *bar = [[Foo alloc] init]; |
| 26 |
|
| 27 |
This check corresponds to the Google Objective-C Style Guide rule |
| 28 |
`Do Not Use +new |
| 29 |
<https://google.github.io/styleguide/objcguide.html#do-not-use-new>`_. |