Skip to content

Paulxia/ZWRCompatibility

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published