The "Pass-by-value argument in message expression is undefined" static analyzer error explained.

I was running the LLVM/Clang Static Analyzer on my iPhone project today and got the following error:

"Pass-by-value argument in message expression is undefined"

That means as much to me as "blah blah blah blee is undefined" so I looked at the code that was triggering it. Here's a simplified version:

NSString *x;

if (someExpression) {
  x = someThing;

NSDictionary *someDict = [NSDictionary dictionaryWithObjectsAndKeys: x, kSomeKey, ..., nil];

What the analyzer is saying here is that it cannot know for sure that x will be assigned a value. The fix is simple: assign x a default value while declaring it:

NSString *x = @"some default value";

Tada, error gone!

(Note: in my actual app, I was iterating over a data structure and populating the default values of user preferences in NSUserDefaults – you will probably run into this in a similar situation involving a loop.)