什么是 NSConcreteData,它在哪里定义?
以下代码:
[[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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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 anNSData
object, the actual class that is instantiated and returned is different fromNSData
, but can and should be treated and referred to as anNSData
object by your code.At the end of the day, the simple answer is: ignore the existence of
NSConcreteData
and treat it likeNSData
.For more information on class clusters, please see the Class Clusters section of Apple's Cocoa Fundamentals Guide.