Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 7 Null passed to a callee that requires a non-null argument

Tags:

xcode

ios

i updated xcode 7 and gives this error

Null passed to a callee that requires a non-null argument

 _recorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.%@", [NSHomeDirectory() stringByAppendingString:@"/Documents"], name, extension]] settings:nil error:nil];
like image 224
Uyghur Ilan Avatar asked Sep 20 '15 08:09

Uyghur Ilan


2 Answers

If what bothers you is the warnings, you can supress that using this -Wnonnull

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnonnull"

_recorder = [[AVAudioRecorder alloc]initWithURL:[NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/%@.%@", [NSHomeDirectory() stringByAppendingString:@"/Documents"], name, extension]] settings:nil error:nil];

#pragma clang diagnostic pop
like image 124
ruiaureliano Avatar answered Oct 09 '22 07:10

ruiaureliano


An easy way to check is to use Show Completions - go to a method name and press Ctrl-Space or in the menu Editor > Show Completions. A window will pop up. Look for entries with (nonnull) - these must not be nil. For example:

(nonnull) sample popup

I pressed Ctrl-Space with the cursor in [NSString stringWithFormat:...]. As you can see a lot of arguments are marked (nonnull).

When you explicitly pass nil in your method call, you already found the problem. If you pass a variable, check whether that is nil at that time.

like image 37
Rainer Schwarze Avatar answered Oct 09 '22 05:10

Rainer Schwarze