ARC is enabled per translation -- every compiled source file and everything it sees via inclusion must abide by the ARC or MRC. And yes, the modes can coexist (i.e. you can have ARC on for some files, but not all and the libraries you link to can use either).
You have two modes:
ARC
The expression [obj autorelease]
is forbidden. ARC will add it for you (unless you have unusual reference counting sequences).
Under typical scenarios, you can just write:
// a method which returns an autoreleased object
- (NSArray *)something
{
return [[NSArray alloc] initWithObjects:…YOUR_OBJECTS…];
}
and then ARC will add the autorelease
for you.
But if you write:
- (NSArray *)something
{
return [[[NSArray alloc] initWithObjects:…YOUR_OBJECTS…] autorelease];
}
in ARC, it will be a compile error (like the one in your title).
MRC
And this is the MRC form:
- (NSArray *)something
{
return [[[NSArray alloc] initWithObjects:…YOUR_OBJECTS…] autorelease];
}
Your project probably uses ARC by default (i.e. it is defined in an xcconfig, at the project level, or at the target level), though you have added a source file which was written for MRC.
Since the file is either compiled as ARC, you can either remove the autorelease
message or disable ARC for the single file.