什么是 NSConcreteData,它在哪里定义?

发布于 2024-07-26 22:20:03 字数 276 浏览 2 评论 0原文

以下代码:

[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]]

返回 NSConcreteData 的实例,而不是 NSData (这是我所期望的!)。 NSConcreteData 到底代表什么?为什么返回它而不是 NSData 的实例? 此外,这个类是在哪里定义的? XCode 抱怨它尚未定义,但我不知道应该包含什么才能获取该类。

任何帮助表示赞赏!

The following code:

[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:mapURL]]

returns an instance of NSConcreteData as opposed to NSData (which I expected!). What does NSConcreteData represent, exactly, and why is it being returned instead of an instance of NSData? Further, where is this class defined? XCode is complaining that it hasn't been defined, but I don't know what I should include in order to get the class.

Any help appreciated!

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

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

发布评论

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

评论(1

孤凫 2024-08-02 22:20:03

Foundation框架在某些领域使用类簇来为各种类提供公共接口。 这意味着,当您使用 NSData API 创建 NSData 对象时,实例化并返回的实际类与 NSData 不同>,但可以而且应该被代码视为 NSData 对象并引用。

归根结底,简单的答案是:忽略 NSConcreteData 的存在并将其视为 NSData

有关类簇的更多信息,请参阅 Apple Cocoa 基础指南

The Foundation framework uses class clusters in certain areas to provide a common interface to various classes. What this means is that, when you use an NSData API to create an NSData object, the actual class that is instantiated and returned is different from NSData, but can and should be treated and referred to as an NSData object by your code.

At the end of the day, the simple answer is: ignore the existence of NSConcreteData and treat it like NSData.

For more information on class clusters, please see the Class Clusters section of Apple's Cocoa Fundamentals Guide.

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