Heath Borders Heath Borders - 4 months ago 7x
Objective-C Question

How can clang warn me if I fail to initialize a variable while using ARC?

I forgot to initialize a local variable, and I got no warning when I used it. Since I'm using

, the variable was initialized to
, so no harm was done, but I still want a warning when I used an uninitialized value. If I disable
, I get the warning I expect.

NSString *foo;
NSString *baz;
if (bar) {
foo = @"fizz";
} else {
foo = @"buzz";
NSLog(@"foo: %@", foo); // foo: (fizz|buzz)
NSLog(@"baz: %@", baz); // baz: (null)

Without ARC:

/blah/blah/blah/Blah.m:14:18: note: initialize the variable 'foo' to silence this warning
NSString *foo;


I've figured out how to make uninitialized values impossible using local blocks. This obviates the need for the warning.


With ARC, pointers to Objective C objects are automatically initialized to nil, so there is no "uninitialized value" which the compiler can warn about.