Trouble converting the lottery app into ARC


#1

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

cl.ly/CLcv

Any suggestions to why this may be the case?


#2

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.


#3

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!


#4

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.


#5

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.