Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Support Objective-C zeroing weak references with unsafe fallback on non-OS X 10.7/iOS 5.0

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 README.md
Octocat-spinner-32 ZWRCompatibility.h
Octocat-spinner-32 ZWRCompatibility.m
README.md

ZWRCompatibility

Support Objective-C zeroing weak references with unsafe fallback on non-OS X 10.7/iOS 5.0

Warning: References are not zeroing on older OS versions and should be used to provide additional safety only. If you need true zeroing references, use MAZeroingWeakRef instead.

Example

#import "ZWRCompatibility.h"
@protocol FooDelegate <NSObject>
@end

@interface Foo : NSObject {
    __zwrc_weak id<FooDelegate> delegate;
}

@property (nonatomic, assign) id<FooDelegate> delegate;

@end

@implementation Foo

- (id<FooDelegate>)delegate
{
    return zwrc_load(delegate);
}

- (void)setDelegate:(id<FooDelegate>)newDelegate
{
    zwrc_store(delegate, newDelegate);
}

- (void)dealloc
{
    zwrc_clear(delegate);
    [super dealloc];
}

@end

Simplified Delegate Example

#import "ZWRCompatibility.h"
@protocol BarDelegate <NSObject>
@end

@interface Bar : NSObject
@property (nonatomic, assign) id<BarDelegate> delegate;
@end

@implementation Bar

ZWRC_DELEGATE_SYNTHESIZE(BarDelegate);

- (void)dealloc
{
    zwrc_delegate_clear();
    [super dealloc];
}

@end
Something went wrong with that request. Please try again.