Jules
Jules

Reputation: 7776

Obj-C, Receiver in message expression is an uninitialized value, analyzer warning?

I'm getting the following analyzer warning on this line...

if ([datStartDate compare:now] == NSOrderedDescending) {

Receiver in message expression is an uninitialized value

The line of code occurs in the middle of an IBAction.

What am I doing wrong?

Upvotes: 2

Views: 1347

Answers (2)

DarkDust
DarkDust

Reputation: 92384

There is at least one code path that can lead to this line with datStartDate still being uninitialized. That means you have never assigned an object to datStartDate, not even nil.

Upvotes: 0

bbum
bbum

Reputation: 162722

If you expand the disclosure triangle next to the error (in the error navigator on the left side), it'll show you the exact code path that leads to a situation where the value is not initialized.

You may think "But, analyzer, really, that can never happen.". While that may be true, you are creating an assumption in your code that may not hold true in the future due to bug or intentional change. That increases the fragility of your codebase and will lead to maintenance headaches.

Fix the code such that it is explicit and remove the assumption.

Upvotes: 4

Related Questions