1

I have a project that is already transitioned to ARC. Now I'm trying to include an existing file from the other project, which is not using ARC and I want it to be ARC-compliant too: release-retains, [super dealloc]s gone from this file, quick fixes, other stuff "Convert to Objective-C ARC..." does.

The problem is I can't use the Edit->Refactor->"Convert to Objective-C ARC..." tool for this. If I select only this file in "Select Targets to Convert" screen I'm getting "Cannot Convert to Objective-C ARC" message because of errors like: "@synthesize of 'weak' property is only allowed in ARC or GC mode". But they are already in ARC mode indeed! Also numerous warnings: "Method possibly missing a [super dealloc] call"

If I select all files except marked with -fno-objc-arc while converting, I get only errors about weak properties.

Of course I can build and delete the release-retains manually but why to walk if there is a bus (Conversion tool)... So can I auto-transition a separate file to ARC?

Update: I do not want ARC to be turned off for this file with -fno-objc-arc flag, I want ARC used in this file.

AndreyMan
  • 113
  • 8
  • Possible duplicate: http://stackoverflow.com/questions/6646052/how-can-i-disable-arc-for-a-single-file-in-a-project – Attila H Apr 10 '13 at 10:16
  • @Attila H I do not want to disable ARC for this file, I want release-retains, [super dealloc]s gone from this file automatically as it happens when you use "Cannot Convert to Objective-C ARC" tool. Sorry if I was unclear in my question. – AndreyMan Apr 10 '13 at 10:43

2 Answers2

1

If you insist on making Xcode do the work, create a new Xcode project and deselect "Use ARC" when creating it. Add the files to convert, and convert the project to ARC. Take the modified files and import them into your other project.

It's probably simpler, however, to convert the file manually. This is not difficult, even for a large file or an entire project. Just lean on the compiler: build your app, walk through the errors and simply delete all retain/release calls and convert any NSAutoreleasePools to @autoreleasepool {}. You may also need to add __bridge casts if interacting with core foundation types.

Mike Weller
  • 45,401
  • 15
  • 131
  • 151
  • Bingo! That done the trick! And by the way, after first answers in this thread I modified the file manually by compiler errors: deleted retains, releases, [super dealloc]. And the conversion tool made 2 more changes than me: modified assign to weak for one of the properties; modified __block to __weak for a variable. As this code was not mine and I didn't investigate it much I never saw those places. Seems these chages have similar effect to what was before, but I think its cleaner now. Thanks for the answer! – AndreyMan Apr 10 '13 at 13:51
0

It sounds like you'll have to convert this file to ARC manually, instead of relying on the automatic conversion tool. You'll need to go through the file and remove all of the release, retain etc. I've done this before, and while it takes a while, it's not too painful. Rely on the error messages from Xcode to guide you what needs to be fixed/removed in the code. Here's a couple of links I found that may help. Also look at Apple's ARC docs and WWDC 2011 talks (referenced at the bottom of the second link).

Xcode ARC conversion tool issue

http://blog.mugunthkumar.com/articles/migrating-your-code-to-objective-c-arc/

Community
  • 1
  • 1
stevekohls
  • 2,214
  • 23
  • 29
  • Agreed. It's not hard to convert to ARC manually, even for a large file or an entire project. Just lean on the compiler: build your app, walk through the errors and simply delete all retain/release calls and convert any `NSAutoreleasePool`s to `@autoreleasepool {}`. You may also need to add __bridge casts if interacting with core foundation types. – Mike Weller Apr 10 '13 at 13:10
  • @stevekohls Turned out the automatic tool had found some more than me. See my comment on the [Mike Weller's answer](http://stackoverflow.com/questions/15922753/transitioning-one-separate-file-to-arc/15926876#15926876) – AndreyMan Apr 10 '13 at 13:55