Is ARC really supported in iOS 4? The iOS 4.2 SDK is missing ARC-related symbols at linking time

落花浮王杯 提交于 2019-11-26 08:08:41

问题


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)


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/7747783/is-arc-really-supported-in-ios-4-the-ios-4-2-sdk-is-missing-arc-related-symbols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!