What is NSConcreteData, and where is it defined?

空扰寡人 提交于 2019-11-29 17:24:22

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/1113811/what-is-nsconcretedata-and-where-is-it-defined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!