clang-tidy - google-objc-avoid-nsobject-new — Extra Clang Tools 21.1.8 documentation

# Extra Clang Tools 21.1.8 documentation

## clang-tidy - google-objc-avoid-nsobject-new

# google-objc-avoid-nsobject-new

Finds calls to `+new` or overrides of it, which are prohibited by the Google Objective-C style guide.

The Google Objective-C style guide forbids calling `+new` or overriding it in class implementations, preferring `+alloc` and `-init` methods to instantiate objects.

An example:

    NSDate *now = [NSDate new];
    Foo *bar = [Foo new];

Instead, code should use `+alloc`/`-init` or class factory methods.

    NSDate *now = [NSDate date];
    Foo *bar = [[Foo alloc] init];

This check corresponds to the Google Objective-C Style Guide rule Do Not Use +new.