swift - 模型 I/O – 如何使用 `makeVerticesUniqueAndReturnError()` 实例方法?
问题描述
一个实例方法makeVerticesUnique()
修改了网格的顶点缓冲区,因此没有顶点被多个面共享。但它在 macOS 10.13 High Sierra 和 iOS 11 中已被弃用:
mdlMesh.makeVerticesUnique() /* deprecated in macOS 10.13 and iOS 11 */
现在开发者必须使用一个新的实例方法:
func makeVerticesUniqueAndReturnError() throws
但它没有记录。如何使用它?
当我使用这个新的实例方法时,Xcode 给了我一个错误:
'throws' may only occur before '->'
解决方案
每当您在 developer.apple.com 或 Xcode 文档查看器中找不到文档时,请检查框架头文件或 Swift 接口——它们通常有代码注释,至少可以作为粗略的文档形式。
在 Xcode 中,使用 Open Quickly (⌘⇧O) 并输入相关标题的名称 ( MDLMesh.h
) 或其中的符号之一 ( MDLMesh, makeVerticesUnique, etc
)。或者 ⌘-单击源中的这些符号之一,然后选择跳转到定义。(如果此时您在 Objective-C 头文件中结束并希望查看 Swift 版本,请从文件顶部的相关项目菜单中选择 Generated Interface。)
在这种情况下,您会看到两种方法在用法上是等效的(但新方法能够引发错误):
/*!
@method makeVerticesUnique:
@abstract Deindexes the vertex array
@discussion If any vertices are shared on multiple faces, duplicate those
vertices so faces do not share vertices. The vertex buffer and index
buffers on submeshes may grow to accomadate any vertices added.
*/
@available(OSX, introduced: 10.11, deprecated: 10.13)
open func makeVerticesUnique()
/*!
@method makeVerticesUniqueAndReturnError:
@abstract Deindexes the vertex array
@discussion If any vertices are shared on multiple faces, duplicate those
vertices so faces do not share vertices. The vertex buffer and index
buffers on submeshes may grow to accomadate any vertices added.
*/
@available(OSX 10.13, *)
open func makeVerticesUniqueAndReturnError() throws
据推测,Apple 确定原始方法没有优雅地处理故障(致命错误停止?崩溃?产生错误输出?不知道)并决定最好让调用者知道什么时候出现问题。
推荐阅读
- python - Luhns 算法,mod 10 检查
- node.js - 如何在 mongoDB 中查询每个文档的另一个集合
- reactjs - React:setState 不会导致重新渲染?
- repository - 复制 terraform 存储库结构的最佳解决方案是什么?
- typescript - 如何从 TypeScript 中的外部文件向类构造函数添加函数?
- javascript - iframe 安全 postmessage 劫持
- python - 将软件安装到另一台用python制作的计算机时如何解决绝对路径错误?
- python - 可选地根据属性列表值组合字典的 Python 列表
- typescript - 带有并行内部调用的顺序 rxjs 调用
- spring-boot - 条件切入点表达式