Trouble converting the lottery app into ARC


I followed the process in chapter 4 and converted the project into manual memory management. However, for some reason I’m not able to convert it into ARC using Xcode’s refactoring tool. I keep on getting the following error.

The source code of the entire Xcode project is below

Any suggestions to why this may be the case?


I’m not sure why the conversion tool doesn’t like that line. You could try combining the last two lines to this:

and see if it likes it any better.


That does solve the issue exactly! Why is this the case though? Obviously the two versions are exactly equivalent. And I would imagine autoreleasing is such a common thing, therefore someone else must have had problem converting to ARC already, how come Googling couldn’t suggest a solution? Is it something about the coding style of objective C that you only have autorelease on the return statement?

Thank you for clarifying!


My best guess is just that it’s a bug in the ARC converter. Autoreleasing is extremely common in manual retain counted code, so it’s definitely a case that the converter should handle. Presumably there’s just something about the way that method is written that the converter doesn’t like.


I was looking at this and it may be that the converter refuses to deal with a single command call like this because if you remove it you end up with [color=#0000FF][result][/color] which is illegal and removing the entire line may cause some other problem. Removing it in something like [color=#0000FF][[foo makeSomething] autorelease][/color] would work just fine.