AndreyMan
AndreyMan

Reputation: 113

Transitioning one separate file to arc

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.

Upvotes: 1

Views: 667

Answers (2)

Mike Weller
Mike Weller

Reputation: 45598

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.

Upvotes: 1

stevekohls
stevekohls

Reputation: 2255

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/

Upvotes: 0

Related Questions