Search code examples
javaobjective-cguava

Equivalent of Guava's Preconditions.checkNotNull(...) for Objective-C?


In Java, I like to start methods with using Guava's Preconditions class to make sure the method parameters are not null, or are valid values. For example:

public void myMethod(String str) {
    Preconditions.checkNotNull(str);
    ... method logic here ...
}

This is an important part of my approach to coding. Is there something similar in Objective-C?


Solution

  • The equivalent is NSParameterAssert, defined in NSException.h. It's not as full-featured as Guava's, though.