Reputation: 919
I developed an ios app that had a:
NSError *error;
instead of:
NSError *error = nil;
It worked fine in while I was debugging in the simulator and debugging on the device while connected. The moment I archived it and sent it into TestFlight to deploy for testing, I started getting Unknown Signal errors coming up in the crash log.
Why does this happen?
Upvotes: 5
Views: 2419
Reputation: 33101
To clarify on dasblinkenlights answer, this is declaring a variable:
NSError *error;
... and this is declaring AND assigning a variable
NSError *error = nil;
When you use it the first way and try to access it without ever setting it to something, the value it is pointing at is known as "garbage" It is a pointer to some other stack of memory, and accessing it will almost always make your app crash. Thus, it is always best practice to assign a value to your variable as above, or shortly after.
Upvotes: 3
Reputation: 726639
This happens because you have an uninitialized pointer. It does not crash as long as you get lucky, but using such pointers is undefined behavior.
Upvotes: 6