How to Automatically Convert Manual Retain-Release Code to Arc

How to automatically convert Manual Retain-Release code to ARC?

In Xcode 6+, the command is now:

Edit > Convert > To Objective-C ARC...

how do i change an old project I had so it can use ARC?

In Xcode, Edit => Refactor => Convert to Objective-C ARC... and follow the instructions.

Tool for transitioning to ARC

Oh man I just found it:

Convert > To Objective-C ARC

I checked in Xcode's help first where I could not find it.

Sample Image

How to change to use ARC from nonARC project?

This screen shot will help you

Sample Image

Read this DaveOnCode and Migrating your code to Objective-C ARC.

Manual retain with ARC

Why not just assign your delegate object to a strong ivar for the duration of the asynchronous task?

Or have a local variable in executeAsyncWork

- (void)executeAsyncWork
{
id localCopy = _delegate;

if (localCopy != nil) // since this method is async, the delegate might have gone
{
// do work on local copy
}
}

iOS ARC:What's the principle of xcode compiler to add retain and release to code under arc?

Where retains and released are added are specified in the ARC specification, although it's kind of a technical read.

What is the value in learning manual retain/release? (iOS)

I think it is unlikely that you will need to write code that uses retain, release, etc. I can't think of many reasons why you would ever need to start writing code like that.

That being said, I have found it very helpful to understand what the compiler is doing on my behalf when writing applications. Understanding some of the details will help you write code that is better optimized.

So as a beginner to Objective-C I think you should not focus too much on memory management details when you are just starting out, but as you grow your expertise I believe it is useful background information that will help you write better code, even if you always use ARC.

iOS - Automatic Reference Counting (ARC) vs Manual Retain-Release (MRR)

Your colleagues don't sound experienced with iOS. ARC isn't buggy. Every single experienced iOS developer I've heard mention ARC has done so in approving terms. I have over three year's experience with iOS and I would strongly recommend ARC, so long as you actually understand what's going on under the hood. Apple themselves, in the very guide you link to say:

You are strongly encouraged to use ARC for new projects.

When Apple say that you must use explicit memory management, they are grouping traditional manual memory management and ARC together as explicit memory management, in contrast to garbage collection.

Also, note that you linked to documentation in the Mac developer library, not the iOS developer library. If you need to develop for iOS, use the iOS developer library.



Related Topics



Leave a reply



Submit