8

I think the title explains my question pretty well, I'm currently working on a small framework for my personal needs, and thought about building it with ARC (if thats possible at all?), and use it in old projects that were built before ARC?

Shai Mishali
  • 9,224
  • 4
  • 56
  • 83

3 Answers3

7

Yes, with one caveat: if you have iOS 4.x as a deployment target, a supplemental library is necessary to deal with ARC-compiled code on the older runtime. For an application built using ARC, this is packaged in with the application. This is not included if you are using an ARC-compiled library in a non-ARC application.

You can manually link this library into your non-ARC application to avoid runtime problems on the older OS versions by adding -fobjc-arc to your Other Linker Flags for the application.

See this Apple Developer Forums thread for some more discussion on this.

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
  • I've actually tried that just now in a project and it didn't help, any chance you could have a look? http://stackoverflow.com/questions/8375233/ld-duplicate-symbol-objc-retainedobject-on-ios-4-3-but-not-on-ios-5-0 – Shai Mishali Dec 04 '11 at 12:19
  • Why should there be any runtime problems? Isn't ARC doing it's at compile time? – Zaky German Apr 26 '12 at 16:19
  • @ZakyGerman - ARC does more than just inject `-retain` and `-release` at the right points, and it introduces things like the new `@autoreleasepool`, so it needs a little runtime help for this. This is built into iOS 5.0, but 4.x needs this backwards compatibility library. – Brad Larson Apr 26 '12 at 20:31
  • @Brad Larson - This makes sense to me but I can't find any documentation on the -fobjc-arc LINKER flag. Do you have a pointer to docs? I figured man ld would show it, but I'm not seeing it... – TomSwift Jun 14 '12 at 17:09
  • Did you mean -fno-objc-arc flag? – Sam B May 18 '16 at 15:35
  • @SamB - No, that's to turn off ARC for select files. The above was specific for targeting iOS 4.0, and may no longer be necessary (as well as rare, given how few people will be targeting that OS version today). – Brad Larson May 18 '16 at 15:49
2

You can link against the glue library provided by Apple (as Brad has said in his answer above). However, the __weak variable qualifier is not compatible with operating systems below 4.3 (As mentioned here: iOS 5 Best Practice (Release/retain?) in a comment by sudo).

Community
  • 1
  • 1
Paul de Lange
  • 10,613
  • 10
  • 41
  • 56
1

Should be fine. The library is already compiled, so ARC/NonARC shouldn't matter anymore.

Patrick Perini
  • 22,555
  • 12
  • 59
  • 88
  • 1
    There is one potential issue with the older runtime and ARC-enabled static libraries, that I've detailed in my answer. – Brad Larson Nov 03 '11 at 19:10