-
Notifications
You must be signed in to change notification settings - Fork 1
Filtering
Nullarihyon 1.2 introduced filtering, which helps programmers to have a working set of programs. Filter is a set of class names, and warnings irrelevant to given classes are ignored.
You can try filtering with nullarihyon check
command.
$ nullarihyon check --filter NSString test.m
For nullarihyon xcode
, add nullfilter
file in the directory which contains .xcodeproj
you are working with.
The content of nullfilter
is like the following.
NSString
YourViewController
# AnotherViewController
/ViewController/
Each line contains a class name, or a regular expression for class name enclosed by /
.
You can have comments with #
symbol.
When you setup filtering with ViewController
, following warnings will be printed.
- Warnings found in implementation of
ViewController
- Warnings found about message call expression to method of
ViewController
- Warnings about nullability introduced from method of
ViewController
1 is trivial. 2 and 3 should look a bit ambiguous. Let's explain them with example.
Method of ViewController
means a method which is declared in @interface
declaration of ViewController
.
Assume we have a @interface
declaration as the following:
@interface ViewController : UIViewController
// ViewController specific method
@property (nonatomic, nonnull) NSString *name;
// UIViewController method but with explicit declaration
- (void)presentViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated completion:(void(^nullable){})completion;
@end
-[ViewController setName:]
is a method of ViewController
. -[ViewController prepareForSegue:sender:]
is also a method of ViewController
. However, other methods inherited from UIViewController
including -[UIViewController addChildViewController:]
is not.
ViewController *viewController;
NSString * _Nullable string;
UIViewController * _Nullable anotherViewController;
// Next two lines will have warning
viewController.name = string;
[viewController presentViewController:anotherViewController animated:YES completion:nil];
// This line will not have warning, though addChildViewController expects _Nonnull argument
[viewController addChildViewController:anotherViewController];
If you override a method of super class but do not expose it to @interface
, the method is not of the class.
Let's explain the motivation.
- (void)example:(nullable ViewController viewController) {
// Dont want warning for this
ViewController * _Nonnull vc = viewController;
NSString * _Nullable name = [viewController nameOrNil];
// Want warning for this
BOOL x = [@"example" isEqualToString:name]; // isEqualToString expects _Nonnull argument
}
The nullability of viewController
is not related to definition of ViewController
.
It is by the definition of the method.
We don't want warning for that.
However, nullability of name
is by the definition of ViewController
(assume nameOrNil
method returns _Nullable
).
And we want warning reported around isEqualToString:
.
Warning about an expression will be reported if
- Expression is result of method call of
ViewController
, or - Expression is a variable and a variable has assignment with result of method call of
ViewController