I'm aware that with Xcode now, it is recommended to use ARC, however I've read a bit about it not being compatible with iOS 4.x, at least when using __weak
. When I create an IBOutlet
it gives the choice of weak or strong as the storage type, does this mean my application is limited to iOS 5 or above, or will it still run on an older iOS?

- 2,054
- 3
- 17
- 33

- 611
- 7
- 16
3 Answers
Definitely just use ARC. As you point out, if you elect to provide iOS 4.3 compatibility, you don't enjoy that one little benefit feature of weak
variables, where they'd be automatically nil
-ed for you when they're deallocated (but you don't have that feature in non-ARC code, so it's not like you're losing anything). And, yes, when you control-drag from Interface Builder to the .h file, it says you have only the strong
and weak
options, but in the latest Xcode, at least, if you have iOS 4.3 as a target and you choose weak
, it will automatically create it for you as a __unsafe_unretained
, so all is good.
In short, use ARC, even if you're targetting support for iOS 4.3, and your coding life will be considerably better than if you didn't use ARC. Even in iOS 4.3, you get so many wonderful ARC benefits. And if you are willing to use iOS 5.0 as your target deployment, then you enjoy the full benefits of ARC.
If you use Xcode 4.5, you do, admittedly lose support for armv6, the processor for the iPhone 3G and earlier, so your app will only support the iPhone 3GS and later.

- 415,655
- 72
- 787
- 1,044
-
Thanks, I've heard `__unsafe_unretained` should be avoided, probably another topic of discussion in its self, but is that the case? If it doesn't nil on deallocation, would that leave you open to the problem of memory leaks? – Dayn Goodbrand Dec 04 '12 at 07:13
-
3No, it doesn't cause leaks. It opens you up to possibly having dangling pointers (a pointer to an object that doesn't exist any more), just like you would have in your non-ARC code. But if you code properly, you never have dangling pointers, anyway, so it's not a huge deal. And if you're sloppy, you'd have dangling pointers, but you'd have that in non-ARC as well. If you're comfortable supporting iOS 5 and later (which I think is a reasonable compromise at this point), then you can use `weak` without reservation. – Rob Dec 04 '12 at 07:15
-
Yeah I intend to, more for my personal knowledge. Thanks for your help – Dayn Goodbrand Dec 04 '12 at 07:25
No, ARC is just compiler feature. It's per file, so it wouldn't impact your existing code at all.

- 9,143
- 5
- 32
- 58
iOS version support depends on your Xcode version.
With the last version of Xcode (4.5) you can create apps for iOS 4.3 and higher. If you need to create apps for earlier versions of iOS (prior that 4.3) you need to install Xcode 4.4.1.

- 2,054
- 3
- 17
- 33
-
-
-
If i change to iOS 4.3 after creating anything for iOS 5, it errors because of `weak`, but if i change it first, then create say an `IBOutlet`, it will automatically change it to `unsafe_unretained`. Thanks for the help – Dayn Goodbrand Dec 04 '12 at 07:21