Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
502 views
in Technique[技术] by (71.8m points)

objective c - Recommended way to declare delegate properties with ARC

I used to declare all delegate properties as

@property (assign) id<FooDelegate> delegate;

I was under the impression that all assign properties should now be weak pointers, is this correct? If I try to declare as:

@property (weak) id<FooDelegate> delegate;

I get an error while trying to @synthesize (autogenerated weak properties are not supported).

What's the best practice in this case?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Xcode 4 Refactor > Convert to Objective-C ARC transforms:

@interface XYZ : NSObject
{
    id delegate;
}
@property (assign) id delegate;
...
@synthesize delegate;

into:

@interface XYZ : NSObject
{
    id __unsafe_unretained delegate;
}
@property (unsafe_unretained) id delegate;
...
@synthesize delegate;

If I remember correctly it is also mentioned in WWDC 2011 video about ARC.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...