SkillAgentSearch skills...

ZWRCompatibility

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

Install / Use

/learn @rpetrich/ZWRCompatibility
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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
View on GitHub
GitHub Stars40
CategoryCustomer
Updated1y ago
Forks4

Languages

Objective-C

Security Score

60/100

Audited on Dec 3, 2024

No findings