I\'m making my first steps with Objective-C and have encountered a minor, albeit confusing issue with the static analyzer (Product->Analyze) in XCode 4.1. I have created a
Trying to separate calls to +alloc and -init is explicitly recommended against by Apple, per the documentation for +[NSObject alloc]:
An init... method must be used to complete the initialization process. For example:
TheClass *newObject = [[TheClass alloc] init];
and -[NSObject init]:
In some cases, an init method might release the new object and return a substitute. Programs should therefore always use the object returned by init, and not necessarily the one returned by alloc or allocWithZone:, in subsequent code.
The static analyzer is complaining because it expects that +alloc will be paired with -init. Because -init can release the sender, the static analyzer therefore thinks you're trying to call a method on a deallocated instance.