为什么委托声明前面没有*?

发布于 2024-08-26 02:47:55 字数 542 浏览 3 评论 0原文

我只是注意到委托声明前面没有 * ...

我做了这样的事情:

@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

它工作得很好,但因为我习惯于在我声明的对象前面总是有一个 * ,为什么不呢? ?!?

谢谢你,

戈泰。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末骤雨初歇 2024-09-02 02:47:55

这与代表无关。

由于历史原因,id 类型有所不同;将其视为任何对象*。每当你写id时,就没有*

如果所有 Objective-C 对象都有一个根类 Object,那么您可以想象 typedef Object * id; — 但没有,所以 id 是不同的(好吧,实际上,如果我没记错的话,它被定义为类似于 struct objc_object * 的东西,但你不应该担心该实现细节与尊重-等级)。

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).

数理化全能战士 2024-09-02 02:47:55

因为id已经有了它隐含的*。如果您忽略协议限制,则

id <NavBarHiddenDelegate> delegate;

显然

id delegate;

不需要 *。顺便说一句,如果协议放在 ObjC 类型上,那么您需要 *,例如

XXViewController<NavBarHiddenDelegate>* delegate;

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文