32

I've read and heard since ARC was first announced that it was a compile-time thing and would be backwards-compatible with iOS 4. I have successfully refactored my project to ARC using Xcode 4.2's automatic refactoring, and when compiled against the iOS 5.0 SDK, it works fine. However, if I try to compile against my iOS 4.2 SDK, it fails at link time, missing the following symbols:

  • _objc_retainAutoreleaseReturnValue
  • _objc_autoreleaseReturnValue
  • _objc_storeStrong
  • _objc_retain
  • _objc_release
  • _objc_retainAutoreleasedReturnValue

I checked, and these symbols are present in 5.0 but not 4.2:

iPhoneOS5.0.sdk/usr/lib $ find . -type f|xargs nm|grep -i _objc_retain$
00005ed0 T _objc_retain
000061d0 T _objc_retain

iPhoneOS4.2.sdk/usr/lib $ find . -type f|xargs nm|grep -i _objc_retain$
[... *crickets* ...]

Does this mean that Apple lied? I assume instead that I'm confused and doing something wrong, but I can't figure out what.

This is with the GM release of Xcode 4.2 (Build 4C199)

Doug McBride
  • 514
  • 1
  • 4
  • 13
  • 3
    In addition to what others have said, don't install the 4.2 SDK. Use the 5.0 SDK. Set your deployment target. I don't mean for this, I mean in general; older SDKs should not be used. – Steven Fisher Oct 12 '11 at 23:40
  • 1
    Wow, I can't believe I've gone this long without knowing that newer SDKs could build for older OS versions. Here I've been mad at Apple that they've been deleting all my old SDK versions :/ Thank you! – Doug McBride Oct 12 '11 at 23:46

2 Answers2

34

ARC is supported on iOS 4.3 and above. You need to use the iOS 5.x SDK but can select iOS 4.3 for the Deployment Target. The one thing that is not supported in 4.x is automatic weak reference zeroing.

See Apple's documentation here for the Objective-C Feature Availability Index.

Xcode 4.4 and 4.5 can be used to submit apps.

Note that NSDictionary and NSArray subscripting deploys back to OS X 10.6 and iOS 4, be sure to set the deployment target back as well.

zaph
  • 111,848
  • 21
  • 189
  • 228
  • Thanks (facepalm). It actually seems to be working with 4.2 as a deployment target as well, however... going to test on a real device now. – Doug McBride Oct 12 '11 at 23:47
  • It seems to run fine on my device as well, running iOS 4.2.1. – Doug McBride Oct 13 '11 at 00:24
  • Sorry, looks like @CocoaFu was correct. After I restarted Xcode, it seems to only work in 4.3. Xcode 4 seems easily confused :( – Doug McBride Oct 13 '11 at 01:17
  • @CocoaFu what version reference are you referring to? Everything I can find just says it supports iOS 4. – Christopher Pickslay Oct 13 '11 at 21:02
  • I can't find a good reference so I am basing on what I remember from WWDC11. – zaph Oct 13 '11 at 22:26
  • @CocoaFu - This isn't limited to iOS 4.3. I was just able to successfully deploy an ARC-enabled application to an iPhone 3G running 4.2. I'm pretty sure the floor on the deployment target here is 4.0, from what I saw at WWDC. All that is required is the modern runtime, which is present in iOS 4.0 (and 64-bit on Snow Leopard). – Brad Larson Oct 19 '11 at 14:18
  • @Doug - If you are attempting to deploy to an older device (say an iPhone 3G running 4.2), make sure that you've added an armv6 architecture to your build settings. Xcode 4.2 doesn't have a default setting for this any more, so you need to manually add it in order to target older devices. I just successfully ran an ARC-enabled application on an iPhone 3G on 4.2 here. – Brad Larson Oct 19 '11 at 14:20
  • 1
    Apple itself says that ARC is available on "iOS 4": http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html Personally I've ran ARC app on iPhone 3G with iOS 4.2 and iPad with iOS 4.2. If you use the "weak" keyword however you will get an error trying to build for iOS 4.x. – CodeSmile Oct 23 '11 at 22:34
  • 1
    I can confirm that ARC without weak reference support works on at least iOS 4.2.1, I have nothing older to test on. – NJones Jan 15 '12 at 19:54
  • Apple's documentation provided in the answer clearly says that "NSDictionary and NSArray subscripting deploys back to iOS 5", not iOS 4. I have submitted an update that is waiting for approval. – Roberto May 10 '13 at 22:00
11

A little bit late, but this is important information. The accepted answer is correct, Apple states iOS 4.0 and above as the minimum OS for ARC support.

However, it can break in a few situations. One of them is of course the __weak keyword and it's derivatives. You will see an error like the following.

dyld: lazy symbol binding failed: Symbol not found: _objc_initWeak

A second and very dangerous condition is when you use the +load method of NSObject. If you do this using ARC on iOS 4.x you will have runtime crashes that are very hard to find. If you get runtime errors like the following, check your +load methods. For me it worked to set the -fno-objc-arc flag for that particular file.

dyld: lazy symbol binding failed: Symbol not found: _objc_retainAutoreleasedReturnValue
Paul de Lange
  • 10,613
  • 10
  • 41
  • 56
  • That second part you mention has come back to haunt me, crash in `+load`. We will drop iOS 4.3 soon but I have to provide one more working update for some people refusing to update 4.3 to 5 or 6, gaaaah. – Pascal May 18 '13 at 19:01