Re: Two problems building 32/64 framework for Lion/ARC
Re: Two problems building 32/64 framework for Lion/ARC
- Subject: Re: Two problems building 32/64 framework for Lion/ARC
- From: Jean-Denis MUYS <email@hidden>
- Date: Tue, 07 Feb 2012 15:35:52 +0000
- Thread-topic: Two problems building 32/64 framework for Lion/ARC
On 7 févr. 2012, at 14:56, David Hoerl wrote:
> 1) I support an open source framework that I'm migrating to Xcode 4.2 / ARC. It uses the 10.7 SDK and with a deployment target of 10.6, and should support 32 and 64 bit runtimes.
>
> It appears that I can use ARC in 64 bit mode but not in 32. So, I am going to need to deal with perhaps 20 instances of autorelease. My thoughts are to add two defines and wrap these lines, so that if in 32 bit mode I get a prefix of "[" and a suffix of "autorelease]" and in 64 bit they are nil. Does anyone have a better idea?
Perhaps. The first idea is to skip using ARC in your framework at all. This will not change anything for your users: they can still use it in their own projects, with or without ARC, as ARC-compiled code is compatible with non-ARC compiled code.
Now if you insist using ARC for the modern run-time, I would probably prefer something like this (assuming you conditionally defined :
{
TSomething *objectToReturn = [[TSomething alloc] init];
// […]
#ifndef ARC_ENABLED
[objectToReturn autorelease];
#endif
return objectToReturn;
}
Or you can package it in a function-like form:
#ifdef ARC_ENABLED
#define AUTORELEASE_UNLESS_ARC(object) (object)
#else
#define AUTORELEASE_UNLESS_ARC(object) [(object) autorelease]
#endif
Of course, you must define the ARC_ENABLED macro, something like this:
#if __has_feature(objc_arc)
#define ARC_ENABLED 1
#endif
>
> Will the end framework properly serve both 32 and 64 bit apps, or should I really not use ARC at all?
The end result will probably be OK for both runtime. ARC is clever, but not magic. In both cases, the compiled code calls retain/release/autorelease…
Run-time compatibility is an issue with GC, not with ARC (zeroing weak references excepted to some extent).
Jean-Denis
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden