[英]How do I convert Objective-C array of pointers to Swift?
In Objective-C
these are two declarations of array of pointers: 在
Objective-C
这是指针数组的两个声明:
NSArray<MTKMesh *> *mtkMeshes;
NSArray<MDLMesh *> *mdlMeshes;
I am struggling declaring the equivalent in Swift 3.0
. 我正在努力声明
Swift 3.0
的等效项。
MTKMesh
and MDLMesh
are classes (reference types). MTKMesh
和MDLMesh
是类 (引用类型)。 A variable of type MTKMesh
in Swift is a reference to an object instance, ie what a variable of type MTKMesh *
is in Objective-C. Swift中类型为
MTKMesh
的变量是对对象实例的引用,即,Objective-C中类型为MTKMesh *
的变量。
Therefore you can simply declare 因此,您只需声明
var mtkMeshes: [MTKMesh] = []
var mdlMeshes: [MDLMesh] = []
Each element of the array is a reference to an object instance: 数组的每个元素都是对对象实例的引用:
let mesh1 = MDLMesh()
let mesh2 = MDLMesh()
mdlMeshes.append(mesh1)
mdlMeshes.append(mesh1)
mdlMeshes.append(mesh2)
print(mdlMeshes[0] === mdlMeshes[1]) // true
print(mdlMeshes[0] === mdlMeshes[2]) // false
The first two array elements reference the same object instance, the last array element references a different instance. 前两个数组元素引用相同的对象实例,最后一个数组元素引用不同的实例。 (
===
is the "identical-to" operator ). (
===
是“与”相同的运算符 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.