1

Okay so I've been happily using ARC in my project until I attempted to add some third party code to my project. I dragged the folder in (not a project file, just some viewcontroller source files). The 3rd party code was not ARC so I did Edit->Refactor->Convert To Objective-C ARC and choose ONLY the files from the 3rd party app to convert to ARC. Everything went swimmingly but I started getting the following warning in MY previously working code:

TTKSoundGenerator.m:94:10: warning: '__bridge' casts have no effect when not using ARC [-Warc-bridge-casts-disallowed-in-nonarc]
        (__bridge CFStringRef)soundFile,
         ^~~~~~~~
1 warning generated.

This is the first clue that something is amiss. I go ahead and build and run and sure enough the app crashes where things are getting released while still being referenced. So ARC is not working at all despite the fact that the Objective-C Automatic Reference Counting is set to YES in project file.

I went back and did Edit->Refactor->Convert To Objective-C ARC on ALL the files in the project hoping to rectify this but no dice. So now the project is stuck in ARC limbo. It seems like unselecting files when doing the refactor somehow told Xcode to add a special case of 'No ARC' to those files. Any ideas on how to fix or further diagnose this?

Kirby Todd
  • 11,254
  • 3
  • 32
  • 60
  • 1
    just a note. you can enable or disable arc in single class , http://stackoverflow.com/questions/9629820/use-automatic-referencing-count-in-specific-classes-in-ios/9629853#9629853 – janusfidel Aug 17 '12 at 08:49
  • Yeah, that was it. I guess Refactor helpfully does that for you if you unselect files during the conversion. – Kirby Todd Aug 17 '12 at 09:00
  • It would be great if you could post your own answer to this then accept it so people like me would know the questions has been answered. – David H Aug 17 '12 at 12:10

3 Answers3

2

There is no need to convert your 3rd part library to ARC, it is possible to have both ARC-code and non-ARC-code in the same project. Since your 3rd part lib is not written as ARC, you save lots of extra work if you just use it as it is. (especially if you need to update it)

I think it is fair to assume that a 3rd part lib is correctly written without ARC if you decide to use it in your project.

See this:

is it possible to combine non-ARC and ARC project code?

Community
  • 1
  • 1
jake_hetfield
  • 3,388
  • 1
  • 23
  • 30
0

Okay so apparently if you do Edit->Refactor->Convert To Objective-C ARC on a project and only choose some of the files to convert then Xcode will mark the rest as No ARC. Running Edit->Refactor->Convert To Objective-C ARC again on all the files has no further effect once that option has been set. The fix is to go to your project settings, under Build Phases->Compile Sources, select the files you want ARC re-enabled and remove the -fno-objc-arc compiler flags that refactor added.

Kirby Todd
  • 11,254
  • 3
  • 32
  • 60
0

The ACR conversion tool is very powerful and very convenient, but more often than not you should use it in the exact opposite way to what you would think.

If you have an ARC project and you've added a class that isn't ARC-compliant. You have two choices:

1) mark the file as not using ARC (recommended for 3rd party classes)
2) convert the file to use ARC

The ARC conversion tool can perform either of these tasks, saving you having to remember the syntax for f-no-whatsit and where to set the flag manually:

For case 1) Run the tool and tick every file except the non-ARC class. The ARC conversion tool won't do anything to files that are already ARC compliant, and any file left unchecked will get the -fno-objc-arc flag added.

For case 2) Run the tool and tick every file including the new class. The ARC conversion tool will now convert only this file to ARC and leave the others alone.

Intuitively you'd expect that if a file is already ARC you should leave it unchecked, but in fact doing this will cause the ARC conversion tool to mark those files with the -fno-objc-arc flag.

Nick Lockwood
  • 40,865
  • 11
  • 112
  • 103