3

I had an app that was working just fine. And then I tried to embed the navigation controller into a tabbarcontroller and next thing I know I started getting these errors during compiling.

Would anyone know why these happen? Did some setting get unchecked or checked by accident?

Thanks, Alex

justin
  • 104,054
  • 14
  • 179
  • 226
Genadinik
  • 18,153
  • 63
  • 185
  • 284

3 Answers3

7

Seems your previously working code did not use ARC, now you tried to embed it into code which uses ARC ... Refactor your code using "Edit->Convert->Convert to Object-C ARC"

AnLT
  • 569
  • 8
  • 22
Martin Mandl
  • 721
  • 3
  • 11
  • 1
    thank you. I just tried that and it told me it cannot do that because there were some errors. And to see the errors I have to select "continue building after errors" in the general preferenes pane. But I am not sure which pane is that. Any ideas? – Genadinik Jul 01 '13 at 19:32
  • which means your code is to complicated for the refactoring wizard and you have - unfortunately - refactor the code manually :( – Martin Mandl Jul 01 '13 at 19:36
  • @Marting so what should I do to set it right? Should I comment out all the statements with errors? Or something else? – Genadinik Jul 01 '13 at 19:37
  • Have a look how ARC is working - which basically means you do not have to retain and release objects yourself and thus is much simpler ;) ... but because the wizard could not remove the retains, releases, auto-releases, itself it could be you use some bridge magic, which you might want to handle with care ... Nevertheless, have a look at how ARC works, it shouldn't be to difficult to incorporate into your code. – Martin Mandl Jul 01 '13 at 19:41
  • I am not sure I need/want ARC. To get rid of it, do I just comment out the autorelease parts of the code? – Genadinik Jul 01 '13 at 19:51
  • To get rid of ARC, you have to tell the the compiler. Have a look at the comments of the other answers: http://stackoverflow.com/questions/7837024/how-to-disable-xcode4-2-automatic-reference-counting – Martin Mandl Jul 01 '13 at 19:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/32705/discussion-between-genadinik-and-martin-mandl) – Genadinik Jul 01 '13 at 20:04
4

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.

Community
  • 1
  • 1
justin
  • 104,054
  • 14
  • 179
  • 226
  • so should I just get read of that autorelease part? Would that fix things? – Genadinik Jul 01 '13 at 19:39
  • @Genadinik If this source file is still used by another project, you should compile it with ARC disabled (because 'they' compile it without ARC, you would introduce problems by removing the ref count ops they depend on). If the file is not used in other projects, then go ahead and delete it (if the migration fails). Although they are very rare, keep an eye out for unusual reference count operations. – justin Jul 01 '13 at 19:57
1

The errors are on the new code?

In that case I think your projects is ARC-enabled and when you tried to embed the UINavigationController you inserted some non-ARC code.

Did you change the compiler?

LLVM compiler introduces ARC. If you were developing a non-ARC project, maybe you just compiled with LLVM and that broke your code.

Try refactoring the code. Check this.

Qix - MONICA WAS MISTREATED
  • 14,451
  • 16
  • 82
  • 145
Eduardo
  • 1,383
  • 8
  • 13
  • the errors are on existing code. I really didn't change much. The only changes I made were in the storyboard. – Genadinik Jul 01 '13 at 19:32
  • 1
    Try disabling ARC. Check this answer: http://stackoverflow.com/questions/7837024/how-to-disable-xcode4-2-automatic-reference-counting – Eduardo Jul 01 '13 at 19:37