Wojtek @suda Siudzinski


Python/Node/Golang/Rust developer, DIY hacker, rookie designer, 3D print junkie. CEO @ Gaia Charge


Using NON-ARC 3rd party code in an ARC project

ARC (Automatic Reference Counting) is great. It's even better than Nutella sandwich with bacon and sprinkles. But it can be irritating when you use a lot of third party code that doesn't support it and compiler just "won't let you do this Dave".

No worries, there's a simple workaround for this: put this code into a non-ARC library. Here's how you do it:

  1. Remove all the non-ARC code from the project
  2. Create new "Cocoa Touch Static Library" (or "Cocoa Library" for Mac projects) target
  3. Uncheck "Use Automatic Reference Counting"
  4. Add your non-ARC to your library (there should be a folder in top level of Xcode Navigator with your library name - add them here)
  5. Go to Build Phases of your main target and:
    • Remove non-ARC code from Compile Sources phase
    • Add your library target to Target Dependencies phase
    • Drag your library product (it's in last group in Navigator) to Link Binary With Libraries phase
  6. Go to Build Phases of your library target and add all *.m files from library to Compile Sources phase
  7. Compile and enjoy your non-ARC code in an ARC project :)

Note: If building library still gives you errors about ARC, go to Build Settings of library and set Objective-C Automatic Reference Counting to No (sometimes Xcode ignores unchecking it when creating library).

comments powered by Disqus