I have some doubts in objective-C programming. I have function like this.
+ (NSManagedObjectContext *) newContext {
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (coordinator != nil)
{
NSManagedObjectContext* managedObjectContext = [[[NSManagedObjectContext alloc] init] autorelease];
[managedObjectContext setPersistentStoreCoordinator:coordinator];
return managedObjectContext;
}
return nil;
}
But when I run analyse on my project I am seeing something like this with warning
“Object with a +0 retain count returned to caller where a +1 (owning)
retain count is expected”

Can someone point me out so as to why Xcode is giving me a warning here. What is the correct way to return any variable?
The problem lies not within your code but within the name of your method. In Objective C, methods whose names start with
initorneware assumed by the analyser to return an object with a retain count of 1. You are returning an object with a retain count of zero, therefore your method name should not containnew.