Including ARC headers in non-ARC project
I created a static library that was coded using ARC. I am planning to distribute this library for other people to use. I understand that nothing needs to be done to include the static ARC library in a non-ARC project, but what about including ARC header files? For example, the headers for my ARC static library declare properties like weak
and strong
, but when I try to include those headers in a non-ARC project, the compiler fades.
Any ideas?
source to share
For strong
you can just use retain
. They are identical.
weak
harder, and while I know several ways that should work, I'm not sure if this is the best way to handle it.
Make sure you really need it first. If you support iOS4, you can't have it weak
anyway, so this is a moot point. I feel like Iām probably just avoiding weak
and missing out on all these problems. weak, it's nice, but most of the time it's not that hard.
However, there are some approaches that will work. Your best bet is probably to declare weak
accessors with no properties in the header. Instead of this:
@property (nonatomic, readwrite, weak) id delegate;
Do it:
- (id)delegate;
- (void)setDelegate:(id)aDelegate;
Then you can declare the property weak
inside your implementation file. The caller can still use dot notation, BTW.
You might get a compile error here, as it setDelegate:
technically accepts __strong id
. If this is the case, just a manual implementationsetDelegate:
- (void)setDelegate:(id)aDelegate {
_delegate = aDelegate;
}
Haven't tested but it should work. You can also declare ivar _delegate
__weak
in a block @implementation
rather than declare it as a property weak
.
As I said; I haven't tested anything. Please post your results if they work.
source to share