从框架调用协议?
我目前正在使用 NinevehGL 引擎开发一个简单的应用程序。该引擎有一个名为 NGLMesh 的类,用于存储此类实例的 openGL 数据。来自 NinevehGL 的 copyInstance 方法文档,位于 http://nineveh.gl/docs/Protocols/NGLCopying。 html 它说:
“NGLCopying是Cocoa协议NSCopying的扩展。
它定义了NinevehGL对象的两种基本复制模式:
Copy: Makes a new clone, copying all the used memory.
Copy Instance: Makes a new clone, but clonning just the superficial memory."
我想 我很难理解协议以及如何调用它们,到目前为止,互联网已经被证明有点令人困惑。
使用这种方法将我的一个 NGLMesh 复制到一个新的 NGLMesh 实例中,但是 收集(虽然我很可能是错的)我需要在我想要使用它的类中“采用”NGLCoping 协议,我似乎找不到太多关于如何完成此操作的信息。
I am currently using the NinevehGL engine to develop a simple app. This engine has a class called NGLMesh that stores openGL data for an instance of this class. From NinevehGL's documentation for the copyInstance method located at http://nineveh.gl/docs/Protocols/NGLCopying.html it says:
"The NGLCopying is an extension of Cocoa protocol NSCopying.
It defines two basic copying modes to NinevehGL objects:
Copy: Makes a new clone, copying all the used memory.
Copy Instance: Makes a new clone, but clonning just the superficial memory."
I would like to copy one of my NGLMeshs into a new NGLMesh instance using this method, however Im having a hard time understanding protocols and how to call them. Could someone offer some explanation? The internet has proved to be a little confusing thus far.
From what I gather (although Im most likely wrong) I need to "adopt" the NGLCopying protocol in the class that I want to use it with. I cant seem to find much information on how to accomplish this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
协议只是一个类可以响应的消息列表。将其视为类的
@interface
块的扩展,只是它可以被多个类共享。如果您只是尝试复制另一个已经符合此协议的类(例如 NGLMesh),则无需执行任何特殊操作 - 只需执行[yourNGLMeshObject copy]
或[yourNGLMeshObject复制实例]
。A protocol is just a list of messages that a class can respond to. Think of it as an extension of the class's
@interface
block, only it can be shared by several classes. If you are just trying to copy another class that already conforms to this protocol (such as NGLMesh), you don't need to do anything special — just do[yourNGLMeshObject copy]
or[yourNGLMeshObject copyInstance]
.