id< ...>是什么在Objective-C中意味着什么? [英] What does id<...> mean in Objective-C?

查看:99
本文介绍了id< ...>是什么在Objective-C中意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在iOS应用中使用Google Analytics,我看到了这部分代码:

I'm trying to use Google Analytics in an iOS application, and I saw this portion of code :

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

作为iOS开发的初学者,我不知道<$ c $之间有什么区别C> ID< GAITracker>跟踪器和 GAITracker *跟踪器。我在谷歌搜索过但没有找到解释。有人能澄清一下吗?

As a beginner in iOS development, I don't know what is the difference between id<GAITracker> tracker and GAITracker *tracker. I searched for it in Google but didn't find the explanation. Can someone clarify it to me ?

谢谢。

推荐答案

<>表示该对象符合方括号内的协议(pr协议)。

The <> means that the object conforms to the protocol (pr protocols) inside the square brackets.

在您的示例中,对象 tracker 可以是任何类型的对象,但它符合 GAITracker 协议。

On your example, the object tracker can be any type of object but it conforms to the GAITracker protocol.

因此,尽管如此它没有特定的类,您仍然可以调用该协议声明的方法和属性。

Therefore, although it doesn't have a specific class you can still call methods and properties on it that are declared by that protocol.

这篇关于id&lt; ...&gt;是什么在Objective-C中意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆