开发者

Why is there no * in front of delegate declaration?

I just noticed there is no * in front of the declaration for a delegate ...

I did something like this :

@protocol NavBarHiddenDelegate;


@interface AsyncImageView : UIView {

    NSURLConnection* connection;
    NSMutableData* data;
    UIActivityIndicatorView *indicator;

    id <NavBarHiddenDelegate> delegate;

}

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

- (id)initWithUrl:(NSString*)url;

@end


@protocol NavBarHiddenDelegate 

- (void)hideNavBar;

@end

It works perfectly well but as I am used to always but a * in front of objects开发者_开发百科 I declare, why not for this one ?!?

Thank you,

Gotye.


This has nothing to do with delegates.

The type id is different, for historical reasons; think of it as any-object *. Whenever you write id, there is no *.

If there were a single root class Object for all Objective-C objects then you could imagine that typedef Object * id; — but there isn't, so id is different (well, actually, it's defined as something like struct objc_object * if I recall correctly, but you shouldn't worry about that implementation-detail-with-respect-to-this-level).


Because id already has its implicit *. If you ignore the protocol restriction then

id <NavBarHiddenDelegate> delegate;

becomes

id delegate;

which obviously doesn't need a *. BTW, if the protocol is put on an ObjC type then you need the *, e.g.

XXViewController<NavBarHiddenDelegate>* delegate;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜